MessageHandler.c 730 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141
  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 && (server_sign == TRUE) &&
  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. DEBUG_INFO("sendStatusNotificationRequest...\n");
  3192. gettimeofday(&tmnow, NULL);
  3193. time_t t;
  3194. t = time(NULL);
  3195. /*UTC time and date*/
  3196. tm = gmtime(&t);
  3197. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3198. #if 0 // remove temporally
  3199. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3200. strcat(buf,".");
  3201. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3202. strcat(buf,usec_buf);
  3203. #endif
  3204. printf("%s",buf);
  3205. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  3206. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  3207. // it's option
  3208. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  3209. /*
  3210. enum _SYSTEM_STATUS
  3211. {
  3212. S_BOOTING = 0,
  3213. S_IDLE, = 1
  3214. S_AUTHORIZING, =2
  3215. S_REASSIGN_CHECK, =3
  3216. S_REASSIGN, =4
  3217. S_PRECHARGE, =5
  3218. S_PREPARING_FOR_EV, =6
  3219. S_PREPARING_FOR_EVSE, =7
  3220. S_CHARGING, =8
  3221. S_TERMINATING, =9
  3222. S_COMPLETE, =10
  3223. S_ALARM, =11
  3224. S_FAULT =12
  3225. }
  3226. */
  3227. //check Transaction active
  3228. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3229. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3230. {
  3231. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3232. {
  3233. tempIndex = ((gun_index==2) ? 1: 0);
  3234. }
  3235. else
  3236. {
  3237. tempIndex = gun_index;
  3238. }
  3239. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3240. {
  3241. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  3242. {
  3243. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  3244. {
  3245. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3246. {
  3247. currentStatus = Preparing; //OCPP Status: Preparing
  3248. }
  3249. else
  3250. {
  3251. currentStatus = Available; //OCPP Status: Available
  3252. }
  3253. }
  3254. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3255. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3256. ) //S_PRECHARGE
  3257. {
  3258. currentStatus = Preparing; //OCPP Status: Preparing
  3259. }
  3260. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3261. {
  3262. currentStatus = Charging; //OCPP Status: Charging
  3263. }
  3264. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3265. {
  3266. currentStatus = Finishing; //OCPP Status: Finishing
  3267. }
  3268. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3269. {
  3270. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3271. }
  3272. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  3273. {
  3274. currentStatus = Unavailable; //OCPP Status: Unavailable
  3275. }
  3276. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3277. {
  3278. currentStatus = Faulted; //OCPP Status: Faulted
  3279. }
  3280. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3281. {
  3282. currentStatus = Reserved; //OCPP Status: Reserved
  3283. }
  3284. } //end of the same index
  3285. }//end of for CHAdeMO_QUANTITY
  3286. }
  3287. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3288. {
  3289. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3290. {
  3291. tempIndex = ((gun_index==2) ? 1: 0);
  3292. }
  3293. else
  3294. {
  3295. tempIndex = gun_index;
  3296. }
  3297. for (int index = 0; index < CCS_QUANTITY; index++)
  3298. {
  3299. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3300. {
  3301. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3302. {
  3303. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3304. {
  3305. currentStatus = Preparing; //OCPP Status: Preparing
  3306. }
  3307. else
  3308. {
  3309. currentStatus = Available; //OCPP Status: Available
  3310. }
  3311. }
  3312. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3313. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3314. ) //S_PRECHARGE
  3315. {
  3316. currentStatus = Preparing; //OCPP Status: Preparing
  3317. }
  3318. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3319. {
  3320. currentStatus = Charging; //OCPP Status: Charging
  3321. }
  3322. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3323. {
  3324. currentStatus = Finishing; //OCPP Status: Finishing
  3325. }
  3326. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3327. {
  3328. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3329. }
  3330. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  3331. {
  3332. currentStatus = Unavailable; //OCPP Status : Unavailable
  3333. }
  3334. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3335. {
  3336. currentStatus = Faulted; //OCPP Status: Faulted
  3337. }
  3338. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3339. {
  3340. currentStatus = Reserved; //OCPP Status: Reserved
  3341. }
  3342. } //end of the same index
  3343. } // end of for CCS_QUANTITY
  3344. }
  3345. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3346. {
  3347. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3348. {
  3349. tempIndex = ((gun_index==2) ? 1: 0);
  3350. }
  3351. else
  3352. {
  3353. tempIndex = gun_index;
  3354. }
  3355. for (int index = 0; index < GB_QUANTITY; index++)
  3356. {
  3357. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3358. {
  3359. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3360. {
  3361. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3362. {
  3363. currentStatus = Preparing; //OCPP Status: Preparing
  3364. }
  3365. else
  3366. {
  3367. currentStatus = Available; //OCPP Status: Available
  3368. }
  3369. }
  3370. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3371. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3372. ) //S_PRECHARGE
  3373. {
  3374. currentStatus = Preparing; //OCPP Status: Preparing
  3375. }
  3376. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3377. {
  3378. currentStatus = Charging; //OCPP Status: Charging
  3379. }
  3380. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3381. {
  3382. currentStatus = Finishing; //OCPP Status: Finishing
  3383. }
  3384. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3385. {
  3386. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3387. }
  3388. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  3389. {
  3390. currentStatus = Unavailable; //OCPP Status: Unavailable
  3391. }
  3392. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3393. {
  3394. currentStatus = Faulted; //OCPP Status: Faulted
  3395. }
  3396. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3397. {
  3398. currentStatus = Reserved; //OCPP Status: Reserved
  3399. }
  3400. } //end of the same index
  3401. } // end of for GB_QUANTITY
  3402. }
  3403. else if(gunType[gun_index] == GUN_TYPE_DO)
  3404. {
  3405. tempIndex = gun_index;
  3406. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3407. {
  3408. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3409. {
  3410. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3411. {
  3412. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3413. {
  3414. currentStatus = Preparing; //OCPP Status: Preparing
  3415. }
  3416. else
  3417. {
  3418. currentStatus = Available; //OCPP Status: Available
  3419. }
  3420. }
  3421. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3422. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3423. ) //S_PRECHARGE
  3424. {
  3425. currentStatus = Preparing; //OCPP Status: Preparing
  3426. }
  3427. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3428. {
  3429. currentStatus = Charging; //OCPP Status: Charging
  3430. }
  3431. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3432. {
  3433. currentStatus = Finishing; //OCPP Status: Finishing
  3434. }
  3435. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3436. {
  3437. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3438. }
  3439. else if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  3440. {
  3441. currentStatus = Unavailable; //OCPP Status: Unavailable
  3442. }
  3443. 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
  3444. {
  3445. currentStatus = Faulted; //OCPP Status: Faulted
  3446. }
  3447. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3448. {
  3449. currentStatus = Reserved; //OCPP Status: Reserved
  3450. }
  3451. } //end of the same index
  3452. }
  3453. }
  3454. else
  3455. {
  3456. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3457. {
  3458. tempIndex = 2;
  3459. }
  3460. else
  3461. {
  3462. tempIndex = gun_index;
  3463. }
  3464. for (int index = 0; index < AC_QUANTITY; index++)
  3465. {
  3466. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3467. {
  3468. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3469. {
  3470. 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))
  3471. {
  3472. currentStatus = Preparing; //OCPP Status: Preparing
  3473. }
  3474. else
  3475. {
  3476. currentStatus = Available; //OCPP Status: Available
  3477. }
  3478. }
  3479. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3480. {
  3481. currentStatus = Preparing; //OCPP Status: Preparing
  3482. }
  3483. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3484. {
  3485. currentStatus = Charging; //OCPP Status: Charging
  3486. }
  3487. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3488. {
  3489. currentStatus = Finishing; //OCPP Status: Finishing
  3490. }
  3491. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3492. {
  3493. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3494. }
  3495. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  3496. {
  3497. currentStatus = Unavailable; //OCPP Status: Unavailable
  3498. }
  3499. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3500. {
  3501. currentStatus = Faulted; //OCPP Status: Faulted
  3502. }
  3503. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3504. {
  3505. currentStatus = Reserved; //OCPP Status: Reserved
  3506. }
  3507. }//end of the same index
  3508. }//end of for AC_QUANTITY
  3509. }
  3510. //it's option
  3511. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3512. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3513. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3514. random_uuid(guid);
  3515. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3516. , MESSAGE_TYPE_CALL
  3517. , guid
  3518. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3519. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3520. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3521. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3522. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3523. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3524. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3525. if((server_sign == TRUE))
  3526. {
  3527. LWS_Send(message);
  3528. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3529. 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*/)
  3530. {
  3531. //DEBUG_ERROR("statusNotification mapitem pass");
  3532. result = PASS;
  3533. }
  3534. }
  3535. else
  3536. {
  3537. result = PASS;
  3538. }
  3539. return result;
  3540. }
  3541. int sendStopTransactionRequest(int gun_index)
  3542. {
  3543. mtrace();
  3544. int result = FAIL;
  3545. //char message[1500]={0};
  3546. char guid[37]={0};
  3547. char tempdata[65]={0};
  3548. int tempIndex = 0;
  3549. char TempStopTransaction[256];
  3550. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  3551. //int idx_sample=0;
  3552. DEBUG_INFO("sendStopTransactionRequest \n");
  3553. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3554. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  3555. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3556. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3557. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3558. {
  3559. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3560. {
  3561. tempIndex = ((gun_index==2) ? 1: 0);
  3562. }
  3563. else
  3564. {
  3565. tempIndex = gun_index;
  3566. }
  3567. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3568. {
  3569. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3570. {
  3571. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3572. }
  3573. }// END OF CHAdeMO_QUANTITY
  3574. }
  3575. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3576. {
  3577. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3578. {
  3579. tempIndex = ((gun_index==2) ? 1: 0);
  3580. }
  3581. else
  3582. {
  3583. tempIndex = gun_index;
  3584. }
  3585. for (int index = 0; index < CCS_QUANTITY; index++)
  3586. {
  3587. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3588. {
  3589. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3590. }
  3591. }// END OF CCS_QUANTITY
  3592. }
  3593. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3594. {
  3595. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3596. {
  3597. tempIndex = ((gun_index==2) ? 1: 0);
  3598. }
  3599. else
  3600. {
  3601. tempIndex = gun_index;
  3602. }
  3603. for (int index = 0; index < GB_QUANTITY; index++)
  3604. {
  3605. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3606. {
  3607. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3608. }
  3609. }// END OF GB_QUANTITY
  3610. }
  3611. else if(gunType[gun_index] == GUN_TYPE_DO)
  3612. {
  3613. tempIndex = gun_index;
  3614. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3615. {
  3616. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3617. {
  3618. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3619. }
  3620. }// END OF GB_QUANTITY
  3621. }
  3622. else
  3623. {
  3624. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3625. {
  3626. tempIndex = 2;
  3627. }
  3628. else
  3629. {
  3630. tempIndex = gun_index;
  3631. }
  3632. for (int index = 0; index < AC_QUANTITY; index++)
  3633. {
  3634. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3635. {
  3636. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3637. }
  3638. }// END OF AC_QUANTITY
  3639. }
  3640. //====================================== Stop Transaction Time =====================================================
  3641. struct timeval tmnow;
  3642. struct tm *tm;
  3643. char buf[28];//, usec_buf[6];
  3644. gettimeofday(&tmnow, NULL);
  3645. time_t t;
  3646. t = time(NULL);
  3647. /*UTC time and date*/
  3648. tm = gmtime(&t);
  3649. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3650. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  3651. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  3652. random_uuid(guid);
  3653. /***********************************transactionData******************************************************/
  3654. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  3655. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  3656. //=================================
  3657. // Transaction_Begin
  3658. //=================================
  3659. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  3660. {
  3661. //============================================ Energy.Active.Import.Interval ================================
  3662. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  3663. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  3664. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  3665. 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*/]);
  3666. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3667. 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))
  3668. {
  3669. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  3670. }
  3671. else
  3672. {
  3673. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  3674. }
  3675. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  3676. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3677. }
  3678. //=================================
  3679. // Transaction_End
  3680. //=================================
  3681. // ================================= Current.Import L1 ===============================================
  3682. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  3683. {
  3684. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  3685. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3686. {
  3687. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3688. {
  3689. tempIndex = ((gun_index==2) ? 1: 0);
  3690. }
  3691. else
  3692. {
  3693. tempIndex = gun_index;
  3694. }
  3695. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3696. {
  3697. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3698. {
  3699. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3700. }
  3701. }// End of for CHAdeMO_QUANTITY
  3702. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3703. }
  3704. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3705. {
  3706. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3707. {
  3708. tempIndex = ((gun_index==2) ? 1: 0);
  3709. }
  3710. else
  3711. {
  3712. tempIndex = gun_index;
  3713. }
  3714. for (int index = 0; index < CCS_QUANTITY; index++)
  3715. {
  3716. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3717. {
  3718. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3719. }
  3720. }// End of for CCS_QUANTITY
  3721. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3722. }
  3723. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3724. {
  3725. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3726. {
  3727. tempIndex = ((gun_index==2) ? 1: 0);
  3728. }
  3729. else
  3730. {
  3731. tempIndex = gun_index;
  3732. }
  3733. for (int index = 0; index < GB_QUANTITY; index++)
  3734. {
  3735. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3736. {
  3737. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3738. }
  3739. }// End of for GB_QUANTITY
  3740. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3741. }
  3742. else if(gunType[gun_index] == GUN_TYPE_DO)
  3743. {
  3744. tempIndex = gun_index;
  3745. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3746. {
  3747. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3748. {
  3749. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3750. }
  3751. }
  3752. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3753. }
  3754. else
  3755. {
  3756. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3757. {
  3758. tempIndex = 2;
  3759. }
  3760. else
  3761. {
  3762. tempIndex = gun_index;
  3763. }
  3764. for (int index = 0; index < AC_QUANTITY; index++)
  3765. {
  3766. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3767. {
  3768. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  3769. }
  3770. }// End of for AC_QUANTITY
  3771. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  3772. }
  3773. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3774. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  3775. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  3776. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  3777. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3778. }
  3779. // ================================= Energy.Active.Import.Interval ==============================================
  3780. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  3781. {
  3782. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3783. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3784. {
  3785. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3786. {
  3787. tempIndex = ((gun_index==2) ? 1: 0);
  3788. }
  3789. else
  3790. {
  3791. tempIndex = gun_index;
  3792. }
  3793. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3794. {
  3795. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3796. {
  3797. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3798. }
  3799. }// END OF CHAdeMO_QUANTITY
  3800. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3801. }
  3802. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3803. {
  3804. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3805. {
  3806. tempIndex = ((gun_index==2) ? 1: 0);
  3807. }
  3808. else
  3809. {
  3810. tempIndex = gun_index;
  3811. }
  3812. for (int index = 0; index < CCS_QUANTITY; index++)
  3813. {
  3814. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3815. {
  3816. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3817. }
  3818. }// END OF CCS_QUANTITY
  3819. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3820. }
  3821. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3822. {
  3823. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3824. {
  3825. tempIndex = ((gun_index==2) ? 1: 0);
  3826. }
  3827. else
  3828. {
  3829. tempIndex = gun_index;
  3830. }
  3831. for (int index = 0; index < GB_QUANTITY; index++)
  3832. {
  3833. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3834. {
  3835. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3836. }
  3837. }// END OF GB_QUANTITY
  3838. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3839. }
  3840. else if(gunType[gun_index] == GUN_TYPE_DO)
  3841. {
  3842. tempIndex = gun_index;
  3843. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3844. {
  3845. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3846. {
  3847. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3848. }
  3849. }
  3850. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3851. }
  3852. else
  3853. {
  3854. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3855. {
  3856. tempIndex = 2;
  3857. }
  3858. else
  3859. {
  3860. tempIndex = gun_index;
  3861. }
  3862. for (int index = 0; index < AC_QUANTITY; index++)
  3863. {
  3864. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3865. {
  3866. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3867. }
  3868. }// END OF AC_QUANTITY
  3869. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  3870. }
  3871. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3872. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  3873. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  3874. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  3875. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3876. }
  3877. //=================================== Power.Active.Import ==================================================
  3878. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  3879. {
  3880. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3881. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3882. {
  3883. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3884. {
  3885. tempIndex = ((gun_index==2) ? 1: 0);
  3886. }
  3887. else
  3888. {
  3889. tempIndex = gun_index;
  3890. }
  3891. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3892. {
  3893. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3894. {
  3895. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3896. }
  3897. } // End for CHAdeMO_QUANTITY
  3898. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3899. }
  3900. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3901. {
  3902. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3903. {
  3904. tempIndex = ((gun_index==2) ? 1: 0);
  3905. }
  3906. else
  3907. {
  3908. tempIndex = gun_index;
  3909. }
  3910. for (int index = 0; index < CCS_QUANTITY; index++)
  3911. {
  3912. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3913. {
  3914. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3915. }
  3916. } // END for CCS_QUANTITY
  3917. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3918. }
  3919. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3920. {
  3921. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3922. {
  3923. tempIndex = ((gun_index==2) ? 1: 0);
  3924. }
  3925. else
  3926. {
  3927. tempIndex = gun_index;
  3928. }
  3929. for (int index = 0; index < GB_QUANTITY; index++)
  3930. {
  3931. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3932. {
  3933. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3934. }
  3935. }// END for GB_QUANTITY
  3936. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3937. }
  3938. else if(gunType[gun_index] == GUN_TYPE_DO)
  3939. {
  3940. tempIndex = gun_index;
  3941. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3942. {
  3943. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3944. {
  3945. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3946. }
  3947. }
  3948. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3949. }
  3950. else
  3951. {
  3952. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3953. {
  3954. tempIndex = 2;
  3955. }
  3956. else
  3957. {
  3958. tempIndex = gun_index;
  3959. }
  3960. for (int index = 0; index < AC_QUANTITY; index++)
  3961. {
  3962. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3963. {
  3964. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3965. }
  3966. } // END for AC_QUANTITY
  3967. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  3968. }
  3969. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3970. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  3971. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  3972. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  3973. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  3974. }
  3975. //============================ Voltage L1 ====================================
  3976. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  3977. {
  3978. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3979. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3980. {
  3981. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3982. {
  3983. tempIndex = ((gun_index==2) ? 1: 0);
  3984. }
  3985. else
  3986. {
  3987. tempIndex = gun_index;
  3988. }
  3989. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3990. {
  3991. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3992. {
  3993. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3994. }
  3995. } // END OF FOR CHAdeMO_QUANTITY
  3996. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3997. }
  3998. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3999. {
  4000. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4001. {
  4002. tempIndex = ((gun_index==2) ? 1: 0);
  4003. }
  4004. else
  4005. {
  4006. tempIndex = gun_index;
  4007. }
  4008. for (int index = 0; index < CCS_QUANTITY; index++)
  4009. {
  4010. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4011. {
  4012. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4013. }
  4014. } // END OF FOR CCS_QUANTITY
  4015. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4016. }
  4017. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4018. {
  4019. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4020. {
  4021. tempIndex = ((gun_index==2) ? 1: 0);
  4022. }
  4023. else
  4024. {
  4025. tempIndex = gun_index;
  4026. }
  4027. for (int index = 0; index < GB_QUANTITY; index++)
  4028. {
  4029. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4030. {
  4031. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4032. }
  4033. } // END OF FOR GB_QUANTITY
  4034. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4035. }
  4036. else if(gunType[gun_index] == GUN_TYPE_DO)
  4037. {
  4038. tempIndex = gun_index;
  4039. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4040. {
  4041. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4042. {
  4043. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4044. }
  4045. }
  4046. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4047. }
  4048. else
  4049. {
  4050. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4051. {
  4052. tempIndex = 2;
  4053. }
  4054. else
  4055. {
  4056. tempIndex = gun_index;
  4057. }
  4058. for (int index = 0; index < AC_QUANTITY; index++)
  4059. {
  4060. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4061. {
  4062. 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
  4063. }
  4064. } // END OF FOR AC_QUANTITY
  4065. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  4066. }
  4067. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4068. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  4069. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  4070. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  4071. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4072. }
  4073. //====================== End SoC ================================
  4074. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4075. {
  4076. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4077. 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))
  4078. {
  4079. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4080. {
  4081. tempIndex = ((gun_index==2) ? 1: 0);
  4082. }
  4083. else
  4084. {
  4085. tempIndex = gun_index;
  4086. }
  4087. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4088. {
  4089. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4090. {
  4091. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4092. {
  4093. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  4094. }
  4095. }
  4096. }
  4097. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4098. {
  4099. for (int index = 0; index < CCS_QUANTITY; index++)
  4100. {
  4101. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4102. {
  4103. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  4104. }
  4105. }
  4106. }
  4107. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4108. {
  4109. for (int index = 0; index < GB_QUANTITY; index++)
  4110. {
  4111. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4112. {
  4113. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  4114. }
  4115. }
  4116. }
  4117. else if(gunType[gun_index] == GUN_TYPE_DO)
  4118. {
  4119. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4120. {
  4121. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4122. {
  4123. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  4124. }
  4125. }
  4126. }
  4127. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4128. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  4129. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4130. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  4131. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  4132. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4133. } // END FOR DC CASE
  4134. }
  4135. // ================================= Current.Import L2 ===============================================
  4136. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4137. {
  4138. // AC 3 phse L2 current
  4139. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4140. {
  4141. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4142. {
  4143. tempIndex = 2;
  4144. }
  4145. else
  4146. {
  4147. tempIndex = gun_index;
  4148. }
  4149. for (int index = 0; index < AC_QUANTITY; index++)
  4150. {
  4151. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4152. {
  4153. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  4154. }
  4155. }// End of for AC_QUANTITY
  4156. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  4157. }
  4158. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4159. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  4160. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  4161. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  4162. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4163. }
  4164. // ================================= Current.Import L3 ===============================================
  4165. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4166. {
  4167. // AC 3 phse L3 current
  4168. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4169. {
  4170. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4171. {
  4172. tempIndex = 2;
  4173. }
  4174. else
  4175. {
  4176. tempIndex = gun_index;
  4177. }
  4178. for (int index = 0; index < AC_QUANTITY; index++)
  4179. {
  4180. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4181. {
  4182. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  4183. }
  4184. }// End of for AC_QUANTITY
  4185. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  4186. }
  4187. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4188. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  4189. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  4190. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  4191. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4192. }
  4193. //============================ Voltage L2 ====================================
  4194. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4195. {
  4196. // AC 3 phse L2 voltage
  4197. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4198. {
  4199. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4200. {
  4201. tempIndex = 2;
  4202. }
  4203. else
  4204. {
  4205. tempIndex = gun_index;
  4206. }
  4207. for (int index = 0; index < AC_QUANTITY; index++)
  4208. {
  4209. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4210. {
  4211. 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
  4212. }
  4213. } // END OF FOR AC_QUANTITY
  4214. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  4215. }
  4216. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4217. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  4218. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  4219. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  4220. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4221. }
  4222. //============================ Voltage L3 ====================================
  4223. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4224. {
  4225. // AC 3 phse L3 voltage
  4226. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4227. {
  4228. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4229. {
  4230. tempIndex = 2;
  4231. }
  4232. else
  4233. {
  4234. tempIndex = gun_index;
  4235. }
  4236. for (int index = 0; index < AC_QUANTITY; index++)
  4237. {
  4238. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4239. {
  4240. 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
  4241. }
  4242. } // END OF FOR AC_QUANTITY
  4243. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  4244. }
  4245. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4246. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  4247. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  4248. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  4249. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4250. }
  4251. //====================== Start SoC ================================
  4252. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4253. {
  4254. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4255. 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))
  4256. {
  4257. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4258. {
  4259. tempIndex = ((gun_index==2) ? 1: 0);
  4260. }
  4261. else
  4262. {
  4263. tempIndex = gun_index;
  4264. }
  4265. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4266. {
  4267. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4268. {
  4269. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4270. {
  4271. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  4272. }
  4273. }
  4274. }
  4275. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4276. {
  4277. for (int index = 0; index < CCS_QUANTITY; index++)
  4278. {
  4279. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4280. {
  4281. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  4282. }
  4283. }
  4284. }
  4285. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4286. {
  4287. for (int index = 0; index < GB_QUANTITY; index++)
  4288. {
  4289. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4290. {
  4291. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  4292. }
  4293. }
  4294. }
  4295. else if(gunType[gun_index] == GUN_TYPE_DO)
  4296. {
  4297. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4298. {
  4299. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4300. {
  4301. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  4302. }
  4303. }
  4304. }
  4305. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4306. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  4307. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4308. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  4309. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  4310. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4311. } // END FOR DC CASE
  4312. }
  4313. //================================================ Message create ====================================================
  4314. json_object *StopTransaction = json_object_new_object();
  4315. json_object *transactionDatas = json_object_new_array();
  4316. json_object *sampledValues = json_object_new_array();
  4317. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  4318. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  4319. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  4320. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  4321. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  4322. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  4323. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  4324. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  4325. {
  4326. json_object *transactionData = json_object_new_object();
  4327. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  4328. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  4329. {
  4330. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  4331. {
  4332. json_object *sampledValue = json_object_new_object();
  4333. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  4334. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  4335. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  4336. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  4337. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  4338. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  4339. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  4340. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  4341. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  4342. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  4343. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  4344. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  4345. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  4346. json_object_array_add(sampledValues, sampledValue);
  4347. }
  4348. }
  4349. json_object_object_add(transactionData, "sampledValue", sampledValues);
  4350. json_object_array_add(transactionDatas, transactionData);
  4351. }
  4352. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  4353. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  4354. ,MESSAGE_TYPE_CALL
  4355. ,guid
  4356. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  4357. json_object_put(StopTransaction);
  4358. #if 1 // for TempStopTransaction
  4359. //Delete TempStopTransaction
  4360. if((access(TempStopTransaction,F_OK))!=-1)
  4361. {
  4362. remove(TempStopTransaction); // remove file "TempStopTransaction"
  4363. }
  4364. #endif
  4365. #if 1
  4366. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4367. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4368. {
  4369. result = PASS;
  4370. //DEBUG_INFO("StopTransaction mapitem pass\n");
  4371. }
  4372. #endif
  4373. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4374. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4375. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4376. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  4377. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4378. {
  4379. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4380. }
  4381. //for test
  4382. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4383. return result;
  4384. }
  4385. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4386. {
  4387. mtrace();
  4388. int result = FAIL;
  4389. char guid[37]={0};
  4390. char tempdata[65]={0};
  4391. int tempIndex = 0;
  4392. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4393. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4394. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  4395. //set value
  4396. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4397. 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) )?
  4398. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  4399. -1);
  4400. random_uuid(guid);
  4401. //UTC Date time
  4402. struct timeval tmnow;
  4403. struct tm *tm;
  4404. char buf[28];//, usec_buf[6];
  4405. gettimeofday(&tmnow, NULL);
  4406. time_t t;
  4407. t = time(NULL);
  4408. /*UTC time and date*/
  4409. tm = gmtime(&t);
  4410. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4411. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4412. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4413. //********************************(1)Current.Import L1************************************************/
  4414. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  4415. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  4416. (dataType == ReadingContext_Trigger))
  4417. {
  4418. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4419. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4420. {
  4421. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4422. {
  4423. tempIndex = ((gun_index==2) ? 1: 0);
  4424. }
  4425. else
  4426. {
  4427. tempIndex = gun_index;
  4428. }
  4429. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4430. {
  4431. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4432. {
  4433. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4434. }
  4435. }
  4436. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4437. }
  4438. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4439. {
  4440. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4441. {
  4442. tempIndex = ((gun_index==2) ? 1: 0);
  4443. }
  4444. else
  4445. {
  4446. tempIndex = gun_index;
  4447. }
  4448. for (int index = 0; index < CCS_QUANTITY; index++)
  4449. {
  4450. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4451. {
  4452. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4453. }
  4454. }
  4455. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4456. }
  4457. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4458. {
  4459. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4460. {
  4461. tempIndex = ((gun_index==2) ? 1: 0);
  4462. }
  4463. else
  4464. {
  4465. tempIndex = gun_index;
  4466. }
  4467. for (int index = 0; index < GB_QUANTITY; index++)
  4468. {
  4469. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4470. {
  4471. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4472. }
  4473. }
  4474. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4475. }
  4476. else if(gunType[gun_index] == GUN_TYPE_DO)
  4477. {
  4478. tempIndex = gun_index;
  4479. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4480. {
  4481. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4482. {
  4483. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  4484. }
  4485. }
  4486. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4487. }
  4488. else
  4489. {
  4490. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4491. {
  4492. tempIndex = 2;
  4493. }
  4494. else
  4495. {
  4496. tempIndex = gun_index;
  4497. }
  4498. for (int index = 0; index < AC_QUANTITY; index++)
  4499. {
  4500. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4501. {
  4502. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4503. }
  4504. }
  4505. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4506. }
  4507. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4508. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4509. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4510. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4511. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4512. }
  4513. //********************************(2)Energy.Active.Import.Register ************************************************/
  4514. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4515. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4516. (dataType == ReadingContext_Trigger))
  4517. {
  4518. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4519. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4520. {
  4521. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4522. {
  4523. tempIndex = ((gun_index==2) ? 1: 0);
  4524. }
  4525. else
  4526. {
  4527. tempIndex = gun_index;
  4528. }
  4529. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4530. {
  4531. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4532. {
  4533. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4534. }
  4535. }
  4536. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4537. }
  4538. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4539. {
  4540. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4541. {
  4542. tempIndex = ((gun_index==2) ? 1: 0);
  4543. }
  4544. else
  4545. {
  4546. tempIndex = gun_index;
  4547. }
  4548. for (int index = 0; index < CCS_QUANTITY; index++)
  4549. {
  4550. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4551. {
  4552. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4553. }
  4554. }
  4555. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4556. }
  4557. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4558. {
  4559. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4560. {
  4561. tempIndex = ((gun_index==2) ? 1: 0);
  4562. }
  4563. else
  4564. {
  4565. tempIndex = gun_index;
  4566. }
  4567. for (int index = 0; index < GB_QUANTITY; index++)
  4568. {
  4569. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4570. {
  4571. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4572. }
  4573. }
  4574. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4575. }
  4576. else if(gunType[gun_index] == GUN_TYPE_DO)
  4577. {
  4578. tempIndex = gun_index;
  4579. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4580. {
  4581. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4582. {
  4583. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  4584. }
  4585. }
  4586. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4587. }
  4588. else
  4589. {
  4590. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4591. {
  4592. tempIndex = 2;
  4593. }
  4594. else
  4595. {
  4596. tempIndex = gun_index;
  4597. }
  4598. for (int index = 0; index < AC_QUANTITY; index++)
  4599. {
  4600. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4601. {
  4602. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4603. }
  4604. }
  4605. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4606. }
  4607. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  4608. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4609. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4610. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4611. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4612. }
  4613. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  4614. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  4615. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  4616. (dataType == ReadingContext_Trigger))
  4617. {
  4618. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4619. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4620. {
  4621. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4622. {
  4623. tempIndex = ((gun_index==2) ? 1: 0);
  4624. }
  4625. else
  4626. {
  4627. tempIndex = gun_index;
  4628. }
  4629. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4630. {
  4631. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4632. {
  4633. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4634. }
  4635. } // END OF FOR CHAdeMO_QUANTITY
  4636. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4637. }
  4638. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4639. {
  4640. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4641. {
  4642. tempIndex = ((gun_index==2) ? 1: 0);
  4643. }
  4644. else
  4645. {
  4646. tempIndex = gun_index;
  4647. }
  4648. for (int index = 0; index < CCS_QUANTITY; index++)
  4649. {
  4650. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4651. {
  4652. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  4653. }
  4654. } // END OF CCS_QUANTITY
  4655. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4656. }
  4657. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4658. {
  4659. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4660. {
  4661. tempIndex = ((gun_index==2) ? 1: 0);
  4662. }
  4663. else
  4664. {
  4665. tempIndex = gun_index;
  4666. }
  4667. for (int index = 0; index < GB_QUANTITY; index++)
  4668. {
  4669. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4670. {
  4671. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  4672. }
  4673. } // END OF GB_QUANTITY
  4674. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4675. }
  4676. else if(gunType[gun_index] == GUN_TYPE_DO)
  4677. {
  4678. tempIndex = gun_index;
  4679. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4680. {
  4681. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4682. {
  4683. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  4684. }
  4685. }
  4686. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4687. }
  4688. else
  4689. {
  4690. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4691. {
  4692. tempIndex = 2;
  4693. }
  4694. else
  4695. {
  4696. tempIndex = gun_index;
  4697. }
  4698. for (int index = 0; index < AC_QUANTITY; index++)
  4699. {
  4700. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4701. {
  4702. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  4703. }
  4704. }
  4705. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  4706. }
  4707. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  4708. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  4709. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  4710. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  4711. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4712. }
  4713. //********************************(4)Power.Active.Import************************************************/
  4714. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Power.Active.Import") != NULL)) ||
  4715. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Power.Active.Import") != NULL)) ||
  4716. (dataType == ReadingContext_Trigger))
  4717. {
  4718. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4719. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4720. {
  4721. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4722. {
  4723. tempIndex = ((gun_index==2) ? 1: 0);
  4724. }
  4725. else
  4726. {
  4727. tempIndex = gun_index;
  4728. }
  4729. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4730. {
  4731. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4732. {
  4733. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  4734. }
  4735. } // END OF FOR
  4736. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4737. }
  4738. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4739. {
  4740. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4741. {
  4742. tempIndex = ((gun_index==2) ? 1: 0);
  4743. }
  4744. else
  4745. {
  4746. tempIndex = gun_index;
  4747. }
  4748. for (int index = 0; index < CCS_QUANTITY; index++)
  4749. {
  4750. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4751. {
  4752. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  4753. }
  4754. }
  4755. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4756. }
  4757. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4758. {
  4759. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4760. {
  4761. tempIndex = ((gun_index==2) ? 1: 0);
  4762. }
  4763. else
  4764. {
  4765. tempIndex = gun_index;
  4766. }
  4767. for (int index = 0; index < GB_QUANTITY; index++)
  4768. {
  4769. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4770. {
  4771. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4772. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  4773. }
  4774. }
  4775. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4776. }
  4777. else if(gunType[gun_index] == GUN_TYPE_DO)
  4778. {
  4779. tempIndex = gun_index;
  4780. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4781. {
  4782. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4783. {
  4784. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4785. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  4786. }
  4787. }
  4788. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4789. }
  4790. else
  4791. {
  4792. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4793. {
  4794. tempIndex = 2;
  4795. }
  4796. else
  4797. {
  4798. tempIndex = gun_index;
  4799. }
  4800. for (int index = 0; index < AC_QUANTITY; index++)
  4801. {
  4802. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4803. {
  4804. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  4805. }
  4806. }
  4807. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  4808. }
  4809. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  4810. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  4811. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  4812. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  4813. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  4814. }
  4815. //***********************************************(5)VOLTAGE L1******************************************************/
  4816. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  4817. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  4818. (dataType == ReadingContext_Trigger))
  4819. {
  4820. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4821. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4822. {
  4823. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4824. {
  4825. tempIndex = ((gun_index==2) ? 1: 0);
  4826. }
  4827. else
  4828. {
  4829. tempIndex = gun_index;
  4830. }
  4831. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4832. {
  4833. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4834. {
  4835. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  4836. }
  4837. }
  4838. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4839. }
  4840. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4841. {
  4842. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4843. {
  4844. tempIndex = ((gun_index==2) ? 1: 0);
  4845. }
  4846. else
  4847. {
  4848. tempIndex = gun_index;
  4849. }
  4850. for (int index = 0; index < CCS_QUANTITY; index++)
  4851. {
  4852. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4853. {
  4854. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  4855. }
  4856. }
  4857. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4858. }
  4859. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4860. {
  4861. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4862. {
  4863. tempIndex = ((gun_index==2) ? 1: 0);
  4864. }
  4865. else
  4866. {
  4867. tempIndex = gun_index;
  4868. }
  4869. for (int index = 0; index < GB_QUANTITY; index++)
  4870. {
  4871. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4872. {
  4873. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  4874. }
  4875. }
  4876. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4877. }
  4878. else if(gunType[gun_index] == GUN_TYPE_DO)
  4879. {
  4880. tempIndex = gun_index;
  4881. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4882. {
  4883. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4884. {
  4885. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  4886. }
  4887. }
  4888. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4889. }
  4890. else
  4891. {
  4892. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4893. {
  4894. tempIndex = 2;
  4895. }
  4896. else
  4897. {
  4898. tempIndex = gun_index;
  4899. }
  4900. for (int index = 0; index < AC_QUANTITY; index++)
  4901. {
  4902. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4903. {
  4904. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  4905. }
  4906. }
  4907. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  4908. }
  4909. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  4910. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  4911. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  4912. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  4913. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4914. }
  4915. //***********************************************(6)SOC******************************************************/
  4916. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "SOC") != NULL)) ||
  4917. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "SOC") != NULL)) ||
  4918. (dataType == ReadingContext_Trigger))
  4919. {
  4920. 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))
  4921. {
  4922. //idx_sample=5;
  4923. //sampledValue = NULL;
  4924. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4925. {
  4926. tempIndex = ((gun_index==2) ? 1: 0);
  4927. }
  4928. else
  4929. {
  4930. tempIndex = gun_index;
  4931. }
  4932. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4933. {
  4934. //tempIndex = ((gun_index==2) ? 1: 0);
  4935. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4936. {
  4937. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4938. {
  4939. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  4940. }
  4941. }
  4942. }
  4943. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4944. {
  4945. //tempIndex = ((gun_index==2) ? 1: 0);
  4946. for (int index = 0; index < CCS_QUANTITY; index++)
  4947. {
  4948. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4949. {
  4950. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  4951. }
  4952. }
  4953. }
  4954. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4955. {
  4956. //tempIndex = ((gun_index==2) ? 1: 0);
  4957. for (int index = 0; index < GB_QUANTITY; index++)
  4958. {
  4959. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4960. {
  4961. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  4962. }
  4963. }
  4964. }
  4965. else if(gunType[gun_index] == GUN_TYPE_DO)
  4966. {
  4967. //tempIndex = ((gun_index==2) ? 1: 0);
  4968. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4969. {
  4970. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4971. {
  4972. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  4973. }
  4974. }
  4975. }
  4976. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  4977. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  4978. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  4979. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  4980. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  4981. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  4982. }
  4983. }
  4984. //********************************(7)Current.Import L2************************************************/
  4985. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  4986. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  4987. (dataType == ReadingContext_Trigger))
  4988. {
  4989. // Only for AC 3 phase
  4990. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4991. {
  4992. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4993. {
  4994. tempIndex = 2;
  4995. }
  4996. else
  4997. {
  4998. tempIndex = gun_index;
  4999. }
  5000. for (int index = 0; index < AC_QUANTITY; index++)
  5001. {
  5002. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5003. {
  5004. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  5005. }
  5006. }
  5007. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  5008. }
  5009. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  5010. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  5011. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  5012. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  5013. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5014. }
  5015. //********************************(8)Current.Import L3************************************************/
  5016. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5017. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5018. (dataType == ReadingContext_Trigger))
  5019. {
  5020. // Only for AC 3 phase
  5021. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5022. {
  5023. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5024. {
  5025. tempIndex = 2;
  5026. }
  5027. else
  5028. {
  5029. tempIndex = gun_index;
  5030. }
  5031. for (int index = 0; index < AC_QUANTITY; index++)
  5032. {
  5033. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5034. {
  5035. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  5036. }
  5037. }
  5038. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  5039. }
  5040. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  5041. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  5042. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  5043. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  5044. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5045. }
  5046. //***********************************************(9)VOLTAGE L2******************************************************/
  5047. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5048. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5049. (dataType == ReadingContext_Trigger))
  5050. {
  5051. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5052. {
  5053. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5054. {
  5055. tempIndex = 2;
  5056. }
  5057. else
  5058. {
  5059. tempIndex = gun_index;
  5060. }
  5061. for (int index = 0; index < AC_QUANTITY; index++)
  5062. {
  5063. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5064. {
  5065. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  5066. }
  5067. }
  5068. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  5069. }
  5070. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  5071. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  5072. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  5073. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  5074. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5075. }
  5076. //***********************************************(10)VOLTAGE L3******************************************************/
  5077. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5078. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5079. (dataType == ReadingContext_Trigger))
  5080. {
  5081. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5082. {
  5083. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5084. {
  5085. tempIndex = 2;
  5086. }
  5087. else
  5088. {
  5089. tempIndex = gun_index;
  5090. }
  5091. for (int index = 0; index < AC_QUANTITY; index++)
  5092. {
  5093. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5094. {
  5095. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  5096. }
  5097. }
  5098. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  5099. }
  5100. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  5101. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  5102. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  5103. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  5104. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5105. }
  5106. // Message create ====================================================================================================
  5107. if(TRUE)
  5108. {
  5109. json_object *MeterValueReq = json_object_new_object();
  5110. json_object *MeterValues = json_object_new_array();
  5111. json_object *sampledValues = json_object_new_array();
  5112. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  5113. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  5114. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  5115. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  5116. {
  5117. json_object *MeterValue = json_object_new_object();
  5118. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  5119. {
  5120. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  5121. {
  5122. json_object *sampledValue = json_object_new_object();
  5123. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  5124. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  5125. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  5126. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  5127. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  5128. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  5129. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  5130. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  5131. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  5132. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  5133. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  5134. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  5135. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  5136. json_object_array_add(sampledValues, sampledValue);
  5137. }
  5138. }
  5139. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  5140. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  5141. json_object_array_add(MeterValues, MeterValue);
  5142. }
  5143. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  5144. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  5145. ,gun_index + 1
  5146. ,MESSAGE_TYPE_CALL
  5147. ,guid
  5148. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  5149. json_object_put(MeterValueReq);
  5150. }
  5151. // Put request guid to hash map
  5152. sprintf(tempdata, "MeterValues,%d", (gun_index));
  5153. 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*/)
  5154. {
  5155. result = PASS;
  5156. //DEBUG_INFO("MeterValues mapitem pass\n");
  5157. }
  5158. if((dataType != ReadingContext_Trigger) &&
  5159. (dataType != ReadingContext_Sample_Clock) &&
  5160. (ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1))
  5161. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  5162. else
  5163. {
  5164. if(FirstHeartBeat)
  5165. LWS_Send(queuedata +2);
  5166. }
  5167. return result;
  5168. }
  5169. //==========================================
  5170. // send confirm routine
  5171. //==========================================
  5172. int sendCancelReservationConfirmation(char *uuid,char *payload)
  5173. {
  5174. mtrace();
  5175. int result = FAIL;
  5176. char message[100]={0};
  5177. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  5178. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5179. LWS_Send(message);
  5180. result = TRUE;
  5181. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  5182. return result;
  5183. }
  5184. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  5185. {
  5186. mtrace();
  5187. int result = FAIL;
  5188. char message[100]={0};
  5189. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  5190. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5191. LWS_Send(message);
  5192. result = TRUE;
  5193. return result;
  5194. }
  5195. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  5196. {
  5197. mtrace();
  5198. int result = FAIL;
  5199. char message[100]={0};
  5200. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  5201. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5202. LWS_Send(message);
  5203. result = TRUE;
  5204. return result;
  5205. }
  5206. int sendClearCacheConfirmation(char *uuid,char *payload)
  5207. {
  5208. mtrace();
  5209. int result = FAIL;
  5210. char message[500]={0};
  5211. DEBUG_INFO("sendClearCacheConfirmation...\n");
  5212. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5213. LWS_Send(message);
  5214. return result;
  5215. }
  5216. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  5217. {
  5218. mtrace();
  5219. int result = FAIL;
  5220. char message[500]={0};
  5221. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  5222. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5223. LWS_Send(message);
  5224. return result;
  5225. }
  5226. int sendDataTransferConfirmation(char *uuid,char *payload)
  5227. {
  5228. mtrace();
  5229. char statusStr[20]={0};
  5230. char dataStr[10]={0};
  5231. char sstr[20]={0};
  5232. int c = 0;
  5233. char *loc;
  5234. int result = FAIL;
  5235. DEBUG_INFO("sendDataTransferConfirmation...\n");
  5236. /**********************status**************************/
  5237. loc = strstr(payload, "status");
  5238. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5239. c = 0;
  5240. while (loc[3+strlen("status")+c] != '\"')
  5241. {
  5242. sstr[c] = loc[3+strlen("status")+c];
  5243. c++;
  5244. }
  5245. sstr[c] = '\0';
  5246. strcpy(statusStr, sstr);
  5247. /**********************data**************************/
  5248. loc = strstr(payload, "data");
  5249. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5250. c = 0;
  5251. while (loc[3+strlen("data")+c] != '\"')
  5252. {
  5253. sstr[c] = loc[3+strlen("data")+c];
  5254. c++;
  5255. }
  5256. sstr[c] = '\0';
  5257. strcpy(dataStr, sstr);
  5258. return result;
  5259. }
  5260. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  5261. {
  5262. mtrace();
  5263. int result = FAIL;
  5264. char message[1000]={0};
  5265. int CompositeScheduleIndex = 0;
  5266. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  5267. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  5268. if(nPeriod == 0)
  5269. {
  5270. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  5271. {
  5272. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  5273. ,MESSAGE_TYPE_CALLRESULT
  5274. ,uuid
  5275. ,payload
  5276. ,connectorIdInt);
  5277. }
  5278. else
  5279. {
  5280. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  5281. ,MESSAGE_TYPE_CALLRESULT
  5282. ,uuid
  5283. ,payload
  5284. ,connectorIdInt
  5285. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5286. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5287. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5288. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  5289. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  5290. }
  5291. }
  5292. else
  5293. {
  5294. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  5295. ,MESSAGE_TYPE_CALLRESULT
  5296. ,uuid
  5297. ,payload
  5298. ,connectorIdInt
  5299. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5300. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5301. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5302. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  5303. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  5304. {
  5305. if (idx_sample == 0)
  5306. {
  5307. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5308. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5309. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5310. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5311. }
  5312. else
  5313. {
  5314. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5315. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5316. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5317. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5318. }
  5319. }
  5320. sprintf(message + strlen(message), "]}}]");
  5321. }
  5322. LWS_Send(message);
  5323. result = TRUE;
  5324. return result;
  5325. }
  5326. int sendGetConfigurationConfirmation(char *uuid)
  5327. {
  5328. mtrace();
  5329. int result = FAIL;
  5330. int MaxKeySupported = 0;
  5331. int sentConfigurationNumber= 0;
  5332. int sentunConfigurationNumber= 0;
  5333. char message[4000]={0};
  5334. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5335. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5336. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5337. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5338. ,MESSAGE_TYPE_CALLRESULT
  5339. ,uuid );
  5340. //configuration key
  5341. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5342. {
  5343. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5344. {
  5345. if (sentConfigurationNumber == 0)
  5346. {
  5347. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5348. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5349. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5350. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5351. }
  5352. else
  5353. {
  5354. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5355. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5356. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5357. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5358. }
  5359. sentConfigurationNumber = sentConfigurationNumber + 1;
  5360. }
  5361. }
  5362. sprintf(message + strlen(message), "]");
  5363. if(UnknownKeynum != 0)
  5364. {
  5365. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5366. //unkown key
  5367. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5368. {
  5369. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5370. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5371. if(sentunConfigurationNumber == 0)
  5372. {
  5373. sprintf(message + strlen(message), "\"%s\""
  5374. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5375. }
  5376. else
  5377. {
  5378. sprintf(message + strlen(message), ",\"%s\""
  5379. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5380. }
  5381. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5382. }
  5383. sprintf(message + strlen(message), "]");
  5384. }
  5385. sprintf(message + strlen(message), "}]");
  5386. LWS_Send(message);
  5387. return result;
  5388. }
  5389. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5390. {
  5391. mtrace();
  5392. int result = FAIL;
  5393. char message[400]={0};
  5394. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5395. if(strcmp(payload,"")==0)
  5396. {
  5397. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5398. }
  5399. else
  5400. {
  5401. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5402. }
  5403. LWS_Send(message);
  5404. result = TRUE;
  5405. return result;
  5406. }
  5407. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5408. {
  5409. mtrace();
  5410. int result = FAIL;
  5411. char message[80]={0};
  5412. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5413. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  5414. LWS_Send(message);
  5415. result = TRUE;
  5416. return result;
  5417. }
  5418. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5419. {
  5420. mtrace();
  5421. int result = FAIL;
  5422. char message[80]={0};
  5423. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5424. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5425. LWS_Send(message);
  5426. result = TRUE;
  5427. return result;
  5428. }
  5429. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5430. {
  5431. mtrace();
  5432. int result = FAIL;
  5433. char message[80]={0};
  5434. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5435. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5436. LWS_Send(message);
  5437. result = TRUE;
  5438. return result;
  5439. }
  5440. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5441. {
  5442. mtrace();
  5443. int result = FAIL;
  5444. char message[80]={0};
  5445. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5446. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5447. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5448. LWS_Send(message);
  5449. result = TRUE;
  5450. return result;
  5451. }
  5452. int sendResetConfirmation(char *uuid,char *payload)
  5453. {
  5454. mtrace();
  5455. int result = FAIL;
  5456. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  5457. char message[80]={0};
  5458. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  5459. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5460. LWS_Send(message);
  5461. result = TRUE;
  5462. return result;
  5463. }
  5464. int sendSendLocalListConfirmation(char *uuid,char *payload)
  5465. {
  5466. mtrace();
  5467. int result = FAIL;
  5468. char message[500]={0};
  5469. // [ 3, "1571284266109", { "status": "Accepted" } ]
  5470. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5471. LWS_Send(message);
  5472. result = TRUE;
  5473. return result;
  5474. }
  5475. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  5476. {
  5477. mtrace();
  5478. int result = FAIL;
  5479. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  5480. char message[80]={0};
  5481. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  5482. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5483. LWS_Send(message);
  5484. result = TRUE;
  5485. return result;
  5486. }
  5487. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  5488. {
  5489. mtrace();
  5490. int result = FAIL;
  5491. char message[80]={0};
  5492. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  5493. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5494. LWS_Send(message);
  5495. result = TRUE;
  5496. return result;
  5497. }
  5498. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  5499. {
  5500. mtrace();
  5501. int result = FAIL;
  5502. char message[80]={0};
  5503. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5504. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  5505. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5506. LWS_Send(message);
  5507. result = TRUE;
  5508. return result;
  5509. }
  5510. int sendUpdateFirmwareConfirmation(char *uuid)
  5511. {
  5512. mtrace();
  5513. int result = FAIL;
  5514. char message[60]={0};
  5515. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5516. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  5517. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5518. LWS_Send(message);
  5519. result = TRUE;
  5520. return result;
  5521. }
  5522. //==========================================
  5523. // send CallError routine
  5524. //==========================================
  5525. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  5526. {
  5527. mtrace();
  5528. char message[220]={0};
  5529. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  5530. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  5531. LWS_Send(message);
  5532. }
  5533. //==========================================
  5534. // Handle server request routine Start
  5535. //==========================================
  5536. int handleCancelReservationRequest(char *uuid, char *payload)
  5537. {
  5538. mtrace();
  5539. int result = FAIL;
  5540. int gunNO = 0;
  5541. int reservationIdInt = -1;
  5542. char comfirmstr[20];
  5543. DEBUG_INFO("handleCancelReservationRequest...\n");
  5544. json_object *CancelReservation;
  5545. CancelReservation = json_tokener_parse(payload);
  5546. if(!is_error(CancelReservation))
  5547. {
  5548. // Required data
  5549. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  5550. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  5551. }
  5552. json_object_put(CancelReservation);
  5553. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  5554. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5555. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  5556. if(reservationIdInt != -1)
  5557. {
  5558. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  5559. //check Transaction active
  5560. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5561. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5562. {
  5563. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  5564. {
  5565. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5566. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5567. if(gunType[2] == GUN_TYPE_CHAdeMO)
  5568. {
  5569. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  5570. }
  5571. else
  5572. {
  5573. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  5574. }
  5575. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5576. goto end;
  5577. }
  5578. }
  5579. for (int index = 0; index < CCS_QUANTITY; index++)
  5580. {
  5581. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  5582. {
  5583. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5584. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5585. if(gunType[2] == GUN_TYPE_CCS)
  5586. {
  5587. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  5588. }
  5589. else
  5590. {
  5591. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  5592. }
  5593. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5594. goto end;
  5595. }
  5596. }
  5597. for (int index = 0; index < GB_QUANTITY; index++)
  5598. {
  5599. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  5600. {
  5601. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5602. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5603. if(gunType[2] == GUN_TYPE_GBT)
  5604. {
  5605. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  5606. }
  5607. else
  5608. {
  5609. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  5610. }
  5611. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5612. goto end;
  5613. }
  5614. }
  5615. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5616. {
  5617. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  5618. {
  5619. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5620. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5621. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  5622. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5623. goto end;
  5624. }
  5625. }
  5626. for (int index = 0; index < AC_QUANTITY; index++)
  5627. {
  5628. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  5629. {
  5630. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5631. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5632. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5633. {
  5634. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  5635. }
  5636. else
  5637. {
  5638. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  5639. }
  5640. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5641. goto end;
  5642. }
  5643. }
  5644. }
  5645. //The reservationId does NOT match the reservationId
  5646. sendCancelReservationConfirmation(uuid, comfirmstr);
  5647. end:
  5648. // Fill in ocpp packet uuid
  5649. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  5650. return result;
  5651. }
  5652. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  5653. {
  5654. mtrace();
  5655. int result = FAIL;
  5656. int gunIndex = 0;
  5657. char typeStr[16]={0};
  5658. char comfirmstr[20];
  5659. int specificId = FALSE;
  5660. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  5661. json_object *ChangeAvailability;
  5662. ChangeAvailability = json_tokener_parse(payload);
  5663. if(!is_error(ChangeAvailability))
  5664. {
  5665. // Required data
  5666. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  5667. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  5668. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  5669. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  5670. }
  5671. json_object_put(ChangeAvailability);
  5672. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5673. {
  5674. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  5675. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  5676. }
  5677. else if(gunIndex == 0)
  5678. {
  5679. for(int i=0; i < gunTotalNumber; i++)
  5680. {
  5681. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  5682. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  5683. }
  5684. }
  5685. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5686. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5687. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  5688. {
  5689. specificId = TRUE;
  5690. }
  5691. if(specificId == FALSE)
  5692. goto end;
  5693. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  5694. {
  5695. //----------------------gunIndex is 0 ------------------------------------------------//
  5696. if(gunIndex == 0)
  5697. {
  5698. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5699. {
  5700. for(int i=0; i < gunTotalNumber; i++)
  5701. {
  5702. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5703. {
  5704. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  5705. {
  5706. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5707. {
  5708. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5709. goto end;
  5710. }
  5711. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5712. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5713. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5714. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5715. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5716. {
  5717. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5718. goto end;
  5719. }
  5720. }
  5721. }//END FOR CHAdeMO_QUANTITY
  5722. for (int index = 0; index < CCS_QUANTITY; index++)
  5723. {
  5724. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  5725. {
  5726. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  5727. {
  5728. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5729. goto end;
  5730. }
  5731. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5732. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5733. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5734. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5735. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5736. {
  5737. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5738. goto end;
  5739. }
  5740. }
  5741. }//END FOR CCS_QUANTITY
  5742. for (int index = 0; index < GB_QUANTITY; index++)
  5743. {
  5744. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  5745. {
  5746. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5747. {
  5748. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5749. goto end;
  5750. }
  5751. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5752. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5753. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5754. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5755. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5756. {
  5757. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5758. goto end;
  5759. }
  5760. }
  5761. }// END FOR GB_QUANTITY
  5762. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5763. {
  5764. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  5765. {
  5766. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5767. {
  5768. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5769. goto end;
  5770. }
  5771. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  5772. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  5773. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  5774. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  5775. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5776. {
  5777. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5778. goto end;
  5779. }
  5780. }
  5781. }// END FOR GENERAL_GUN_QUANTITY
  5782. for (int index = 0; index < AC_QUANTITY; index++)
  5783. {
  5784. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  5785. {
  5786. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5787. {
  5788. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5789. goto end;
  5790. }
  5791. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5792. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5793. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5794. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5795. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5796. {
  5797. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5798. goto end;
  5799. }
  5800. }
  5801. }//END FOR AC_QUANTITY
  5802. }// END FOR gunTotalNumber
  5803. }
  5804. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5805. {
  5806. for(int i=0; i < gunTotalNumber; i++)
  5807. {
  5808. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5809. {
  5810. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5811. goto end;
  5812. }
  5813. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5814. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  5815. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  5816. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  5817. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5818. {
  5819. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5820. goto end;
  5821. }
  5822. }
  5823. }
  5824. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5825. goto end;
  5826. }
  5827. //----------------------gunIndex is not 0 ------------------------------------------------//
  5828. //check Transaction active
  5829. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5830. {
  5831. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  5832. {
  5833. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  5834. {
  5835. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5836. goto end;
  5837. }
  5838. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5839. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5840. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5841. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5842. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5843. {
  5844. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5845. goto end;
  5846. }
  5847. else
  5848. {
  5849. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  5850. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5851. goto end;
  5852. }
  5853. }
  5854. }//END FOR CHAdeMO_QUANTITY
  5855. for (int index = 0; index < CCS_QUANTITY; index++)
  5856. {
  5857. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  5858. {
  5859. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  5860. {
  5861. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5862. goto end;
  5863. }
  5864. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5865. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5866. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5867. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5868. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5869. {
  5870. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5871. goto end;
  5872. }
  5873. else
  5874. {
  5875. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  5876. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5877. goto end;
  5878. }
  5879. }
  5880. }//END FOR CCS_QUANTITY
  5881. for (int index = 0; index < GB_QUANTITY; index++)
  5882. {
  5883. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  5884. {
  5885. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5886. {
  5887. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5888. goto end;
  5889. }
  5890. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5891. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5892. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5893. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5894. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5895. {
  5896. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5897. goto end;
  5898. }
  5899. else
  5900. {
  5901. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  5902. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5903. goto end;
  5904. }
  5905. }
  5906. }// END FOR GB_QUANTITY
  5907. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5908. {
  5909. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  5910. {
  5911. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5912. {
  5913. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5914. goto end;
  5915. }
  5916. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  5917. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  5918. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  5919. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  5920. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5921. {
  5922. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5923. goto end;
  5924. }
  5925. else
  5926. {
  5927. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  5928. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5929. goto end;
  5930. }
  5931. }
  5932. }// END FOR GENERAL_GUN_QUANTITY
  5933. for (int index = 0; index < AC_QUANTITY; index++)
  5934. {
  5935. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  5936. {
  5937. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5938. {
  5939. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5940. goto end;
  5941. }
  5942. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5943. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5944. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5945. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5946. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5947. {
  5948. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5949. goto end;
  5950. }
  5951. else
  5952. {
  5953. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  5954. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5955. goto end;
  5956. }
  5957. }
  5958. }//END FOR AC_QUANTITY
  5959. }//END FOR AvailabilityTypeStr[Inoperative]
  5960. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  5961. {
  5962. //----------------------gunIndex is 0 ------------------------------------------------//
  5963. if(gunIndex == 0)
  5964. {
  5965. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5966. {
  5967. for(int i=0; i < gunTotalNumber; i++)
  5968. {
  5969. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5970. {
  5971. 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
  5972. {
  5973. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5974. goto end;
  5975. }
  5976. }//END FOR CHAdeMO_QUANTITY
  5977. for (int index = 0; index < CCS_QUANTITY; index++)
  5978. {
  5979. 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
  5980. {
  5981. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5982. goto end;
  5983. }
  5984. }//END FOR CCS_QUANTITY
  5985. for (int index = 0; index < GB_QUANTITY; index++)
  5986. {
  5987. 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
  5988. {
  5989. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5990. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5991. goto end;
  5992. }
  5993. }// END FOR GB_QUANTITY
  5994. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5995. {
  5996. 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
  5997. {
  5998. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5999. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6000. goto end;
  6001. }
  6002. }// END FOR GENERAL_GUN_QUANTITY
  6003. for (int index = 0; index < AC_QUANTITY; index++)
  6004. {
  6005. 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
  6006. {
  6007. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6008. goto end;
  6009. }
  6010. }//END FOR CHAdeMO_QUANTITY
  6011. }// END FOR gunTotalNumber
  6012. }
  6013. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6014. {
  6015. for(int i=0; i < gunTotalNumber; i++)
  6016. {
  6017. for (int index = 0; index < AC_QUANTITY; index++)
  6018. {
  6019. 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
  6020. {
  6021. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6022. goto end;
  6023. }
  6024. }//END FOR CHAdeMO_QUANTITY
  6025. } // END FOR gunTotalNumber
  6026. }
  6027. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6028. goto end;
  6029. }
  6030. //----------------------gunIndex is not 0 ------------------------------------------------//
  6031. //check Transaction active
  6032. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6033. {
  6034. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6035. {
  6036. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6037. goto end;
  6038. }
  6039. }//END FOR CHAdeMO_QUANTITY
  6040. for (int index = 0; index < CCS_QUANTITY; index++)
  6041. {
  6042. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6043. {
  6044. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6045. goto end;
  6046. }
  6047. }//END FOR CCS_QUANTITY
  6048. for (int index = 0; index < GB_QUANTITY; index++)
  6049. {
  6050. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6051. {
  6052. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6053. goto end;
  6054. }
  6055. }// END FOR GB_QUANTITY
  6056. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6057. {
  6058. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6059. {
  6060. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6061. goto end;
  6062. }
  6063. }// END FOR GENERAL_GUN_QUANTITY
  6064. for (int index = 0; index < AC_QUANTITY; index++)
  6065. {
  6066. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6067. {
  6068. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6069. goto end;
  6070. }
  6071. }//END FOR AC_QUANTITY
  6072. }//END FOR AvailabilityTypeStr[Operative]
  6073. end:
  6074. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6075. {
  6076. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  6077. }
  6078. else
  6079. {
  6080. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  6081. }
  6082. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6083. {
  6084. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6085. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6086. }
  6087. else if(gunIndex == 0)
  6088. {
  6089. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6090. {
  6091. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  6092. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  6093. }
  6094. }
  6095. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  6096. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6097. return result;
  6098. }
  6099. int handleChangeConfigurationRequest(char *uuid, char *payload)
  6100. {
  6101. mtrace();
  6102. int result = FAIL;
  6103. char keystr[40]={0};
  6104. char valuestr[256]={0};
  6105. char comfirmstr[20]={0};
  6106. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  6107. json_object *ChangeConfiguration;
  6108. ChangeConfiguration = json_tokener_parse(payload);
  6109. if(!is_error(ChangeConfiguration))
  6110. {
  6111. // Required data
  6112. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  6113. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  6114. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  6115. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  6116. }
  6117. json_object_put(ChangeConfiguration);
  6118. if((uuid==NULL) || (payload ==NULL) )
  6119. {
  6120. DEBUG_ERROR("Payload is null\n");
  6121. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6122. }
  6123. else
  6124. {
  6125. int status = setKeyValue(keystr, valuestr);
  6126. switch(status)
  6127. {
  6128. case ConfigurationStatus_Accepted:
  6129. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  6130. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  6131. StoreConfigurationTable();
  6132. break;
  6133. case RebootRequired:
  6134. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  6135. StoreConfigurationTable();
  6136. break;
  6137. case NotSupported:
  6138. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  6139. break;
  6140. case ConfigurationStatus_Rejected:
  6141. default:
  6142. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6143. break;
  6144. }
  6145. }
  6146. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  6147. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  6148. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6149. {
  6150. ChageWebSocketPingInterval(atoi(valuestr));
  6151. }
  6152. if((strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6153. {
  6154. SetOcppConnStatus(FALSE);
  6155. }
  6156. return result;
  6157. }
  6158. int handleClearCacheRequest(char *uuid, char *payload)
  6159. {
  6160. mtrace();
  6161. int result = FAIL;
  6162. char comfirmstr[20];
  6163. char rmFileCmd[100]={0};
  6164. struct stat stats;
  6165. DEBUG_INFO("handleClearCacheRequest...\n");
  6166. stat("/Storage/OCPP", &stats);
  6167. // Check for directory existence
  6168. if (S_ISDIR(stats.st_mode) == 1)
  6169. {}
  6170. else
  6171. {
  6172. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  6173. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  6174. system(rmFileCmd);
  6175. }
  6176. if(OCPP_cleanLocalCache())
  6177. {
  6178. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  6179. }
  6180. else
  6181. {
  6182. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  6183. }
  6184. sendClearCacheConfirmation(uuid, comfirmstr);
  6185. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6186. return result;
  6187. }
  6188. int handleClearChargingProfileRequest(char *uuid, char *payload)
  6189. {
  6190. mtrace();
  6191. int result = FAIL;
  6192. int resultRename;
  6193. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  6194. char chargingProfilePurposeStr[26]={0};
  6195. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  6196. char tempchargingProfilePurposeStr[26]={0};
  6197. char str[100]={0};
  6198. char fname[200]={0};
  6199. char comfirmstr[20]={0};
  6200. char word[1600]={0};
  6201. int clearflag = FALSE;
  6202. int chargingProfileIdIsNULL = FALSE;
  6203. int connectorIsNULL = FALSE;
  6204. int chargingProfilePurposeIsNULL = FALSE;
  6205. int stackLevelIsNULL = FALSE;
  6206. //int GotoEnd = FALSE;
  6207. FILE *fptr1, *fptr2;
  6208. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  6209. int n_chargingProfile=0;
  6210. int isEmptyFile = FALSE;
  6211. char sLineWord[1600]={0};
  6212. char chargingProfiles[10][100]={0};
  6213. int ChargeProfileCount = 0;
  6214. int ch;
  6215. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  6216. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  6217. json_object *ClearChargingProfile;
  6218. ClearChargingProfile = json_tokener_parse(payload);
  6219. if(!is_error(ClearChargingProfile))
  6220. {
  6221. // Optional data
  6222. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  6223. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  6224. else
  6225. chargingProfileIdIsNULL = TRUE;
  6226. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  6227. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  6228. else
  6229. connectorIsNULL = TRUE;
  6230. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  6231. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  6232. else
  6233. chargingProfilePurposeIsNULL = TRUE;
  6234. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  6235. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  6236. else
  6237. stackLevelIsNULL = TRUE;
  6238. }
  6239. json_object_put(ClearChargingProfile);
  6240. if(connectorIsNULL == FALSE)
  6241. {
  6242. switch(connectorIdInt)
  6243. {
  6244. case 0:
  6245. if(chargingProfilePurposeIsNULL == TRUE)
  6246. {
  6247. int l = 0;
  6248. strcpy(fname, ChargePointMaxProfile_JSON);
  6249. if((access(fname,F_OK))!=-1)
  6250. {
  6251. strcpy(chargingProfiles[l], fname);
  6252. l = l + 1;
  6253. }
  6254. strcpy(fname, TxDefaultProfile_0_JSON);
  6255. if((access(fname,F_OK))!=-1)
  6256. {
  6257. strcpy(chargingProfiles[l], fname);
  6258. l = l + 1;
  6259. }
  6260. ChargeProfileCount = l;
  6261. }
  6262. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  6263. {
  6264. strcpy(fname, ChargePointMaxProfile_JSON);
  6265. if((access(fname,F_OK))!=-1)
  6266. {
  6267. strcpy(chargingProfiles[0], fname);
  6268. ChargeProfileCount = 1;
  6269. }
  6270. }
  6271. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6272. {
  6273. strcpy(fname, TxDefaultProfile_0_JSON);
  6274. if((access(fname,F_OK))!=-1)
  6275. {
  6276. strcpy(chargingProfiles[0], fname);
  6277. ChargeProfileCount = 1;
  6278. }
  6279. }
  6280. break;
  6281. default:
  6282. if(chargingProfilePurposeIsNULL == TRUE)
  6283. {
  6284. int m = 0;
  6285. memset(fname, 0, ARRAY_SIZE(fname));
  6286. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6287. if((access(fname,F_OK))!=-1)
  6288. {
  6289. strcpy(chargingProfiles[m], fname);
  6290. m = m + 1;
  6291. }
  6292. memset(fname, 0, ARRAY_SIZE(fname));
  6293. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6294. if((access(fname,F_OK))!=-1)
  6295. {
  6296. strcpy(chargingProfiles[m], fname);
  6297. m = m + 1;
  6298. }
  6299. ChargeProfileCount = m;
  6300. }
  6301. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6302. {
  6303. //strcpy(fname, TxDefaultProfile_1_JSON);
  6304. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6305. if((access(fname,F_OK))!=-1)
  6306. {
  6307. strcpy(chargingProfiles[0], fname);
  6308. ChargeProfileCount = 1;
  6309. }
  6310. }
  6311. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  6312. {
  6313. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6314. if((access(fname,F_OK))!=-1)
  6315. {
  6316. strcpy(chargingProfiles[0], fname);
  6317. ChargeProfileCount = 1;
  6318. }
  6319. //strcpy(fname, TxProfile_1_JSON);
  6320. }
  6321. //strcpy(fname, ChargePointMaxProfile_JSON );
  6322. break;
  6323. }
  6324. }
  6325. else // Check all Charging Profiles
  6326. {
  6327. int i = 0;
  6328. char fnametemp[200]={0};
  6329. ChargeProfileCount = 0;
  6330. //Check ChargePointMaxProfile.json exit
  6331. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  6332. {
  6333. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  6334. i = i + 1;
  6335. }
  6336. //Check TxDefaultProfile_0.json exit
  6337. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  6338. {
  6339. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  6340. i = i + 1;
  6341. }
  6342. //Check TxDefaultProfile_%d.json
  6343. for(int j=1; j <= gunTotalNumber; j++)
  6344. {
  6345. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6346. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  6347. if((access(fnametemp,F_OK))!=-1)
  6348. {
  6349. strcpy(chargingProfiles[i], fnametemp);
  6350. i = i + 1;
  6351. }
  6352. }
  6353. //Check TxProfile_%d.json
  6354. for(int j=1; j <= gunTotalNumber; j++)
  6355. {
  6356. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6357. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  6358. if((access(fnametemp,F_OK))!=-1)
  6359. {
  6360. strcpy(chargingProfiles[i], fnametemp);
  6361. i = i + 1;
  6362. }
  6363. }
  6364. ChargeProfileCount = i;
  6365. }// End connectorIsNULL is TRUE
  6366. if(ChargeProfileCount == 0)
  6367. {
  6368. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6369. goto end;
  6370. }
  6371. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  6372. {
  6373. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6374. goto end;
  6375. }
  6376. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  6377. {
  6378. memset(str, 0, ARRAY_SIZE(str));
  6379. // clear temp file
  6380. sprintf(str,"rm -f %s",temp);
  6381. system(str);
  6382. for(int k=0; k < ChargeProfileCount; k++)
  6383. {
  6384. memset(str, 0, ARRAY_SIZE(str));
  6385. //clear file in C
  6386. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6387. system(str);
  6388. }
  6389. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6390. goto end;
  6391. }
  6392. else if(connectorIsNULL == TRUE)
  6393. {
  6394. for(int k=0; k < ChargeProfileCount; k++)
  6395. {
  6396. fptr1 = fopen(chargingProfiles[k], "r");
  6397. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  6398. //Check Charging Profile Count
  6399. while(fscanf(fptr1, "%s", word) != EOF)
  6400. {
  6401. //DEBUG_INFO("word=%s\n",word);
  6402. if(strstr(word, "chargingProfileId")!= NULL)
  6403. {
  6404. //DEBUG_INFO("test chargingProfileId \n");
  6405. n_chargingProfile = n_chargingProfile + 1;
  6406. //DEBUG_INFO("chargingProfileId Found\n");
  6407. }
  6408. }
  6409. rewind(fptr1);
  6410. //search Charging Profile Element
  6411. //int i= 0;
  6412. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6413. {
  6414. json_object *tmpProfilee;
  6415. tmpProfilee = json_tokener_parse(sLineWord);
  6416. if(!is_error(tmpProfilee))
  6417. {
  6418. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  6419. {
  6420. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  6421. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  6422. }
  6423. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  6424. {
  6425. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  6426. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  6427. }
  6428. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  6429. {
  6430. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  6431. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  6432. }
  6433. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  6434. {
  6435. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  6436. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  6437. }
  6438. }
  6439. json_object_put(tmpProfilee);
  6440. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6441. {
  6442. //------- not write to fptr2-------//
  6443. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6444. //clearflag = TRUE;
  6445. }
  6446. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  6447. {
  6448. //------- not write to fptr2-------//
  6449. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6450. }
  6451. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6452. {
  6453. //------- not write to fptr2-------//
  6454. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6455. }
  6456. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  6457. {
  6458. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6459. }
  6460. else
  6461. {
  6462. fprintf(fptr2, sLineWord);//writing data into file
  6463. }
  6464. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6465. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6466. if(clearflag == TRUE)
  6467. {
  6468. fclose(fptr1);
  6469. fclose(fptr2);
  6470. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6471. system(str);
  6472. // clear temp file
  6473. sprintf(str,"rm -f %s",temp);
  6474. system(str);
  6475. }
  6476. else
  6477. {
  6478. fclose(fptr1);
  6479. fclose(fptr2);
  6480. memset(str, 0, ARRAY_SIZE(str));
  6481. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6482. system(str);
  6483. resultRename = rename(temp, chargingProfiles[k]);
  6484. if(resultRename == 0)
  6485. {
  6486. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  6487. }
  6488. else
  6489. {
  6490. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  6491. }
  6492. if(comfirmstr[0]== 0)
  6493. {
  6494. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6495. }
  6496. //Check chargingProfile is empty file
  6497. /*------ Read the file ----------------*/
  6498. fptr1=fopen(chargingProfiles[k],"r");
  6499. ch=fgetc(fptr1);
  6500. rewind(fptr1);
  6501. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6502. if(ch!=EOF)
  6503. {
  6504. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6505. {
  6506. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6507. if(sLineWord[0]=='\0')
  6508. {
  6509. isEmptyFile = TRUE;
  6510. break;
  6511. }
  6512. else
  6513. {
  6514. isEmptyFile = FALSE;
  6515. break;
  6516. }
  6517. }
  6518. }
  6519. else
  6520. isEmptyFile = TRUE;
  6521. fclose(fptr1);
  6522. if(isEmptyFile == TRUE)
  6523. {
  6524. memset(str, 0, ARRAY_SIZE(str));
  6525. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6526. system(str);
  6527. }
  6528. }
  6529. }// End of while(int k=0; k < ChargePointCount; k++)
  6530. }
  6531. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  6532. {
  6533. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  6534. for(int k=0; k < ChargeProfileCount; k++)
  6535. {
  6536. fptr1 = fopen(chargingProfiles[k], "r");
  6537. fptr2 = fopen(temp, "w+");
  6538. //Check Charging Profile Count
  6539. while(fscanf(fptr1, "%s", word) != EOF)
  6540. {
  6541. //DEBUG_INFO("word=%s\n",word);
  6542. if(strstr(word, "chargingProfileId")!= NULL)
  6543. {
  6544. n_chargingProfile = n_chargingProfile + 1;
  6545. }
  6546. }
  6547. rewind(fptr1);
  6548. //search Charging Profile Element
  6549. //int i= 0;
  6550. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6551. {
  6552. json_object *tmpProfilee;
  6553. tmpProfilee = json_tokener_parse(sLineWord);
  6554. if(!is_error(tmpProfilee))
  6555. {
  6556. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  6557. {
  6558. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  6559. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  6560. }
  6561. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  6562. {
  6563. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  6564. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  6565. }
  6566. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  6567. {
  6568. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  6569. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  6570. }
  6571. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  6572. {
  6573. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  6574. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  6575. }
  6576. }
  6577. json_object_put(tmpProfilee);
  6578. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6579. {
  6580. //------- not write to fptr2-------//
  6581. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6582. //clearflag = TRUE;
  6583. }
  6584. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6585. {
  6586. //------- not write to fptr2-------//
  6587. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6588. }
  6589. else if(stackLevelIsNULL == TRUE)
  6590. {
  6591. //Clear Whole File
  6592. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6593. clearflag = TRUE;
  6594. break;
  6595. }
  6596. else
  6597. {
  6598. fprintf(fptr2, sLineWord);//writing data into file
  6599. }
  6600. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6601. }
  6602. if(clearflag == TRUE)
  6603. {
  6604. fclose(fptr1);
  6605. fclose(fptr2);
  6606. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6607. system(str);
  6608. // clear temp file
  6609. sprintf(str,"rm -f %s",temp);
  6610. system(str);
  6611. }
  6612. else
  6613. {
  6614. fclose(fptr1);
  6615. fclose(fptr2);
  6616. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6617. system(str);
  6618. resultRename = rename(temp, chargingProfiles[k]);
  6619. if(resultRename == 0)
  6620. {
  6621. DEBUG_INFO("File ChargingProfile renamed successfully");
  6622. }
  6623. else
  6624. {
  6625. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6626. }
  6627. if(comfirmstr[0]== 0)
  6628. {
  6629. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6630. }
  6631. //Check chargingProfile is empty file
  6632. /*------ Read the file ----------------*/
  6633. fptr1=fopen(chargingProfiles[k],"r");
  6634. ch=fgetc(fptr1);
  6635. rewind(fptr1);
  6636. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6637. if(ch!=EOF)
  6638. {
  6639. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6640. {
  6641. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6642. if(sLineWord[0]=='\0')
  6643. {
  6644. isEmptyFile = TRUE;
  6645. break;
  6646. }
  6647. else
  6648. {
  6649. isEmptyFile = FALSE;
  6650. break;
  6651. }
  6652. }
  6653. }
  6654. else
  6655. isEmptyFile = TRUE;
  6656. fclose(fptr1);
  6657. if(isEmptyFile == TRUE)
  6658. {
  6659. memset(str, 0, ARRAY_SIZE(str));
  6660. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6661. system(str);
  6662. }
  6663. /*------- End of reading ---------------*/
  6664. }
  6665. } // while(int k=0; k < ChargeProfileCount; k++)
  6666. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  6667. end:
  6668. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  6669. {
  6670. if(connectorIdInt == 0)
  6671. {
  6672. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  6673. {
  6674. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  6675. }
  6676. }
  6677. else
  6678. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  6679. }
  6680. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  6681. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6682. return result;
  6683. }
  6684. void createFirmwareVersionByDataTransfer(void)
  6685. {
  6686. json_object *FirmwareDataTransfer = json_object_new_object();
  6687. // AC & DC model
  6688. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  6689. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  6690. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  6691. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  6692. // DC model
  6693. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O')
  6694. {
  6695. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  6696. {
  6697. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6698. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6699. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  6700. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  6701. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6702. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6703. }
  6704. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  6705. ((gunType[1] != GUN_TYPE_UNKNOWN) || (gunType[2] != GUN_TYPE_UNKNOWN) || (gunType[3] != GUN_TYPE_UNKNOWN)))
  6706. {
  6707. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  6708. }
  6709. }
  6710. else
  6711. {
  6712. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6713. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6714. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6715. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6716. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  6717. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  6718. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  6719. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  6720. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  6721. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  6722. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  6723. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  6724. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  6725. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  6726. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  6727. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  6728. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  6729. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  6730. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  6731. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  6732. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  6733. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  6734. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  6735. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  6736. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  6737. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  6738. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  6739. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  6740. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  6741. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  6742. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  6743. }
  6744. // 4G model
  6745. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  6746. {
  6747. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  6748. }
  6749. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  6750. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  6751. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  6752. json_object_put(FirmwareDataTransfer);
  6753. }
  6754. int handleDataTransferRequest(char *uuid, char *payload)
  6755. {
  6756. mtrace();
  6757. json_object *response = json_object_new_object();
  6758. int result = FAIL;
  6759. char tempvendorId[255]={0};
  6760. char tempmessageId[50]={0};
  6761. char tempdata[512]={0};
  6762. char message[2048]={0};
  6763. DEBUG_INFO("handleDataTransferRequest...\n");
  6764. if((uuid != NULL) && (payload != NULL))
  6765. {
  6766. json_object *DataTransfer;
  6767. DataTransfer = json_tokener_parse(payload);
  6768. if(!is_error(DataTransfer))
  6769. {
  6770. // Required data
  6771. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  6772. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  6773. // Optional data
  6774. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  6775. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  6776. if(json_object_object_get(DataTransfer, "data") != NULL)
  6777. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  6778. result = PASS;
  6779. }
  6780. json_object_put(DataTransfer);
  6781. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  6782. {
  6783. // Send all moudle firmware version on EVSE
  6784. createFirmwareVersionByDataTransfer();
  6785. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6786. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  6787. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6788. json_object_put(response);
  6789. }
  6790. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  6791. {
  6792. system("/usr/bin/run_tmate_restart.sh &");
  6793. }
  6794. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  6795. {
  6796. json_object *data;
  6797. data = json_tokener_parse(tempdata);
  6798. if(!is_error(data))
  6799. {
  6800. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  6801. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  6802. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  6803. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  6804. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  6805. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  6806. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  6807. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  6808. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  6809. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  6810. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6811. }
  6812. else
  6813. {
  6814. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6815. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6816. }
  6817. json_object_put(data);
  6818. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6819. json_object_put(response);
  6820. }
  6821. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  6822. {
  6823. json_object *data;
  6824. data = json_tokener_parse(tempdata);
  6825. if(!is_error(data))
  6826. {
  6827. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  6828. if(json_object_object_get(data, "idToken") != NULL)
  6829. {
  6830. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  6831. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  6832. }
  6833. if(json_object_object_get(data, "price") != NULL)
  6834. {
  6835. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  6836. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  6837. }
  6838. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6839. }
  6840. else
  6841. {
  6842. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6843. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6844. }
  6845. json_object_put(data);
  6846. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6847. json_object_put(response);
  6848. }
  6849. else if(strstr(tempmessageId, "RunningCost") != NULL)
  6850. {
  6851. json_object *data;
  6852. data = json_tokener_parse(tempdata);
  6853. if(!is_error(data))
  6854. {
  6855. if(json_object_object_get(data, "txId") != NULL)
  6856. {
  6857. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  6858. for(int idx = 0;idx<gunTotalNumber;idx++)
  6859. {
  6860. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  6861. {
  6862. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  6863. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  6864. if(json_object_object_get(data, "description") != NULL)
  6865. {
  6866. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  6867. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  6868. }
  6869. }
  6870. }
  6871. }
  6872. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6873. }
  6874. else
  6875. {
  6876. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6877. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6878. }
  6879. json_object_put(data);
  6880. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6881. json_object_put(response);
  6882. }
  6883. else if(strstr(tempmessageId, "FinalCost") != NULL)
  6884. {
  6885. json_object *data;
  6886. data = json_tokener_parse(tempdata);
  6887. if(!is_error(data))
  6888. {
  6889. if(json_object_object_get(data, "txId") != NULL)
  6890. {
  6891. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  6892. for(int idx = 0;idx<gunTotalNumber;idx++)
  6893. {
  6894. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  6895. {
  6896. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  6897. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  6898. if(json_object_object_get(data, "description") != NULL)
  6899. {
  6900. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  6901. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  6902. }
  6903. }
  6904. }
  6905. }
  6906. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6907. }
  6908. else
  6909. {
  6910. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6911. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6912. }
  6913. json_object_put(data);
  6914. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6915. json_object_put(response);
  6916. }
  6917. else
  6918. {
  6919. // Can not find valid message id
  6920. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  6921. }
  6922. }
  6923. else
  6924. {
  6925. // Payload is null
  6926. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  6927. }
  6928. LWS_Send(message);
  6929. return result;
  6930. }
  6931. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  6932. {
  6933. mtrace();
  6934. int result = FAIL;
  6935. int connectorIdInt, durationInt;
  6936. char chargingRateUnitStr[4]={0};
  6937. char comfirmstr[20];
  6938. int confirmPeriods = 0;
  6939. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  6940. json_object *GetCompositeSchedule;
  6941. GetCompositeSchedule = json_tokener_parse(payload);
  6942. if(!is_error(GetCompositeSchedule))
  6943. {
  6944. // Required data
  6945. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  6946. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  6947. else
  6948. connectorIdInt = -1;
  6949. if(json_object_object_get(GetCompositeSchedule, "duration"))
  6950. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  6951. else
  6952. durationInt = 86400;
  6953. // Optional data
  6954. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  6955. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  6956. }
  6957. json_object_put(GetCompositeSchedule);
  6958. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  6959. if((connectorIdInt == 0) ||
  6960. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  6961. {
  6962. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  6963. struct StructChargingProfile tmpProfile[1];
  6964. if(strstr(chargingRateUnitStr, "W") != NULL)
  6965. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  6966. else
  6967. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  6968. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6969. {
  6970. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6971. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6972. }
  6973. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  6974. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  6975. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  6976. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6977. {
  6978. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6979. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6980. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  6981. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  6982. {
  6983. confirmPeriods = idx;
  6984. break;
  6985. }
  6986. }
  6987. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6988. }
  6989. else
  6990. {
  6991. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  6992. }
  6993. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  6994. return result;
  6995. }
  6996. int handleGetConfigurationRequest(char *uuid, char *payload)
  6997. {
  6998. mtrace();
  6999. int result = FAIL;
  7000. int MaxKeySupported = 0;
  7001. int n_keys = 0;
  7002. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  7003. DEBUG_INFO("handleGetConfigurationRequest...\n");
  7004. json_object *GetConfiguration;
  7005. GetConfiguration = json_tokener_parse(payload);
  7006. if(!is_error(GetConfiguration))
  7007. {
  7008. // Optional data
  7009. if(json_object_object_get(GetConfiguration, "key") != NULL)
  7010. {
  7011. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  7012. {
  7013. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  7014. n_keys = idx + 1;
  7015. }
  7016. }
  7017. }
  7018. json_object_put(GetConfiguration);
  7019. UnknownKeynum = 0;
  7020. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  7021. MaxKeySupported = GetConfigurationMaxKeysNUM;
  7022. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  7023. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  7024. if(n_keys != 0)
  7025. {
  7026. for(int i=0;i<n_keys;i++)
  7027. {
  7028. getKeyValue(requestKey[i]);
  7029. }
  7030. }
  7031. else
  7032. {
  7033. DEBUG_INFO("There is no key in Message, get all configuration\n");
  7034. getKeyValue("");
  7035. }
  7036. processUnkownKey();
  7037. sendGetConfigurationConfirmation(uuid);
  7038. return result;
  7039. }
  7040. static char fnamePlusPath[100]={0};
  7041. static char fnamePWithNoPath[60]={0};
  7042. void checkUploadLog(void)
  7043. {
  7044. FILE *fp;
  7045. /* Open the command for reading. */
  7046. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  7047. if (fp == NULL) {
  7048. printf("Failed to run command\n" );
  7049. exit(1);
  7050. }
  7051. int ftppathlen = 0;
  7052. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  7053. int i = 0;
  7054. /* Read the output a line at a time - output it. */
  7055. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  7056. if(i==0)
  7057. {
  7058. ftppathlen = strlen(fnamePlusPath);
  7059. printf("%s\n", fnamePlusPath);
  7060. fnamePlusPath[ftppathlen]='\0';
  7061. break;
  7062. }
  7063. i= i+1;
  7064. }
  7065. /* close */
  7066. pclose(fp);
  7067. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  7068. {
  7069. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  7070. {
  7071. fnamePlusPath[k]='\0';
  7072. }
  7073. }
  7074. i=1;
  7075. //char fname[60]={0};
  7076. while(i < ftppathlen)
  7077. {
  7078. int len=ftppathlen-i;
  7079. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  7080. {
  7081. printf("compare '/' all right\n");
  7082. break;
  7083. }
  7084. i=i+1;
  7085. }
  7086. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  7087. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  7088. fnamePWithNoPath[i+1] = '\0';
  7089. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  7090. {
  7091. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  7092. {
  7093. fnamePWithNoPath[j]='\0';
  7094. }
  7095. }
  7096. FILE* fp1 = fopen(fnamePlusPath, "r");
  7097. if (fp1)
  7098. {
  7099. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  7100. // file exists
  7101. fclose(fp1);
  7102. }
  7103. else
  7104. {
  7105. // file doesn't exist
  7106. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  7107. }
  7108. }
  7109. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  7110. {
  7111. mtrace();
  7112. int result = FAIL;
  7113. time_t CurrentTime;
  7114. struct tm *tm;
  7115. pthread_t th_Status;
  7116. CurrentTime = time(NULL);
  7117. tm = localtime(&CurrentTime);
  7118. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  7119. 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);
  7120. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  7121. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  7122. return result;
  7123. }
  7124. void* GetDiagnosticsProcess(void* data)
  7125. {
  7126. pthread_detach(pthread_self());
  7127. mtrace();
  7128. int retriesInt=0, retryIntervalInt=0;
  7129. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  7130. 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};
  7131. int port=0;
  7132. int isSuccess = FALSE;
  7133. char ftpbuf[200]={0};
  7134. char cmdBuf[2048];
  7135. struct tm *tmNow;
  7136. time_t CurrentTime;
  7137. struct tm tmStart;
  7138. struct tm tmStop;
  7139. CurrentTime = time(NULL);
  7140. tmNow=localtime(&CurrentTime);
  7141. uint16_t targetYear, targetMonth;
  7142. json_object *GetDiagnostics;
  7143. DEBUG_INFO("GetDiagnosticsProcess...\n");
  7144. GetDiagnostics = json_tokener_parse(data);
  7145. if(!is_error(GetDiagnostics))
  7146. {
  7147. // Required data
  7148. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  7149. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  7150. // Optional data
  7151. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  7152. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  7153. else
  7154. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  7155. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  7156. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  7157. else
  7158. retryIntervalInt = 30;
  7159. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  7160. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  7161. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  7162. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  7163. }
  7164. json_object_put(GetDiagnostics);
  7165. // Pack log to compress file
  7166. 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) &&
  7167. (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))
  7168. {
  7169. // Pack system log
  7170. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  7171. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  7172. targetYear = tmStart.tm_year;
  7173. targetMonth = tmStart.tm_mon;
  7174. do
  7175. {
  7176. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7177. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7178. if(targetMonth+1>=13)
  7179. {
  7180. targetYear += 1;
  7181. targetMonth = 1;
  7182. }
  7183. else
  7184. {
  7185. targetMonth += 1;
  7186. }
  7187. }while((targetYear < (tmNow->tm_year+1900)) ||
  7188. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  7189. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  7190. system(cmdBuf);
  7191. // Pack charging & event log
  7192. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  7193. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  7194. targetYear = tmStart.tm_year;
  7195. targetMonth = tmStart.tm_mon;
  7196. do
  7197. {
  7198. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7199. if(targetMonth+1>=13)
  7200. {
  7201. targetYear += 1;
  7202. targetMonth = 1;
  7203. }
  7204. else
  7205. {
  7206. targetMonth += 1;
  7207. }
  7208. }while((targetYear < (tmNow->tm_year+1900)) ||
  7209. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  7210. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  7211. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  7212. system(cmdBuf);
  7213. // Combine log file
  7214. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  7215. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  7216. }
  7217. else
  7218. {
  7219. system("exec /root/logPackTools 'log' 6");
  7220. }
  7221. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  7222. system(cmdBuf);
  7223. checkUploadLog();
  7224. //****************location*******************/
  7225. if(strcmp(locationstr,"")==0)
  7226. {
  7227. DEBUG_INFO("location is <Empty>!\n");
  7228. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7229. goto end;
  7230. }
  7231. memset(protocol, 0, ARRAY_SIZE(protocol));
  7232. memset(user, 0, ARRAY_SIZE(user) );
  7233. memset(password, 0, ARRAY_SIZE(password));
  7234. memset(host, 0, ARRAY_SIZE(host));
  7235. memset(path, 0, ARRAY_SIZE(path));
  7236. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  7237. memset(host1, 0, ARRAY_SIZE(host1));
  7238. memset(path1, 0, ARRAY_SIZE(path1));
  7239. /*location: ftp://user:password@host:port/path*/
  7240. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  7241. if((access(fnamePlusPath,F_OK))!=-1)
  7242. {
  7243. DEBUG_INFO("fnamePlusPath exist.\n");
  7244. }
  7245. else
  7246. {
  7247. DEBUG_INFO("fnamePlusPath not exist!\n");
  7248. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7249. goto end;
  7250. }
  7251. if(strchr(locationstr,'@')==NULL)
  7252. {
  7253. sscanf(locationstr,
  7254. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  7255. protocol, host, &port, path);
  7256. strcpy(user,"anonymous");
  7257. strcpy(password,"");
  7258. }
  7259. else
  7260. {
  7261. //DEBUG_INFO("pch=%s\n", pch);
  7262. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  7263. protocol, user, password, host, &port, path);
  7264. }
  7265. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  7266. {
  7267. DEBUG_INFO("protocol is not ftp/http ! \n");
  7268. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7269. goto end;
  7270. }
  7271. if(strncmp(locationstr,"http", 4) == 0)
  7272. {
  7273. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  7274. sprintf(ftppath,"/%s", path);
  7275. do
  7276. {
  7277. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7278. sleep(3);
  7279. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  7280. if(!isSuccess)
  7281. {
  7282. DEBUG_INFO("Diagnostics fail.\n");
  7283. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7284. sleep(retryIntervalInt);
  7285. }
  7286. else
  7287. {
  7288. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7289. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7290. }
  7291. retriesInt--;
  7292. }while((isSuccess == 0)&&(retriesInt >= 0));
  7293. }
  7294. else
  7295. {
  7296. sscanf(host,"%[^/]%s",host1, path1);
  7297. if(strlen(path) > 0)
  7298. sprintf(ftppath,"/%s", path);
  7299. else
  7300. sprintf(ftppath,"/%s", path1);
  7301. int ftppathlen=strlen(ftppath);
  7302. int i=1;
  7303. char filenametemp[50];
  7304. while(i < ftppathlen)
  7305. {
  7306. int len=ftppathlen-i;
  7307. if(ftppath[len]== 47) // '/' ascll code: 47
  7308. {
  7309. DEBUG_INFO("find '/' all right\n");
  7310. break;
  7311. }
  7312. i=i+1;
  7313. }
  7314. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  7315. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  7316. filenametemp[i+1] = 0;
  7317. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  7318. if(port == 0)
  7319. port = 21;
  7320. do
  7321. {
  7322. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7323. sleep(3);
  7324. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  7325. if(!isSuccess)
  7326. {
  7327. DEBUG_INFO("Diagnostics fail.\n");
  7328. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7329. sleep(retryIntervalInt);
  7330. }
  7331. else
  7332. {
  7333. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7334. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7335. }
  7336. retriesInt--;
  7337. }while((!isSuccess)&&(retriesInt >= 0));
  7338. }
  7339. end:
  7340. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  7341. system("rm -f /mnt/*");
  7342. pthread_exit(NULL);
  7343. }
  7344. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  7345. {
  7346. mtrace();
  7347. int result = FAIL;
  7348. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  7349. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  7350. {
  7351. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  7352. localversion = -1;
  7353. }
  7354. else
  7355. {
  7356. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  7357. OCPP_getListVerion();
  7358. }
  7359. //from db.OCPP_getListVerion
  7360. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  7361. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  7362. sendGetLocalListVersionConfirmation(uuid,"");
  7363. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  7364. return result;
  7365. }
  7366. int handleRemoteStartRequest(char *uuid, char *payload)
  7367. {
  7368. mtrace();
  7369. int result = FAIL;
  7370. int connectorIdInt=0;
  7371. int tempIndex = 0;
  7372. int connectorIdIsNULL, chargingProfileIsNULL;
  7373. char comfirmstr[20]={0};
  7374. char cmdBuf[512];
  7375. json_object *RemoteStartTransaction;
  7376. FILE *fp;
  7377. DEBUG_INFO("handleRemoteStartRequest ...\n");
  7378. if(server_pending == TRUE)
  7379. {
  7380. return 0;
  7381. }
  7382. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  7383. RemoteStartTransaction = json_tokener_parse(payload);
  7384. if(!is_error(RemoteStartTransaction))
  7385. {
  7386. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  7387. {
  7388. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  7389. if(connectorIdInt <= gunTotalNumber)
  7390. {
  7391. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  7392. // Required data
  7393. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  7394. // Optional data
  7395. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  7396. {
  7397. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  7398. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  7399. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  7400. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  7401. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  7402. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  7403. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  7404. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  7405. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  7406. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  7407. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  7408. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  7409. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  7410. {
  7411. 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")));
  7412. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  7413. 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"));
  7414. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  7415. 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"));
  7416. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  7417. 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")));
  7418. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  7419. {
  7420. 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++)
  7421. {
  7422. 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"));
  7423. 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"));
  7424. 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)
  7425. 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"));
  7426. }
  7427. }
  7428. }
  7429. }
  7430. else
  7431. chargingProfileIsNULL = TRUE;
  7432. }
  7433. }
  7434. else
  7435. connectorIdIsNULL = TRUE;
  7436. }
  7437. else
  7438. connectorIdIsNULL = TRUE;
  7439. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  7440. {
  7441. DEBUG_WARN("Connector id is NULL\n.");
  7442. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7443. goto end;
  7444. }
  7445. /*
  7446. enum _SYSTEM_STATUS
  7447. {
  7448. S_BOOTING = 0,
  7449. S_IDLE, = 1
  7450. S_AUTHORIZING, = 2
  7451. S_REASSIGN_CHECK, = 3
  7452. S_REASSIGN, = 4
  7453. S_PRECHARGE, = 5
  7454. S_PREPARING_FOR_EV, = 6
  7455. S_PREPARING_FOR_EVSE, = 7
  7456. S_CHARGING, = 8
  7457. S_TERMINATING, = 9
  7458. S_COMPLETE, = 10
  7459. S_ALARM, = 11
  7460. S_FAULT = 12
  7461. }
  7462. */
  7463. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  7464. {
  7465. //check Transaction active
  7466. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  7467. {
  7468. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7469. {
  7470. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7471. }
  7472. else
  7473. {
  7474. tempIndex = connectorIdInt -1;
  7475. }
  7476. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7477. {
  7478. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  7479. {
  7480. 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))
  7481. {
  7482. //Reserved
  7483. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7484. }
  7485. 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))
  7486. {
  7487. //Reserved
  7488. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7489. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7490. goto end;
  7491. }
  7492. else
  7493. {
  7494. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7495. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  7496. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  7497. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  7498. {
  7499. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  7500. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7501. goto end;
  7502. }
  7503. }//END FOR ELSE
  7504. }
  7505. }// END FOR CHAdeMO_QUANTITY
  7506. }
  7507. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  7508. {
  7509. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7510. {
  7511. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7512. }
  7513. else
  7514. {
  7515. tempIndex = connectorIdInt -1;
  7516. }
  7517. for (int index = 0; index < CCS_QUANTITY; index++)
  7518. {
  7519. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7520. {
  7521. 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))
  7522. {
  7523. //Reserved
  7524. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7525. }
  7526. 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))
  7527. {
  7528. //Reserved
  7529. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7530. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7531. goto end;
  7532. }
  7533. else
  7534. {
  7535. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7536. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7537. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7538. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7539. {
  7540. DEBUG_WARN("CCS connector not allow start\n.");
  7541. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7542. goto end;
  7543. }
  7544. }// END FOR ELSE
  7545. }
  7546. }// END FOR CCS_QUANTITY
  7547. }
  7548. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  7549. {
  7550. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7551. {
  7552. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7553. }
  7554. else
  7555. {
  7556. tempIndex = connectorIdInt -1;
  7557. }
  7558. for (int index = 0; index < GB_QUANTITY; index++)
  7559. {
  7560. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7561. {
  7562. 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))
  7563. {
  7564. //Reserved
  7565. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7566. }
  7567. 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))
  7568. {
  7569. //Reserved
  7570. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7571. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7572. goto end;
  7573. }
  7574. else
  7575. {
  7576. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7577. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7578. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7579. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7580. {
  7581. DEBUG_WARN("GB connector not allow start\n.");
  7582. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7583. goto end;
  7584. }
  7585. }// END FOR ELSE
  7586. }
  7587. } // END FOR GB_QUANTITY
  7588. }
  7589. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  7590. {
  7591. tempIndex = connectorIdInt -1;
  7592. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7593. {
  7594. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  7595. {
  7596. 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))
  7597. {
  7598. //Reserved
  7599. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7600. }
  7601. 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))
  7602. {
  7603. //Reserved
  7604. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7605. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7606. goto end;
  7607. }
  7608. else
  7609. {
  7610. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7611. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7612. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7613. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7614. {
  7615. DEBUG_WARN("GB connector not allow start\n.");
  7616. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7617. goto end;
  7618. }
  7619. }// END FOR ELSE
  7620. }
  7621. } // END FOR GB_QUANTITY
  7622. }
  7623. else
  7624. {
  7625. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7626. {
  7627. tempIndex = 2;
  7628. }
  7629. else
  7630. {
  7631. tempIndex = connectorIdInt -1;
  7632. }
  7633. for (int index = 0; index < AC_QUANTITY; index++)
  7634. {
  7635. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7636. {
  7637. 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))
  7638. {
  7639. //Reserved
  7640. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7641. }
  7642. 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))
  7643. {
  7644. //Reserved
  7645. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7646. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7647. goto end;
  7648. }
  7649. else
  7650. {
  7651. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7652. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7653. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7654. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7655. {
  7656. DEBUG_WARN("AC connector not allow start\n.");
  7657. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7658. goto end;
  7659. }
  7660. }//END FOR ELSE
  7661. }
  7662. }// END FOR AC_QUANTITY
  7663. }
  7664. if(chargingProfileIsNULL == FALSE)
  7665. {
  7666. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7667. {
  7668. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7669. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7670. //memset idTag
  7671. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7672. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7673. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7674. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7675. // Save profile to file
  7676. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7677. system(cmdBuf);
  7678. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7679. fp = fopen(cmdBuf, "w");
  7680. 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));
  7681. fclose(fp);
  7682. }
  7683. else
  7684. {
  7685. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  7686. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7687. }
  7688. }
  7689. else
  7690. {
  7691. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7692. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7693. //memset idTag
  7694. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7695. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7696. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7697. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7698. }
  7699. }
  7700. else
  7701. {
  7702. DEBUG_WARN("Connector id over\n.");
  7703. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7704. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7705. }
  7706. end:
  7707. json_object_put(RemoteStartTransaction);
  7708. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  7709. {
  7710. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7711. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7712. }
  7713. //OCPP send RemoteStartConfirmation by first.
  7714. sendRemoteStartConfirmation(uuid, comfirmstr);
  7715. return result;
  7716. }
  7717. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7718. {
  7719. mtrace();
  7720. int result = FAIL;
  7721. int match = FALSE;
  7722. int GunNO = 0;
  7723. int tempIndex = 0;
  7724. int transactionIdInt=0;
  7725. int transactionIdIsNULL= TRUE;
  7726. char comfirmstr[20];
  7727. json_object *RemoteStopTransaction;
  7728. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7729. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7730. if(server_pending == TRUE)
  7731. {
  7732. return 0;
  7733. }
  7734. RemoteStopTransaction = json_tokener_parse(payload);
  7735. if(!is_error(RemoteStopTransaction))
  7736. {
  7737. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  7738. {
  7739. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  7740. transactionIdIsNULL = FALSE;
  7741. }
  7742. }
  7743. json_object_put(RemoteStopTransaction);
  7744. if(transactionIdIsNULL == FALSE)
  7745. {
  7746. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7747. {
  7748. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7749. {
  7750. //check Transaction active
  7751. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7752. {
  7753. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7754. {
  7755. tempIndex = ((gun_index==2) ? 1: 0);
  7756. }
  7757. else
  7758. {
  7759. tempIndex = gun_index;
  7760. }
  7761. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7762. {
  7763. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7764. {
  7765. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7766. {
  7767. match = TRUE;
  7768. GunNO = gun_index;
  7769. }
  7770. }
  7771. }// END FOR CHAdeMO_QUANTITY
  7772. }
  7773. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7774. {
  7775. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7776. {
  7777. tempIndex = ((gun_index==2) ? 1: 0);
  7778. }
  7779. else
  7780. {
  7781. tempIndex = gun_index;
  7782. }
  7783. for (int index = 0; index < CCS_QUANTITY; index++)
  7784. {
  7785. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7786. {
  7787. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7788. {
  7789. match = TRUE;
  7790. GunNO = gun_index;
  7791. }
  7792. }
  7793. }// END FOR CCS_QUANTITY
  7794. }
  7795. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7796. {
  7797. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7798. {
  7799. tempIndex = ((gun_index==2) ? 1: 0);
  7800. }
  7801. else
  7802. {
  7803. tempIndex = gun_index;
  7804. }
  7805. for (int index = 0; index < GB_QUANTITY; index++)
  7806. {
  7807. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7808. {
  7809. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7810. {
  7811. match = TRUE;
  7812. GunNO = gun_index;
  7813. }
  7814. }
  7815. }// END FOR GB_QUANTITY
  7816. }
  7817. else if(gunType[gun_index] == GUN_TYPE_DO)
  7818. {
  7819. tempIndex = gun_index;
  7820. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7821. {
  7822. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7823. {
  7824. 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
  7825. {
  7826. match = TRUE;
  7827. GunNO = gun_index;
  7828. }
  7829. }
  7830. }// END FOR GB_QUANTITY
  7831. }
  7832. else
  7833. {
  7834. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7835. {
  7836. tempIndex = 2;
  7837. }
  7838. else
  7839. {
  7840. tempIndex = gun_index;
  7841. }
  7842. for (int index = 0; index < AC_QUANTITY; index++)
  7843. {
  7844. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7845. {
  7846. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7847. {
  7848. match = TRUE;
  7849. GunNO = gun_index;
  7850. }
  7851. }
  7852. }// END FOR CHAdeMO_QUANTITY
  7853. } // END FOR AC ELSE
  7854. }// CHECK IF ResponseTransactionId == transactionIdInt
  7855. }//END FOR
  7856. if( match == TRUE)
  7857. {
  7858. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7859. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7860. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7861. }
  7862. else
  7863. {
  7864. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7865. }
  7866. }
  7867. else
  7868. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7869. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7870. return result;
  7871. }
  7872. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7873. {
  7874. mtrace();
  7875. int result = FAIL;
  7876. int connectorIdInt=0, reservationIdInt=0;
  7877. int tempIndex = 0;
  7878. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7879. char comfirmstr[20]={0};
  7880. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7881. int c = 0;
  7882. char *loc;
  7883. //char *ptr;
  7884. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  7885. strcpy(sstrtemp, stringtrimspace(payload));
  7886. //***(1)connectorId ****/
  7887. c=0;
  7888. loc = strstr(sstrtemp, "connectorId");
  7889. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7890. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7891. {
  7892. sstr[c] = loc[strlen("connectorId")+2+c];
  7893. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7894. c++;
  7895. }
  7896. sstr[c] = '\0';
  7897. connectorIdInt = atoi(sstr);
  7898. //***(2)expiryDate ****/
  7899. loc = strstr(sstrtemp, "expiryDate");
  7900. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7901. c = 0;
  7902. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7903. {
  7904. sstr[c] = loc[3+strlen("expiryDate")+c];
  7905. c++;
  7906. }
  7907. sstr[c] = '\0';
  7908. strcpy(expiryDatestr, sstr);
  7909. //***(3)idTag ****/
  7910. loc = strstr(sstrtemp, "idTag");
  7911. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7912. c = 0;
  7913. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7914. {
  7915. sstr[c] = loc[3+strlen("idTag")+c];
  7916. c++;
  7917. }
  7918. sstr[c] = '\0';
  7919. strcpy(idTagstr, sstr);
  7920. //***(4)parentIdTag ****/
  7921. loc = strstr(sstrtemp, "parentIdTag");
  7922. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7923. c = 0;
  7924. if(loc == NULL)
  7925. {
  7926. strcpy(parentIdTagstr, "");
  7927. }
  7928. else
  7929. {
  7930. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7931. {
  7932. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7933. c++;
  7934. }
  7935. sstr[c] = '\0';
  7936. strcpy(parentIdTagstr, sstr);
  7937. }
  7938. //***(5)reservationId ****/
  7939. c=0;
  7940. loc = strstr(sstrtemp, "reservationId");
  7941. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7942. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7943. {
  7944. sstr[c] = loc[strlen("reservationId")+2+c];
  7945. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7946. c++;
  7947. }
  7948. sstr[c] = '\0';
  7949. reservationIdInt = atoi(sstr);
  7950. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7951. /*
  7952. enum SYSTEM_STATUS
  7953. {
  7954. SYS_MODE_BOOTING = 0,
  7955. SYS_MODE_IDLE = 1,
  7956. SYS_MODE_AUTHORIZING = 2,
  7957. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7958. SYS_MODE_REASSIGN = 4,
  7959. SYS_MODE_PREPARING = 5,
  7960. SYS_MODE_PREPARE_FOR_EV = 6,
  7961. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7962. SYS_MODE_CHARGING = 8,
  7963. SYS_MODE_TERMINATING = 9,
  7964. SYS_MODE_COMPLETE = 10,
  7965. SYS_MODE_ALARM = 11,
  7966. SYS_MODE_FAULT = 12,
  7967. SYS_MODE_RESERVATION = 13,
  7968. SYS_MODE_BOOKING = 14,
  7969. SYS_MODE_MAINTAIN = 15,
  7970. SYS_MODE_DEBUG = 16,
  7971. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7972. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7973. SYS_MODE_UPDATE = 19
  7974. };
  7975. */
  7976. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7977. {
  7978. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7979. goto end;
  7980. }
  7981. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7982. {
  7983. //check Transaction active
  7984. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  7985. {
  7986. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7987. {
  7988. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7989. }
  7990. else
  7991. {
  7992. tempIndex = connectorIdInt -1;
  7993. }
  7994. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7995. {
  7996. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7997. {
  7998. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7999. {
  8000. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8001. {
  8002. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8003. {
  8004. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8005. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8006. }
  8007. 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'))
  8008. {
  8009. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8010. }
  8011. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8012. {
  8013. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8014. }
  8015. else
  8016. {
  8017. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8018. }
  8019. }
  8020. 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
  8021. {
  8022. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8023. }
  8024. }
  8025. else
  8026. {
  8027. //replace reservation
  8028. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8029. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8030. }
  8031. }
  8032. } // END FOR CHAdeMO_QUANTITY
  8033. }
  8034. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8035. {
  8036. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8037. {
  8038. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8039. }
  8040. else
  8041. {
  8042. tempIndex = connectorIdInt -1;
  8043. }
  8044. for (int index = 0; index < CCS_QUANTITY; index++)
  8045. {
  8046. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8047. {
  8048. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8049. {
  8050. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8051. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8052. {
  8053. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8054. {
  8055. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8056. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8057. }
  8058. 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'))
  8059. {
  8060. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8061. }
  8062. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  8063. {
  8064. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8065. }
  8066. else
  8067. {
  8068. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8069. }
  8070. }
  8071. 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
  8072. {
  8073. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8074. }
  8075. }
  8076. else
  8077. {
  8078. //replace reservation
  8079. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8080. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8081. }
  8082. }
  8083. } // END FOR CCS_QUANTITY
  8084. }
  8085. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8086. {
  8087. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8088. {
  8089. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8090. }
  8091. else
  8092. {
  8093. tempIndex = connectorIdInt -1;
  8094. }
  8095. for (int index = 0; index < GB_QUANTITY; index++)
  8096. {
  8097. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8098. {
  8099. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8100. {
  8101. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8102. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8103. {
  8104. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8105. {
  8106. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8107. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8108. }
  8109. 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'))
  8110. {
  8111. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8112. }
  8113. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8114. {
  8115. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8116. }
  8117. else
  8118. {
  8119. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8120. }
  8121. }
  8122. 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
  8123. {
  8124. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8125. }
  8126. }
  8127. else
  8128. {
  8129. //replace reservation
  8130. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8131. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8132. }
  8133. }
  8134. }// END FOR GB_QUANTITY
  8135. }
  8136. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8137. {
  8138. tempIndex = connectorIdInt -1;
  8139. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8140. {
  8141. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8142. {
  8143. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  8144. {
  8145. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8146. 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
  8147. {
  8148. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8149. {
  8150. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8151. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8152. }
  8153. 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'))
  8154. {
  8155. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8156. }
  8157. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8158. {
  8159. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8160. }
  8161. else
  8162. {
  8163. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8164. }
  8165. }
  8166. 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
  8167. {
  8168. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8169. }
  8170. }
  8171. else
  8172. {
  8173. //replace reservation
  8174. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8175. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8176. }
  8177. }
  8178. }// END FOR GB_QUANTITY
  8179. }
  8180. else
  8181. {
  8182. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8183. {
  8184. tempIndex = 2;
  8185. }
  8186. else
  8187. {
  8188. tempIndex = (connectorIdInt -1);
  8189. }
  8190. for (int index = 0; index < AC_QUANTITY; index++)
  8191. {
  8192. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8193. {
  8194. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8195. {
  8196. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8197. {
  8198. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8199. {
  8200. 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))
  8201. {
  8202. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8203. }
  8204. else
  8205. {
  8206. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8207. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8208. }
  8209. }
  8210. 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'))
  8211. {
  8212. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8213. }
  8214. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8215. {
  8216. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8217. }
  8218. else
  8219. {
  8220. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8221. }
  8222. }
  8223. 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
  8224. {
  8225. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8226. }
  8227. }
  8228. else
  8229. {
  8230. //replace reservation
  8231. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8232. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8233. }
  8234. }
  8235. } // END FOR AC_QUANTITY
  8236. }
  8237. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8238. }
  8239. else if(connectorIdInt == 0)
  8240. {
  8241. //check Transaction active
  8242. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8243. {
  8244. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8245. {
  8246. 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'))
  8247. {
  8248. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8249. goto end;
  8250. }
  8251. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8252. {
  8253. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8254. goto end;
  8255. }
  8256. 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
  8257. {
  8258. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8259. goto end;
  8260. }
  8261. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8262. {
  8263. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8264. goto end;
  8265. }
  8266. }
  8267. }// END FOR CHAdeMO_QUANTITY
  8268. for (int index = 0; index < CCS_QUANTITY; index++)
  8269. {
  8270. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8271. {
  8272. 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'))
  8273. {
  8274. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8275. goto end;
  8276. }
  8277. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  8278. {
  8279. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8280. goto end;
  8281. }
  8282. 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
  8283. {
  8284. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8285. goto end;
  8286. }
  8287. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8288. {
  8289. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8290. goto end;
  8291. }
  8292. }
  8293. } // END FOR CCS_QUANTITY
  8294. for (int index = 0; index < GB_QUANTITY; index++)
  8295. {
  8296. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8297. {
  8298. 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'))
  8299. {
  8300. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8301. goto end;
  8302. }
  8303. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8304. {
  8305. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8306. goto end;
  8307. }
  8308. 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
  8309. {
  8310. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8311. goto end;
  8312. }
  8313. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8314. {
  8315. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8316. goto end;
  8317. }
  8318. }
  8319. } // END FOR GB_QUANTITY
  8320. for (int index = 0; index < AC_QUANTITY; index++)
  8321. {
  8322. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8323. {
  8324. 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'))
  8325. {
  8326. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8327. goto end;
  8328. }
  8329. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8330. {
  8331. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8332. goto end;
  8333. }
  8334. 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
  8335. {
  8336. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8337. goto end;
  8338. }
  8339. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8340. {
  8341. 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))
  8342. {
  8343. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8344. goto end;
  8345. }
  8346. }
  8347. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8348. {
  8349. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8350. goto end;
  8351. }
  8352. }
  8353. }// END FOR AC_QUANTITY
  8354. //The connectorId is 0
  8355. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  8356. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8357. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  8358. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  8359. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  8360. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  8361. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  8362. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  8363. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  8364. result = TRUE;
  8365. return result;
  8366. }
  8367. else
  8368. {
  8369. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8370. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8371. }
  8372. if(strcmp(comfirmstr,"Accepted") == 0)
  8373. {
  8374. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  8375. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  8376. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  8377. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  8378. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  8379. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  8380. result = TRUE;
  8381. return result;
  8382. }
  8383. end:
  8384. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  8385. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  8386. return result;
  8387. }
  8388. int handleResetRequest(char *uuid, char *payload)
  8389. {
  8390. mtrace();
  8391. int result = FAIL;
  8392. char sstr[10]={0},sstrtemp[30]={ 0 };
  8393. char typestr[10]={0};
  8394. char comfirmstr[20]={0};
  8395. int c = 0;
  8396. char *loc;
  8397. DEBUG_INFO("handleResetRequest...\n");
  8398. strcpy(sstrtemp, stringtrimspace(payload));
  8399. loc = strstr(sstrtemp, "type");
  8400. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8401. c = 0;
  8402. while (loc[3+strlen("type")+c] != '\"')
  8403. {
  8404. sstr[c] = loc[3+strlen("type")+c];
  8405. c++;
  8406. }
  8407. sstr[c] = '\0';
  8408. strcpy(typestr,sstr);
  8409. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  8410. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  8411. {
  8412. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  8413. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  8414. result = TRUE;
  8415. return result;
  8416. }
  8417. else
  8418. {
  8419. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  8420. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  8421. goto errorend;
  8422. }
  8423. errorend:
  8424. sendResetConfirmation(uuid, comfirmstr);
  8425. return result;
  8426. }
  8427. int handleSendLocalListRequest(char *uuid, char *payload)
  8428. {
  8429. mtrace();
  8430. int result = FAIL;
  8431. int listVersionInt;
  8432. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  8433. char listsearch[]="listVersion";
  8434. char updateTypesearch[]="updateType";
  8435. char localAuthorizationListsearch[]="localAuthorizationList";
  8436. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  8437. char CardList[500][160]={0};
  8438. char updateTypestr[15]={0};
  8439. char idTagstr[20]={0};
  8440. char parentIdTag[20]={0};
  8441. char expiryDate[30]={0};
  8442. char idTagstatus[16]={0};
  8443. int c = 0;
  8444. int i = 0;
  8445. char *delim1 = "}";
  8446. char * pch;
  8447. char *loc;
  8448. //char *ptr;
  8449. char comfirmstr[20];
  8450. //int n_localAuthorizations = 0;
  8451. int checkState_Faulted = FALSE;
  8452. DEBUG_INFO("handleSendLocalListRequest...\n");
  8453. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  8454. {
  8455. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8456. goto end;
  8457. }
  8458. //check Charge Point state
  8459. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8460. {
  8461. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8462. {
  8463. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8464. }
  8465. }
  8466. for (int index = 0; index < CCS_QUANTITY; index++)
  8467. {
  8468. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8469. {
  8470. checkState_Faulted = TRUE; //OCPP Status
  8471. }
  8472. }
  8473. for (int index = 0; index < GB_QUANTITY; index++)
  8474. {
  8475. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8476. {
  8477. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8478. }
  8479. }
  8480. //check Charge Point state
  8481. for (int index = 0; index < AC_QUANTITY; index++)
  8482. {
  8483. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8484. {
  8485. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8486. }
  8487. }
  8488. if(checkState_Faulted == TRUE)
  8489. {
  8490. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8491. goto end;
  8492. }
  8493. //Filter payload space
  8494. strcpy(sstrtemp, stringtrimspace(payload));
  8495. //listVersion
  8496. c = 0;
  8497. loc = strstr(sstrtemp, listsearch);
  8498. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  8499. {
  8500. sstr[c] = loc[strlen("listVersion")+2+c];
  8501. c++;
  8502. }
  8503. sstr[c] = '\0';
  8504. listVersionInt = atoi(sstr);
  8505. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8506. //updateType
  8507. loc = strstr(sstrtemp, updateTypesearch);
  8508. c = 0;
  8509. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  8510. {
  8511. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  8512. c++;
  8513. }
  8514. sstr[c] = '\0';
  8515. strcpy(updateTypestr, sstr);
  8516. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  8517. //localAuthorizationList
  8518. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8519. loc = strstr(sstrtemp, localAuthorizationListsearch);
  8520. if(loc != NULL) // localAuthorizationList is not NULL
  8521. {
  8522. //Check UpdateType
  8523. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8524. {
  8525. //Local list full update
  8526. printf("Local list full update.\n");
  8527. OCPP_getListVerion();
  8528. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8529. {
  8530. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8531. goto end;
  8532. }
  8533. OCPP_cleanLocalList();
  8534. }
  8535. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8536. {
  8537. //Local list different update
  8538. printf("Local list different update.\n");
  8539. OCPP_getListVerion();
  8540. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8541. {
  8542. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  8543. goto end;
  8544. }
  8545. }
  8546. else
  8547. {
  8548. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8549. goto end;
  8550. }
  8551. c = 0;
  8552. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  8553. {
  8554. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  8555. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8556. c++;
  8557. }
  8558. sstr[c] = '\0';
  8559. //DEBUG_INFO("sstr=%s\n", sstr);
  8560. //parsing strings to words
  8561. i = 0;
  8562. pch = strtok(sstr,delim1);
  8563. while (pch != NULL)
  8564. {
  8565. strcpy(CardList[i], pch);
  8566. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  8567. pch = strtok (NULL, delim1);
  8568. i = i + 1;
  8569. }
  8570. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  8571. //local Authorizations List Numbers
  8572. //n_localAuthorizations = i;
  8573. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8574. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  8575. c= 0;
  8576. while(c < i) // i is CardList Number
  8577. {
  8578. //Search "IdToken"
  8579. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8580. loc = strstr(CardList[c], "idTag");
  8581. int j = 0;
  8582. while (loc[3+strlen("idTag")+j] != '\"')
  8583. {
  8584. sstr[j] = loc[3+strlen("idTag")+j];
  8585. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8586. j++;
  8587. }
  8588. sstr[j] = '\0';
  8589. strcpy(idTagstr, sstr);
  8590. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  8591. //Search "expiryDate"
  8592. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8593. loc = strstr(CardList[c], "expiryDate");
  8594. j = 0;
  8595. if(loc != NULL)
  8596. {
  8597. while (loc[3+strlen("expiryDate")+j] != '\"')
  8598. {
  8599. sstr[j] = loc[3+strlen("expiryDate")+j];
  8600. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8601. j++;
  8602. }
  8603. sstr[j] = '\0';
  8604. strcpy(expiryDate, sstr);
  8605. }
  8606. else
  8607. {
  8608. strcpy(expiryDate, "");
  8609. }
  8610. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  8611. //Search "parentIdTag"
  8612. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8613. loc = strstr(CardList[c], "parentIdTag");
  8614. j = 0;
  8615. if(loc != NULL)
  8616. {
  8617. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8618. {
  8619. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8620. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8621. j++;
  8622. }
  8623. sstr[j] = '\0';
  8624. strcpy(parentIdTag, sstr);
  8625. }
  8626. else
  8627. {
  8628. strcpy(parentIdTag, "");
  8629. }
  8630. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8631. //Search "status"
  8632. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8633. loc = strstr(CardList[c], "status");
  8634. j = 0;
  8635. while (loc[3+strlen("status")+j] != '\"')
  8636. {
  8637. sstr[j] = loc[3+strlen("status")+j];
  8638. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8639. j++;
  8640. }
  8641. sstr[j] = '\0';
  8642. strcpy(idTagstatus, sstr);
  8643. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8644. OCPP_getIdTagFromLocalList(idTagstr);
  8645. //OCPP_getIdTagFromLocalList("test"); For Test
  8646. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8647. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8648. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8649. {
  8650. //Local list full update
  8651. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8652. // update list
  8653. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8654. //DEBUG_INFO("Local list full update. 1\n");
  8655. //OCPP_get_TableAuthlocalAllData();
  8656. //DEBUG_INFO("Local list full update. 2\n");
  8657. }
  8658. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8659. {
  8660. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8661. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8662. }
  8663. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8664. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8665. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8666. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8667. c++;
  8668. }
  8669. }
  8670. else
  8671. {
  8672. //Check UpdateType
  8673. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8674. {
  8675. //Local list full update
  8676. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8677. OCPP_cleanLocalList();
  8678. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8679. goto end;
  8680. }
  8681. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8682. {
  8683. //Local list different update
  8684. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8685. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8686. goto end;
  8687. }
  8688. }
  8689. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8690. end:
  8691. sendSendLocalListConfirmation(uuid, comfirmstr);
  8692. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8693. return result;
  8694. }
  8695. #define MAX 200
  8696. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8697. {
  8698. mtrace();
  8699. int result = FAIL;
  8700. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8701. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8702. char chargingProfilePurposeStr[30]={0};
  8703. char chargingProfileKindStr[16]={0};
  8704. char recurrencyKindStr[10]={0};
  8705. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8706. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8707. int chargingSchedulePeriodCount = 0;
  8708. char comfirmstr[20]={0};
  8709. int meet= FALSE;
  8710. FILE *fptr1;
  8711. char filename[MAX]={0};
  8712. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8713. char rmFileCmd[50]={0};
  8714. char tempchargingProfilePurposeStr[30]={0};
  8715. char word[1600]={0};
  8716. int n_chargingProfile = 0;
  8717. json_object *SetChargingProfile;
  8718. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8719. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8720. SetChargingProfile = json_tokener_parse(payload);
  8721. if(!is_error(SetChargingProfile))
  8722. {
  8723. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  8724. {
  8725. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  8726. if(connectorIdInt == 0)
  8727. {
  8728. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  8729. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8730. }
  8731. else
  8732. {
  8733. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  8734. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  8735. }
  8736. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  8737. }
  8738. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  8739. {
  8740. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  8741. {
  8742. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  8743. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8744. {
  8745. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8746. }
  8747. else
  8748. {
  8749. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8750. }
  8751. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  8752. }
  8753. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  8754. {
  8755. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  8756. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8757. {
  8758. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8759. }
  8760. else
  8761. {
  8762. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8763. }
  8764. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  8765. }
  8766. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8767. {
  8768. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  8769. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8770. {
  8771. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8772. }
  8773. else
  8774. {
  8775. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8776. }
  8777. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  8778. }
  8779. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  8780. {
  8781. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  8782. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8783. {
  8784. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8785. }
  8786. else
  8787. {
  8788. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8789. }
  8790. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  8791. }
  8792. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  8793. {
  8794. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  8795. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8796. {
  8797. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  8798. }
  8799. else
  8800. {
  8801. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  8802. }
  8803. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  8804. }
  8805. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  8806. {
  8807. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  8808. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8809. {
  8810. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8811. }
  8812. else
  8813. {
  8814. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8815. }
  8816. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  8817. }
  8818. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  8819. {
  8820. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  8821. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8822. {
  8823. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8824. }
  8825. else
  8826. {
  8827. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8828. }
  8829. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  8830. }
  8831. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  8832. {
  8833. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  8834. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8835. {
  8836. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8837. }
  8838. else
  8839. {
  8840. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8841. }
  8842. //DEBUG_INFO("validToStr: %s\n", validToStr);
  8843. }
  8844. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  8845. {
  8846. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  8847. {
  8848. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  8849. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8850. {
  8851. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8852. }
  8853. else
  8854. {
  8855. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8856. }
  8857. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  8858. }
  8859. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  8860. {
  8861. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  8862. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8863. {
  8864. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8865. }
  8866. else
  8867. {
  8868. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8869. }
  8870. //DEBUG_INFO("durationInt: %d\n", durationInt);
  8871. }
  8872. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  8873. {
  8874. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  8875. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8876. {
  8877. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8878. }
  8879. else
  8880. {
  8881. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8882. }
  8883. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  8884. }
  8885. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  8886. {
  8887. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  8888. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8889. {
  8890. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8891. }
  8892. else
  8893. {
  8894. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8895. }
  8896. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  8897. }
  8898. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  8899. {
  8900. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  8901. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  8902. if(chargingSchedulePeriodCount <= 10)
  8903. {
  8904. 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++)
  8905. {
  8906. 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)
  8907. {
  8908. 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"));
  8909. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8910. {
  8911. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  8912. }
  8913. else
  8914. {
  8915. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  8916. }
  8917. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  8918. }
  8919. 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)
  8920. {
  8921. 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"));
  8922. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8923. {
  8924. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  8925. }
  8926. else
  8927. {
  8928. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  8929. }
  8930. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  8931. }
  8932. 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)
  8933. {
  8934. 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"));
  8935. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8936. {
  8937. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  8938. }
  8939. else
  8940. {
  8941. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  8942. }
  8943. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  8944. }
  8945. }
  8946. }
  8947. }
  8948. }
  8949. }
  8950. }
  8951. json_object_put(SetChargingProfile);
  8952. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8953. {
  8954. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8955. goto end;
  8956. }
  8957. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8958. {
  8959. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8960. if(connectorIdInt != 0)
  8961. {
  8962. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8963. goto end;
  8964. }
  8965. strcpy(filename, ChargePointMaxProfile_JSON );
  8966. fptr1 = fopen(filename, "r");
  8967. if (!fptr1)
  8968. {
  8969. //file not exist
  8970. DEBUG_INFO("Unable to open the input file!!\n");
  8971. fptr1 = fopen(filename, "w+");
  8972. }
  8973. else
  8974. {
  8975. //Check Charging Profile Count
  8976. while(fscanf(fptr1, "%s", word) != EOF)
  8977. {
  8978. //DEBUG_INFO("word=%s\n",word);
  8979. if(strstr(word, "chargingProfileId")!= NULL)
  8980. {
  8981. //DEBUG_INFO("test chargingProfileId \n");
  8982. n_chargingProfile = n_chargingProfile + 1;
  8983. //DEBUG_INFO("chargingProfileId Found\n");
  8984. }
  8985. }
  8986. }
  8987. fclose(fptr1);
  8988. }
  8989. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8990. {
  8991. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8992. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8993. {
  8994. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8995. goto end;
  8996. }
  8997. memset(filename, 0, ARRAY_SIZE(filename));
  8998. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8999. fptr1 = fopen(filename, "r");
  9000. if (!fptr1)
  9001. {
  9002. //file not exist
  9003. //DEBUG_INFO("Unable to open the input file!!\n");
  9004. fptr1 = fopen(filename, "w+");
  9005. }
  9006. else
  9007. {
  9008. //Check Charging Profile Count
  9009. while(fscanf(fptr1, "%s", word) != EOF)
  9010. {
  9011. //DEBUG_INFO("word=%s\n",word);
  9012. if(strstr(word, "chargingProfileId")!= NULL)
  9013. {
  9014. //DEBUG_INFO("test chargingProfileId \n");
  9015. n_chargingProfile = n_chargingProfile + 1;
  9016. //DEBUG_INFO("chargingProfileId Found\n");
  9017. }
  9018. }
  9019. }
  9020. fclose(fptr1);
  9021. }
  9022. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9023. {
  9024. //printf("set chargingProfile 1-4\n");
  9025. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  9026. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  9027. if(connectorIdInt == 0)
  9028. {
  9029. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9030. goto end;
  9031. }
  9032. int tempIndex = 0;
  9033. //check Transaction active
  9034. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9035. {
  9036. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9037. {
  9038. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9039. }
  9040. else
  9041. {
  9042. tempIndex = connectorIdInt -1;
  9043. }
  9044. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9045. {
  9046. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9047. {
  9048. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9049. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9050. {
  9051. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9052. {
  9053. meet = TRUE;
  9054. break;
  9055. }
  9056. }
  9057. }
  9058. }
  9059. }
  9060. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9061. {
  9062. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9063. {
  9064. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9065. }
  9066. else
  9067. {
  9068. tempIndex = connectorIdInt -1;
  9069. }
  9070. for (int index = 0; index < CCS_QUANTITY; index++)
  9071. {
  9072. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9073. {
  9074. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9075. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9076. {
  9077. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9078. {
  9079. meet = TRUE;
  9080. break;
  9081. }
  9082. }
  9083. }
  9084. }
  9085. }
  9086. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9087. {
  9088. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9089. {
  9090. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9091. }
  9092. else
  9093. {
  9094. tempIndex = connectorIdInt -1;
  9095. }
  9096. for (int index = 0; index < GB_QUANTITY; index++)
  9097. {
  9098. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9099. {
  9100. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9101. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9102. {
  9103. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9104. {
  9105. meet = TRUE;
  9106. break;
  9107. }
  9108. }
  9109. }
  9110. }
  9111. }
  9112. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9113. {
  9114. tempIndex = connectorIdInt -1;
  9115. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9116. {
  9117. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9118. {
  9119. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  9120. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9121. {
  9122. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9123. {
  9124. meet = TRUE;
  9125. break;
  9126. }
  9127. }
  9128. }
  9129. }
  9130. }
  9131. else
  9132. {
  9133. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9134. {
  9135. tempIndex = 2;
  9136. }
  9137. else
  9138. {
  9139. tempIndex = (connectorIdInt -1);
  9140. }
  9141. for (int index = 0; index < AC_QUANTITY; index++)
  9142. {
  9143. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9144. {
  9145. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9146. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9147. {
  9148. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9149. {
  9150. meet = TRUE;
  9151. break;
  9152. }
  9153. }
  9154. }
  9155. }
  9156. }
  9157. //check Transaction active
  9158. if(meet == FALSE)
  9159. {
  9160. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9161. goto end;
  9162. }
  9163. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9164. {
  9165. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9166. goto end;
  9167. }
  9168. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9169. fptr1 = fopen(filename, "r");
  9170. if (!fptr1)
  9171. {
  9172. //file not exist
  9173. DEBUG_INFO("Unable to open the input file!!\n");
  9174. fptr1 = fopen(filename, "w+");
  9175. }
  9176. else
  9177. {
  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. //DEBUG_INFO("chargingProfileId Found\n");
  9187. }
  9188. }
  9189. }
  9190. fclose(fptr1);
  9191. }
  9192. // Check ChargeProfileMaxStackLevel
  9193. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  9194. {
  9195. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9196. goto end;
  9197. }
  9198. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9199. {
  9200. int i = 0;
  9201. char fnametemp[200]={0};
  9202. n_chargingProfile = 0;
  9203. //Check ChargePointMaxProfile.json exit
  9204. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9205. {
  9206. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  9207. //Check Charging Profile Count
  9208. while(fscanf(fptr1, "%s", word) != EOF)
  9209. {
  9210. //DEBUG_INFO("word=%s\n",word);
  9211. if(strstr(word, "chargingProfileId")!= NULL)
  9212. {
  9213. //DEBUG_INFO("test chargingProfileId \n");
  9214. n_chargingProfile = n_chargingProfile + 1;
  9215. i = i + 1;
  9216. //DEBUG_INFO("chargingProfileId Found\n");
  9217. }
  9218. memset(word, 0, ARRAY_SIZE(word));
  9219. }
  9220. fclose(fptr1);
  9221. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  9222. }
  9223. //Check TxDefaultProfile_0.json exit
  9224. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9225. {
  9226. i = 0;
  9227. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  9228. //Check Charging Profile Count
  9229. while(fscanf(fptr1, "%s", word) != EOF)
  9230. {
  9231. //DEBUG_INFO("word=%s\n",word);
  9232. if(strstr(word, "chargingProfileId")!= NULL)
  9233. {
  9234. //DEBUG_INFO("test chargingProfileId \n");
  9235. n_chargingProfile = n_chargingProfile + 1;
  9236. i = i + 1;
  9237. //DEBUG_INFO("chargingProfileId Found\n");
  9238. }
  9239. memset(word, 0, ARRAY_SIZE(word));
  9240. }
  9241. fclose(fptr1);
  9242. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  9243. }
  9244. //Check TxDefaultProfile_%d.json
  9245. for(int j=1; j <= gunTotalNumber; j++)
  9246. {
  9247. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9248. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9249. if((access(fnametemp,F_OK))!=-1)
  9250. {
  9251. i = 0;
  9252. fptr1 = fopen(fnametemp, "r");
  9253. //Check Charging Profile Count
  9254. while(fscanf(fptr1, "%s", word) != EOF)
  9255. {
  9256. //DEBUG_INFO("word=%s\n",word);
  9257. if(strstr(word, "chargingProfileId")!= NULL)
  9258. {
  9259. //DEBUG_INFO("test chargingProfileId \n");
  9260. n_chargingProfile = n_chargingProfile + 1;
  9261. i = i + 1;
  9262. //DEBUG_INFO("chargingProfileId Found\n");
  9263. }
  9264. memset(word, 0, ARRAY_SIZE(word));
  9265. }
  9266. fclose(fptr1);
  9267. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9268. }
  9269. }
  9270. //Check TxProfile_%d.json
  9271. for(int j=1; j <= gunTotalNumber; j++)
  9272. {
  9273. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9274. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9275. if((access(fnametemp,F_OK))!=-1)
  9276. {
  9277. i = 0;
  9278. fptr1 = fopen(fnametemp, "r");
  9279. //Check Charging Profile Count
  9280. while(fscanf(fptr1, "%s", word) != EOF)
  9281. {
  9282. //DEBUG_INFO("word=%s\n",word);
  9283. if(strstr(word, "chargingProfileId")!= NULL)
  9284. {
  9285. //DEBUG_INFO("test chargingProfileId \n");
  9286. n_chargingProfile = n_chargingProfile + 1;
  9287. i = i + 1;
  9288. //DEBUG_INFO("chargingProfileId Found\n");
  9289. }
  9290. memset(word, 0, ARRAY_SIZE(word));
  9291. }
  9292. fclose(fptr1);
  9293. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9294. }
  9295. }
  9296. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  9297. {
  9298. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9299. goto end;
  9300. }
  9301. }
  9302. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9303. //**********************************Write to File********************************************************/
  9304. FILE *infile;
  9305. FILE *outfile;
  9306. infile = fopen (filename, "r");
  9307. outfile = fopen (tempfile, "w");
  9308. int d =0;
  9309. d = fgetc(infile);
  9310. rewind(infile);
  9311. if(d == EOF)
  9312. {
  9313. // Profile is empty
  9314. fprintf(outfile,"%s\n",payload);
  9315. fclose(infile);
  9316. fclose(outfile);
  9317. sprintf(rmFileCmd,"rm -f %s",filename);
  9318. system(rmFileCmd);
  9319. rename(tempfile, filename);
  9320. }
  9321. else
  9322. {
  9323. // Profile is not empty
  9324. char buf[2048]={0};
  9325. int ChargingProfileAdded = FALSE;
  9326. while (fgets(buf, sizeof(buf), infile) != NULL)
  9327. {
  9328. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9329. json_object *tmpChargingProfile;
  9330. tmpChargingProfile = json_tokener_parse(buf);
  9331. if(!is_error(SetChargingProfile))
  9332. {
  9333. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  9334. {
  9335. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  9336. }
  9337. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  9338. {
  9339. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9340. {
  9341. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9342. }
  9343. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9344. {
  9345. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  9346. }
  9347. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9348. {
  9349. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9350. }
  9351. }
  9352. }
  9353. json_object_put(tmpChargingProfile);
  9354. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  9355. {
  9356. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9357. {
  9358. //DEBUG_INFO("update set chargingProfile to file -0\n");
  9359. if(ChargingProfileAdded == FALSE)
  9360. {
  9361. fprintf(outfile,"%s\n",payload);
  9362. ChargingProfileAdded = TRUE;
  9363. }
  9364. }
  9365. else
  9366. {
  9367. if(tempstackLevelInt < stackLevelInt)
  9368. {
  9369. if(ChargingProfileAdded == FALSE)
  9370. {
  9371. fprintf(outfile,"%s\n",buf);
  9372. fprintf(outfile,"%s\n",payload);
  9373. ChargingProfileAdded = TRUE;
  9374. }
  9375. else
  9376. {
  9377. fprintf(outfile,"%s\n",buf);
  9378. }
  9379. }
  9380. else
  9381. {
  9382. if(ChargingProfileAdded == FALSE)
  9383. {
  9384. fprintf(outfile,"%s\n",buf);
  9385. fprintf(outfile,"%s\n",payload);
  9386. ChargingProfileAdded = TRUE;
  9387. }
  9388. else
  9389. {
  9390. fprintf(outfile,"%s\n",buf);
  9391. }
  9392. }
  9393. }
  9394. }
  9395. else
  9396. {
  9397. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9398. {
  9399. if(ChargingProfileAdded == FALSE)
  9400. {
  9401. fprintf(outfile,"%s\n",buf);
  9402. fprintf(outfile,"%s\n",payload);
  9403. ChargingProfileAdded = TRUE;
  9404. }
  9405. else
  9406. {
  9407. fprintf(outfile,"%s\n",buf);
  9408. }
  9409. }
  9410. else if(tempstackLevelInt < stackLevelInt)
  9411. {
  9412. if(ChargingProfileAdded == FALSE)
  9413. {
  9414. fprintf(outfile,"%s\n",buf);
  9415. fprintf(outfile,"%s\n",payload);
  9416. ChargingProfileAdded = TRUE;
  9417. }
  9418. else
  9419. {
  9420. fprintf(outfile,"%s\n",buf);
  9421. }
  9422. }
  9423. else
  9424. {
  9425. if(ChargingProfileAdded == FALSE)
  9426. {
  9427. fprintf(outfile,"%s\n",buf);
  9428. fprintf(outfile,"%s\n",payload);
  9429. ChargingProfileAdded = TRUE;
  9430. }
  9431. else
  9432. {
  9433. fprintf(outfile,"%s\n",buf);
  9434. }
  9435. }
  9436. }
  9437. } // end of while loop
  9438. fclose(infile);
  9439. fclose(outfile);
  9440. sprintf(rmFileCmd,"rm -f %s",filename);
  9441. system(rmFileCmd);
  9442. rename(tempfile, filename);
  9443. }
  9444. sleep(1);
  9445. result = TRUE;
  9446. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9447. end:
  9448. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  9449. {
  9450. if(connectorIdInt == 0)
  9451. {
  9452. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9453. {
  9454. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9455. }
  9456. }
  9457. else
  9458. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9459. }
  9460. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  9461. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9462. return result;
  9463. }
  9464. int handleTriggerMessageRequest(char *uuid, char *payload)
  9465. {
  9466. mtrace();
  9467. int result = FAIL;
  9468. int connectorIdIsNULL = FALSE;
  9469. int connectorIdInt =0;
  9470. char sstr[40]={0},sstrtemp[100]={ 0 };
  9471. char requestedMessagestr[40]={0};
  9472. char comfirmstr[20]={0};
  9473. int c = 0;
  9474. char *loc;
  9475. DEBUG_INFO("handleTriggerMessageRequest\n");
  9476. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  9477. strcpy(sstrtemp, stringtrimspace(payload));
  9478. c = 0;
  9479. loc = strstr(sstrtemp, "requestedMessage");
  9480. while (loc[3+strlen("requestedMessage")+c] != '\"')
  9481. {
  9482. sstr[c] = loc[3+strlen("requestedMessage")+c];
  9483. c++;
  9484. }
  9485. sstr[c] = '\0';
  9486. strcpy(requestedMessagestr, sstr);
  9487. c = 0;
  9488. loc = strstr(sstrtemp, "connectorId");
  9489. if(loc == NULL)
  9490. {
  9491. connectorIdIsNULL = TRUE;
  9492. }
  9493. else
  9494. {
  9495. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9496. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  9497. {
  9498. sstr[c] = loc[strlen("connectorId")+2+c];
  9499. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9500. c++;
  9501. }
  9502. sstr[c] = '\0';
  9503. connectorIdInt = atoi(sstr);
  9504. }
  9505. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  9506. {
  9507. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  9508. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  9509. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  9510. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  9511. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  9512. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  9513. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  9514. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  9515. {
  9516. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  9517. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9518. return TRUE;
  9519. }
  9520. else
  9521. {
  9522. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9523. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9524. }
  9525. }
  9526. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  9527. {
  9528. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  9529. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9530. return TRUE;
  9531. }
  9532. //==========================
  9533. // Trigger message
  9534. //==========================
  9535. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  9536. {
  9537. if((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) &&
  9538. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) &&
  9539. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) &&
  9540. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING) )
  9541. {
  9542. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  9543. }
  9544. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  9545. }
  9546. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  9547. {
  9548. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  9549. }
  9550. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  9551. {
  9552. //sendBootNotificationRequest();
  9553. server_sign = FALSE;
  9554. }
  9555. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  9556. {
  9557. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  9558. }
  9559. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  9560. {
  9561. if(connectorIdIsNULL == FALSE)
  9562. {
  9563. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9564. {
  9565. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  9566. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  9567. }
  9568. }
  9569. else
  9570. {
  9571. for(int idx=0;idx< gunTotalNumber;idx++)
  9572. {
  9573. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  9574. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  9575. }
  9576. }
  9577. }
  9578. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  9579. {
  9580. if(connectorIdIsNULL == FALSE)
  9581. {
  9582. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9583. {
  9584. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  9585. }
  9586. }
  9587. else
  9588. {
  9589. for(int idx=0;idx< gunTotalNumber;idx++)
  9590. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  9591. }
  9592. }
  9593. return result;
  9594. }
  9595. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9596. {
  9597. mtrace();
  9598. int result = FAIL;
  9599. int connectorIdInt =0;
  9600. char comfirmstr[20]={0};
  9601. int tempIndex = 0;
  9602. json_object *UnlockConnector;
  9603. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9604. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9605. UnlockConnector = json_tokener_parse(payload);
  9606. if(!is_error(UnlockConnector))
  9607. {
  9608. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  9609. {
  9610. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  9611. }
  9612. }
  9613. json_object_put(UnlockConnector);
  9614. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  9615. if(gunTotalNumber == 0)
  9616. {
  9617. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9618. goto end;
  9619. }
  9620. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9621. {
  9622. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9623. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9624. goto end;
  9625. }
  9626. else
  9627. {
  9628. //check Transaction active
  9629. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  9630. {
  9631. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9632. {
  9633. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9634. }
  9635. else
  9636. {
  9637. tempIndex = connectorIdInt -1;
  9638. }
  9639. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9640. {
  9641. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9642. {
  9643. //stop Transaction
  9644. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9645. }
  9646. }
  9647. }
  9648. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  9649. {
  9650. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9651. {
  9652. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9653. }
  9654. else
  9655. {
  9656. tempIndex = connectorIdInt -1;
  9657. }
  9658. for (int index = 0; index < CCS_QUANTITY; index++)
  9659. {
  9660. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9661. {
  9662. //stop Transaction
  9663. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9664. }
  9665. }
  9666. }
  9667. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  9668. {
  9669. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9670. {
  9671. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9672. }
  9673. else
  9674. {
  9675. tempIndex = connectorIdInt -1;
  9676. }
  9677. for (int index = 0; index < GB_QUANTITY; index++)
  9678. {
  9679. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9680. {
  9681. //stop Transaction
  9682. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9683. }
  9684. }
  9685. }
  9686. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  9687. {
  9688. tempIndex = connectorIdInt -1;
  9689. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9690. {
  9691. 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)))
  9692. {
  9693. //stop Transaction
  9694. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9695. }
  9696. }
  9697. }
  9698. else
  9699. {
  9700. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9701. {
  9702. tempIndex = 2;
  9703. }
  9704. else
  9705. {
  9706. tempIndex = connectorIdInt-1;
  9707. }
  9708. for (int index = 0; index < AC_QUANTITY; index++)
  9709. {
  9710. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9711. {
  9712. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9713. }
  9714. }
  9715. }
  9716. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9717. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9718. result = TRUE;
  9719. return result;
  9720. }
  9721. end:
  9722. //json_object_put(obj); --- remove temporally
  9723. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9724. return result;
  9725. }
  9726. static char UpdateFirmwarepayloadData[300]={0};
  9727. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9728. {
  9729. mtrace();
  9730. int result = FAIL;
  9731. pthread_t t;
  9732. sendUpdateFirmwareConfirmation(uuid);
  9733. memset(UpdateFirmwarepayloadData, 0, 300);
  9734. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9735. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9736. ////pthread_join(t, NULL); //
  9737. //pthread_detach(t);
  9738. //sendUpdateFirmwareConfirmation(uuid);
  9739. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9740. return result;
  9741. }
  9742. void *UpdateFirmwareProcess(void *data)
  9743. {
  9744. pthread_detach(pthread_self());
  9745. mtrace();
  9746. int retriesInt =0, retryIntervalInt=0;
  9747. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9748. int port=0;
  9749. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9750. int isSuccess = 0;
  9751. char ftpbuf[200];
  9752. char temp[100];
  9753. char * pch;
  9754. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9755. json_object *UpdateFirmware;
  9756. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  9757. if(!is_error(UpdateFirmware))
  9758. {
  9759. // Required data
  9760. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  9761. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  9762. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  9763. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  9764. // Optional data
  9765. if(json_object_object_get(UpdateFirmware, "retries"))
  9766. {
  9767. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  9768. }
  9769. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  9770. {
  9771. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  9772. }
  9773. }
  9774. json_object_put(UpdateFirmware);
  9775. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9776. memset(path, 0, ARRAY_SIZE(path));
  9777. system("rm -f /mnt/*");
  9778. if(strncmp(locationstr,"http", 4) == 0)
  9779. {
  9780. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9781. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9782. // protocol, user, password, host, path);
  9783. sprintf(ftppath,"/%s", path);
  9784. DEBUG_INFO("locationstr: %s\n", locationstr);
  9785. DEBUG_INFO("protocol: %s\n",protocol);
  9786. DEBUG_INFO("host: %s\n",host);
  9787. DEBUG_INFO("path: %s\n",path);
  9788. DEBUG_INFO("ftppath: %s\n",ftppath);
  9789. int ftppathlen=strlen(ftppath);
  9790. int i=1;
  9791. char filenametemp[50];
  9792. while(i < ftppathlen)
  9793. {
  9794. int len=ftppathlen-i;
  9795. if(ftppath[len]== 47) // '/' ascll code: 47
  9796. {
  9797. DEBUG_INFO("compare '/' all right\n");
  9798. break;
  9799. }
  9800. i=i+1;
  9801. }
  9802. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9803. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9804. filenametemp[i+1] = 0;
  9805. do
  9806. {
  9807. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9808. sleep(3);
  9809. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9810. if(!isSuccess)
  9811. {
  9812. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9813. sleep(retryIntervalInt);
  9814. }
  9815. else
  9816. {
  9817. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9818. }
  9819. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9820. }
  9821. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9822. {
  9823. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9824. memset(temp, 0, ARRAY_SIZE(temp));
  9825. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9826. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9827. int ftppathlen=strlen(ftpbuf);
  9828. int i=1;
  9829. char filenametemp[50];
  9830. while(i < ftppathlen)
  9831. {
  9832. int len=ftppathlen-i;
  9833. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9834. {
  9835. DEBUG_INFO(" compare '/' all right\n");
  9836. break;
  9837. }
  9838. i=i+1;
  9839. }
  9840. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9841. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9842. filenametemp[i+1] = 0;
  9843. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9844. pch=strchr(temp,'@');
  9845. if(pch==NULL)
  9846. {
  9847. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9848. protocol, host, &port, path);
  9849. strcpy(user,"anonymous");
  9850. strcpy(password,"");
  9851. }
  9852. else
  9853. {
  9854. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9855. protocol, user, password, host, &port, path);
  9856. }
  9857. sscanf(host,"%[^/]%s",host1, path1);
  9858. sprintf(ftppath,"%s", path1);
  9859. //DEBUG_INFO("protocol =%s\n",protocol);
  9860. //DEBUG_INFO("user =%s\n",user);
  9861. //DEBUG_INFO("password =%s\n",password);
  9862. //DEBUG_INFO("host1 =%s\n",host1);
  9863. //DEBUG_INFO("port =%d\n",port);
  9864. //DEBUG_INFO("path1 =%s\n",path1);
  9865. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9866. //ftpFile(host, user, password, port, ftppath, fname);
  9867. //download firmware pthred
  9868. if(port == 0)
  9869. {
  9870. port = 21;
  9871. }
  9872. do
  9873. {
  9874. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9875. sleep(3);
  9876. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9877. if(!isSuccess)
  9878. {
  9879. //BulldogUtil.sleepMs(interval*1000);
  9880. DEBUG_INFO("Update firmware request and download file fail.\n");
  9881. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9882. sleep(retryIntervalInt);
  9883. }
  9884. else
  9885. {
  9886. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9887. }
  9888. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9889. }
  9890. else
  9891. {
  9892. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9893. }
  9894. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9895. pthread_exit(NULL);
  9896. }
  9897. //==========================================
  9898. // Handle server response routine
  9899. //==========================================
  9900. void handleAuthorizeResponse(char *payload, int gun_index)
  9901. {
  9902. mtrace();
  9903. char expiryDatestr[30]={0};
  9904. char parentIdTagstr[20]={0};
  9905. char statusstr[20]={0};
  9906. int expiryDateISNULL=FALSE;
  9907. int parentIdTagISNULL=FALSE;
  9908. DEBUG_INFO("handleAuthorizeResponse...\n");
  9909. json_object *Authorize;
  9910. Authorize = json_tokener_parse(payload);
  9911. if(!is_error(Authorize))
  9912. {
  9913. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  9914. {
  9915. // Required data
  9916. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  9917. // Optional data
  9918. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  9919. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  9920. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  9921. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  9922. }
  9923. }
  9924. json_object_put(Authorize);
  9925. if(expiryDateISNULL == FALSE)
  9926. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9927. if(parentIdTagISNULL == FALSE)
  9928. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9929. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9930. //Update idTag information to authorization cache if supproted
  9931. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9932. {
  9933. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  9934. }
  9935. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9936. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9937. authorizeRetryTimes = 0;
  9938. }
  9939. void handleBootNotificationResponse(char *payload, int gun_index)
  9940. {
  9941. mtrace();
  9942. char statusStr[12]={0};
  9943. char currentTimeStr[30]={0};
  9944. int intervalInt = 0;
  9945. struct tm tp;
  9946. char buf[28]={0};
  9947. char timebuf[50]={0};
  9948. DEBUG_INFO("handleBootNotificationResponse...\n");
  9949. json_object *BootNotification;
  9950. BootNotification = json_tokener_parse(payload);
  9951. if(!is_error(BootNotification))
  9952. {
  9953. // Required data
  9954. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  9955. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  9956. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  9957. }
  9958. json_object_put(BootNotification);
  9959. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9960. BootNotificationInterval = intervalInt;
  9961. HeartBeatWaitTime = intervalInt;
  9962. //write back to ShmOCPP16Data->BootNotification
  9963. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9964. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9965. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9966. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  9967. {
  9968. server_sign = TRUE;
  9969. server_pending =FALSE;
  9970. }
  9971. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9972. {
  9973. server_pending = TRUE;
  9974. }
  9975. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9976. tp.tm_isdst = -1;
  9977. //time_t utc = mktime(&tp);
  9978. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9979. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9980. sprintf(timebuf,"date -s '%s'",buf);
  9981. system(timebuf);
  9982. srand(time(NULL));
  9983. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  9984. //==============================================
  9985. // RTC sync
  9986. //==============================================
  9987. system("/sbin/hwclock -w --systohc");
  9988. SetOcppConnStatus(TRUE);
  9989. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9990. }
  9991. void handleDataTransferResponse(char *payload, int gun_index)
  9992. {
  9993. char sstr[160]={0};//sstr[200]={ 0 };
  9994. int c = 0;
  9995. char *loc;
  9996. DEBUG_INFO("handleDataTransferResponse ...\n");
  9997. loc = strstr(payload, "status");
  9998. printf("loc=%s\n",loc);
  9999. c = 0;
  10000. while (loc[3+strlen("status")+c] != '\"')
  10001. {
  10002. sstr[c] = loc[3+strlen("status")+c];
  10003. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10004. c++;
  10005. }
  10006. sstr[c] = '\0';
  10007. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  10008. }
  10009. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  10010. {
  10011. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  10012. //struct json_object *obj;
  10013. // obj = json_tokener_parse(payload);
  10014. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  10015. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  10016. //No fields are defined.
  10017. }
  10018. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  10019. {
  10020. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  10021. //struct json_object *obj;
  10022. // obj = json_tokener_parse(payload);
  10023. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  10024. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  10025. //No fields are defined.
  10026. }
  10027. void handleHeartbeatResponse(char *payload, int gun_index)
  10028. {
  10029. mtrace();
  10030. struct tm tp;
  10031. char buf[28]={0};
  10032. char timebuf[50]={0};
  10033. DEBUG_INFO("handleHeartbeatResponse...\n");
  10034. json_object *Heartbeat;
  10035. Heartbeat = json_tokener_parse(payload);
  10036. if(!is_error(Heartbeat))
  10037. {
  10038. // Required data
  10039. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  10040. }
  10041. json_object_put(Heartbeat);
  10042. if(FirstHeartBeat == 0)
  10043. {
  10044. FirstHeartBeat = 1;
  10045. DEBUG_INFO("FirstHeartBeat \n");
  10046. }
  10047. HeartBeatWithNOResponse = 0;
  10048. clientTime.Heartbeat=time((time_t*)NULL);
  10049. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10050. tp.tm_isdst = -1;
  10051. //time_t utc = mktime(&tp);
  10052. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  10053. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  10054. sprintf(timebuf,"date -s '%s'",buf);
  10055. system(timebuf);
  10056. //==============================================
  10057. // RTC sync
  10058. //==============================================
  10059. system("/sbin/hwclock -w --systohc");
  10060. }
  10061. void handleMeterValuesResponse(char *payload, int gun_index)
  10062. {
  10063. mtrace();
  10064. DEBUG_INFO("handleMeterValuesResponse...\n");
  10065. }
  10066. void handleStartTransactionResponse(char *payload, int gun_index)
  10067. {
  10068. mtrace();
  10069. //int transactionIdInt = 0;
  10070. FILE *outfile;
  10071. char data[100]={0};
  10072. DEBUG_INFO("handleStartTransactionResponse...\n");
  10073. json_object *StartTransaction;
  10074. StartTransaction = json_tokener_parse(payload);
  10075. if(!is_error(StartTransaction))
  10076. {
  10077. // Required data
  10078. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  10079. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  10080. // Optional data
  10081. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  10082. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  10083. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10084. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  10085. }
  10086. json_object_put(StartTransaction);
  10087. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  10088. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  10089. //-----------Start : write to the Queue TransactionId file -----------------//
  10090. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  10091. {}
  10092. else
  10093. {
  10094. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  10095. if(log == NULL)
  10096. {
  10097. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  10098. return ;
  10099. }
  10100. else
  10101. {
  10102. fclose(log);
  10103. }
  10104. }
  10105. // open file for writing
  10106. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  10107. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  10108. {
  10109. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  10110. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  10111. fputs(data, outfile);
  10112. fclose (outfile);
  10113. }
  10114. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10115. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10116. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  10117. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  10118. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10119. }
  10120. void handleStatusNotificationResponse(char *payload, int gun_index)
  10121. {
  10122. mtrace();
  10123. DEBUG_INFO("handleStatusNotificationResponse...\n");
  10124. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  10125. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  10126. }
  10127. void handleStopTransactionnResponse(char *payload, int gun_index)
  10128. {
  10129. mtrace();
  10130. DEBUG_INFO("handleStopTransactionnResponse...\n");
  10131. json_object *StopTransaction;
  10132. StopTransaction = json_tokener_parse(payload);
  10133. if(!is_error(StopTransaction))
  10134. {
  10135. // Optional data
  10136. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  10137. {
  10138. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  10139. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  10140. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  10141. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10142. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  10143. }
  10144. }
  10145. json_object_put(StopTransaction);
  10146. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  10147. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  10148. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10149. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10150. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  10151. }
  10152. //==========================================
  10153. // Handle Error routine
  10154. //==========================================
  10155. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  10156. {
  10157. mtrace();
  10158. #ifdef SystemLogMessage
  10159. DEBUG_INFO("errorCode: %s\n", errorCode);
  10160. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  10161. DEBUG_INFO("errorDetails: %s\n", payload);
  10162. #endif
  10163. }
  10164. //===============================================
  10165. // Common routine
  10166. //===============================================
  10167. int initialConfigurationTable(void)
  10168. {
  10169. //clock_t start_t, end_t, total_t;
  10170. FILE *fp;
  10171. FILE *outfile;
  10172. char str[512]={0};
  10173. char sstr[256]={0};
  10174. int c = 0;
  10175. char *loc;
  10176. int confVersion = 1;
  10177. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  10178. //start_t = clock();
  10179. //printf("Starting of the program, start_t = %ld\n", start_t);
  10180. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  10181. // Check configuration file size is correct
  10182. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  10183. {
  10184. struct stat st;
  10185. stat("/Storage/OCPP/OCPPConfiguration", &st);
  10186. if(st.st_size < 3100)
  10187. {
  10188. system("rm -f /Storage/OCPP/OCPPConfiguration");
  10189. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  10190. }
  10191. }
  10192. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  10193. {
  10194. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10195. if(outfile == NULL)
  10196. {
  10197. DEBUG_INFO("Error opening file\n");
  10198. return FALSE;
  10199. }
  10200. /*Core Profile*/
  10201. //AllowOfflineTxForUnknownId
  10202. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10203. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10204. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  10205. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10206. //AuthorizationCacheEnabled
  10207. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10208. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10209. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10210. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10211. //AuthorizeRemoteTxRequests
  10212. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10213. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10214. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  10215. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10216. //BlinkRepeat
  10217. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10218. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10219. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10220. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10221. //ClockAlignedDataInterval
  10222. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10223. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10224. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10225. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10226. //ConnectionTimeOut
  10227. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10228. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10229. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10230. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10231. //GetConfigurationMaxKeys
  10232. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10233. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10234. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  10235. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10236. // HeartbeatInterval
  10237. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10238. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10239. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  10240. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10241. // LightIntensity
  10242. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10243. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10244. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10245. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10246. // LocalAuthorizeOffline
  10247. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  10248. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10249. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10250. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10251. // LocalPreAuthorize
  10252. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10253. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10254. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10255. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10256. // MaxEnergyOnInvalidId
  10257. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10258. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10259. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10260. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10261. // MeterValuesAlignedData
  10262. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10263. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10264. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10265. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10266. else
  10267. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10268. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10269. // MeterValuesAlignedDataMaxLength
  10270. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10271. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10272. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10273. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  10274. else
  10275. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "9" );
  10276. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10277. // MeterValuesSampledData
  10278. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10279. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10280. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10281. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10282. else
  10283. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10284. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10285. // MeterValuesSampledDataMaxLength
  10286. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10287. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10288. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10289. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  10290. else
  10291. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "9" );
  10292. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10293. // MeterValueSampleInterval
  10294. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10295. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10296. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  10297. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10298. // MinimumStatusDuration
  10299. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10301. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  10302. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  10303. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10304. // NumberOfConnectors
  10305. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10306. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10307. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10308. {
  10309. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10310. }
  10311. else
  10312. {
  10313. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10314. }
  10315. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10316. // ResetRetries
  10317. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10318. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10319. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10320. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10321. // ConnectorPhaseRotation
  10322. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10323. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10324. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10325. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10326. // ConnectorPhaseRotationMaxLength
  10327. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10328. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10329. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10330. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10331. // StopTransactionOnEVSideDisconnect
  10332. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10333. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10334. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10335. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10336. // StopTransactionOnInvalidId
  10337. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  10338. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10339. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10340. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10341. // StopTxnAlignedData
  10342. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10343. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10344. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10345. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10346. // StopTxnAlignedDataMaxLength
  10347. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10348. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10349. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10350. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10351. // StopTxnSampledData
  10352. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10353. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10354. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10355. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10356. else
  10357. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10358. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10359. // StopTxnSampledDataMaxLength
  10360. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10361. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10362. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10363. {
  10364. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  10365. }
  10366. else
  10367. {
  10368. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  10369. }
  10370. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10371. // SupportedFeatureProfiles
  10372. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10373. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10374. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10375. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10376. // SupportedFeatureProfilesMaxLength
  10377. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10378. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10379. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10380. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10381. // TransactionMessageAttempts
  10382. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10383. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10384. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10385. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10386. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10387. // TransactionMessageRetryInterval
  10388. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10389. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10390. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10391. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10392. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10393. // UnlockConnectorOnEVSideDisconnect
  10394. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10395. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10396. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10397. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10398. // WebSocketPingInterval
  10399. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10400. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10401. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10402. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10403. // QueueOffLineStartTransactionMessage
  10404. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  10405. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10406. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10407. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10408. // AuthorizationKey
  10409. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  10410. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  10411. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "" );
  10412. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  10413. // SecurityProfile
  10414. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  10415. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  10416. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "0" );
  10417. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  10418. // DefaultPrice
  10419. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  10420. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  10421. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  10422. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  10423. // CustomDisplayCostAndPrice
  10424. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  10425. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  10426. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  10427. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  10428. // CustomIdleFeeAfterStop
  10429. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  10430. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  10431. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  10432. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  10433. // Configuration Version
  10434. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  10435. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  10436. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  10437. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  10438. //* Local Auth List Management Profile*/
  10439. #if 0
  10440. //For OCTT Test Case
  10441. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10442. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10443. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10444. #endif
  10445. #if 1
  10446. //LocalAuthListEnabled
  10447. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10448. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10449. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10450. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10451. #endif
  10452. //LocalAuthListMaxLength
  10453. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10454. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10455. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10456. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10457. //SendLocalListMaxLength
  10458. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10459. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10460. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  10461. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10462. //ReserveConnectorZeroSupported
  10463. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10464. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10465. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10466. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10467. //* Smart Charging Profile */
  10468. //ChargeProfileMaxStackLevel
  10469. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10470. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10471. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10472. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10473. // ChargingScheduleAllowedChargingRateUnit
  10474. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10475. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10476. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10477. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10478. // ChargingScheduleMaxPeriods
  10479. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10480. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10481. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10482. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10483. // ConnectorSwitch3to1PhaseSupported
  10484. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10485. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10486. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10487. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10488. // MaxChargingProfilesInstalled
  10489. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10490. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10491. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  10492. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10493. fclose(outfile);
  10494. }
  10495. else
  10496. {
  10497. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10498. char keystr[60]={0};
  10499. char readonlystr[10]={0};
  10500. char valuestr[256]={0};
  10501. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10502. if(fp == NULL) {
  10503. DEBUG_INFO("Error opening file");
  10504. return FALSE;
  10505. }
  10506. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  10507. {
  10508. //DEBUG_INFO("Get Configuration \n");
  10509. if(strlen(str) > 0)
  10510. {
  10511. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10512. //*************************key*********************************/
  10513. if(strstr(str, "key") != NULL)
  10514. {
  10515. loc = strstr(str, "key");
  10516. c = 0;
  10517. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10518. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  10519. {
  10520. sstr[c] = loc[strlen("key")+3+c];
  10521. c++;
  10522. }
  10523. sstr[c] = '\0';
  10524. strcpy(keystr,sstr);
  10525. }
  10526. //*************************readonly*********************************/
  10527. if(strstr(str, "readonly") != NULL)
  10528. {
  10529. loc = strstr(str, "readonly");
  10530. c = 0;
  10531. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10532. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  10533. {
  10534. sstr[c] = loc[strlen("readonly")+2+c];
  10535. c++;
  10536. }
  10537. sstr[c] = '\0';
  10538. strcpy(readonlystr,sstr);
  10539. }
  10540. //*************************value*********************************/
  10541. if(strstr(str, "value") != NULL)
  10542. {
  10543. loc = strstr(str, "value");
  10544. c = 0;
  10545. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10546. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  10547. {
  10548. sstr[c] = loc[strlen("value")+3+c];
  10549. c++;
  10550. }
  10551. sstr[c] = '\0';
  10552. strcpy(valuestr,sstr);
  10553. }
  10554. // DEBUG_INFO("keystr=%s\n",keystr);
  10555. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10556. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10557. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10558. {
  10559. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10560. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10561. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10562. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10563. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10564. }
  10565. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10566. {
  10567. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10568. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10569. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10570. }
  10571. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10572. {
  10573. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10574. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10575. }
  10576. if(strcmp(keystr, "BlinkRepeat") == 0)
  10577. {
  10578. //Charger.BlinkRepeat = Integer.parseInt(value);
  10579. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10580. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10581. }
  10582. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10583. {
  10584. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10585. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10586. }
  10587. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10588. {
  10589. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10590. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10591. }
  10592. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10593. {
  10594. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10595. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  10596. }
  10597. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10598. {
  10599. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10600. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10601. HeartBeatWaitTime = atoi(valuestr);
  10602. }
  10603. if(strcmp(keystr, "LightIntensity") == 0)
  10604. {
  10605. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10606. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10607. }
  10608. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10609. {
  10610. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10611. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10612. }
  10613. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10614. {
  10615. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10616. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10617. }
  10618. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10619. {
  10620. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10621. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10622. }
  10623. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10624. {
  10625. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10626. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10627. }
  10628. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10629. {
  10630. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10631. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10632. }
  10633. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10634. {
  10635. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10636. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10637. }
  10638. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10639. {
  10640. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10641. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10642. }
  10643. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10644. {
  10645. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10646. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10647. }
  10648. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10649. {
  10650. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10651. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10652. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10653. }
  10654. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10655. {
  10656. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10657. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10658. }
  10659. if(strcmp(keystr, "ResetRetries") == 0)
  10660. {
  10661. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10662. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10663. }
  10664. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10665. {
  10666. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10667. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10668. }
  10669. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10670. {
  10671. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10672. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10673. }
  10674. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10675. {
  10676. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10677. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10678. }
  10679. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10680. {
  10681. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10682. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10683. }
  10684. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10685. {
  10686. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10687. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10688. }
  10689. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10690. {
  10691. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10692. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10693. }
  10694. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10695. {
  10696. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10697. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10698. }
  10699. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10700. {
  10701. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10702. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10703. }
  10704. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10705. {
  10706. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10707. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10708. }
  10709. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10710. {
  10711. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10712. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10713. }
  10714. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10715. {
  10716. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10717. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10718. TransactionMessageAttemptsValue = atoi(valuestr);
  10719. }
  10720. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10721. {
  10722. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10723. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10724. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10725. }
  10726. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10727. {
  10728. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10729. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10730. }
  10731. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10732. {
  10733. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10734. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10735. }
  10736. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  10737. {
  10738. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10739. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  10740. }
  10741. if(strcmp(keystr, "AuthorizationKey") == 0)
  10742. {
  10743. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10744. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  10745. }
  10746. if(strcmp(keystr, "SecurityProfile") == 0)
  10747. {
  10748. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10749. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  10750. }
  10751. if(strcmp(keystr, "DefaultPrice") == 0)
  10752. {
  10753. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10754. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  10755. }
  10756. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  10757. {
  10758. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10759. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  10760. }
  10761. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  10762. {
  10763. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10764. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  10765. }
  10766. if(strcmp(keystr, "ConfigurationVersion") == 0)
  10767. {
  10768. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10769. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  10770. }
  10771. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10772. {
  10773. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10774. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10775. }
  10776. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10777. {
  10778. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10779. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10780. }
  10781. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10782. {
  10783. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10784. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10785. }
  10786. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10787. {
  10788. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10789. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10790. }
  10791. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10792. {
  10793. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10794. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10795. }
  10796. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10797. {
  10798. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10799. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10800. }
  10801. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10802. {
  10803. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10804. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10805. }
  10806. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10807. {
  10808. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10809. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10810. }
  10811. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10812. {
  10813. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10814. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10815. }
  10816. }
  10817. }
  10818. fclose(fp);
  10819. }
  10820. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  10821. {
  10822. return PASS;
  10823. }
  10824. else
  10825. {
  10826. return FAIL;
  10827. }
  10828. }
  10829. void StoreConfigurationTable(void)
  10830. {
  10831. FILE *outfile;
  10832. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10833. if(outfile == NULL)
  10834. {
  10835. DEBUG_INFO("Error opening file");
  10836. return ;
  10837. }
  10838. /*Core Profile*/
  10839. //AllowOfflineTxForUnknownId
  10840. /*
  10841. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10842. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10843. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10845. */
  10846. //DEBUG_INFO("data=%s\n",data);
  10847. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10848. //AuthorizationCacheEnabled
  10849. /*
  10850. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10852. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10853. */
  10854. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10855. //AuthorizeRemoteTxRequests
  10856. /*
  10857. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10859. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10860. */
  10861. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10862. //BlinkRepeat
  10863. /*
  10864. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10865. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10867. */
  10868. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10869. //ClockAlignedDataInterval
  10870. /*
  10871. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10872. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10874. */
  10875. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10876. //ConnectionTimeOut
  10877. /*
  10878. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10879. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10880. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10881. */
  10882. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10883. //GetConfigurationMaxKeys
  10884. /*
  10885. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10886. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10888. */
  10889. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10890. // HeartbeatInterval
  10891. /*
  10892. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10893. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10894. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10895. */
  10896. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10897. // LightIntensity
  10898. /*
  10899. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10900. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10901. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10902. */
  10903. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10904. // LocalAuthorizeOffline
  10905. /*
  10906. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10907. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10908. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10909. */
  10910. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10911. // LocalPreAuthorize
  10912. /*
  10913. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10914. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10915. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10916. */
  10917. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10918. // MaxEnergyOnInvalidId
  10919. /*
  10920. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10921. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10922. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10923. */
  10924. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10925. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10926. // MeterValuesAlignedData
  10927. /*
  10928. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10929. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10930. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10931. */
  10932. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10933. // MeterValuesAlignedDataMaxLength
  10934. /*
  10935. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10936. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10937. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10938. */
  10939. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10940. // MeterValuesSampledData
  10941. /*
  10942. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10943. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10944. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10945. */
  10946. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10947. // MeterValuesSampledDataMaxLength
  10948. /*
  10949. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10950. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10951. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10952. */
  10953. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10954. // MeterValueSampleInterval
  10955. /*
  10956. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10957. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10958. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10959. */
  10960. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10961. // MinimumStatusDuration
  10962. /*
  10963. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10964. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10965. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10966. */
  10967. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10968. // NumberOfConnectors
  10969. /*
  10970. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10971. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10972. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10973. {
  10974. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10975. }
  10976. else
  10977. {
  10978. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10979. }
  10980. */
  10981. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10982. // ResetRetries
  10983. /*
  10984. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10985. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10986. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10987. */
  10988. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10989. // ConnectorPhaseRotation
  10990. /*
  10991. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10992. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10993. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10994. */
  10995. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10996. // ConnectorPhaseRotationMaxLength
  10997. /*
  10998. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10999. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  11000. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  11001. */
  11002. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  11003. // StopTransactionOnEVSideDisconnect
  11004. /*
  11005. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  11006. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  11007. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  11008. */
  11009. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  11010. // StopTransactionOnInvalidId
  11011. /*
  11012. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  11013. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  11014. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  11015. */
  11016. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  11017. // StopTxnAlignedData
  11018. /*
  11019. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  11020. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  11021. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  11022. */
  11023. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  11024. // StopTxnAlignedDataMaxLength
  11025. /*
  11026. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  11027. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  11028. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11029. */
  11030. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11031. // StopTxnSampledData
  11032. /*
  11033. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11034. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11035. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  11036. */
  11037. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11038. // StopTxnSampledDataMaxLength
  11039. /*
  11040. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11041. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11042. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  11043. */
  11044. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11045. // SupportedFeatureProfiles
  11046. /*
  11047. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11048. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11049. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11050. */
  11051. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  11052. // SupportedFeatureProfilesMaxLength
  11053. /*
  11054. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  11055. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  11056. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  11057. */
  11058. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  11059. // TransactionMessageAttempts
  11060. /*
  11061. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11062. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11063. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11064. */
  11065. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11066. // TransactionMessageRetryInterval
  11067. /*
  11068. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11070. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11071. */
  11072. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11073. // UnlockConnectorOnEVSideDisconnect
  11074. /*
  11075. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11077. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11078. */
  11079. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11080. // WebSocketPingInterval
  11081. /*
  11082. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11085. */
  11086. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11087. // QueueOffLineStartTransactionMessage
  11088. /*
  11089. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  11090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  11091. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  11092. */
  11093. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  11094. // AuthorizationKey
  11095. /*
  11096. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  11097. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  11098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  11099. */
  11100. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  11101. // SecurityProfile
  11102. /*
  11103. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  11104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  11105. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  11106. */
  11107. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  11108. // DefaultPrice
  11109. /*
  11110. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  11111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  11112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  11113. */
  11114. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  11115. // CustomDisplayCostAndPrice
  11116. /*
  11117. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  11118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  11119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  11120. */
  11121. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  11122. // CustomIdleFeeAfterStop
  11123. /*
  11124. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  11125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  11126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  11127. */
  11128. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  11129. // ConfigurationVersion
  11130. /*
  11131. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  11132. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  11133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  11134. */
  11135. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  11136. //* Local Auth List Management Profile*/
  11137. //LocalAuthListEnabled
  11138. /*
  11139. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11140. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  11141. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11142. */
  11143. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11144. //LocalAuthListMaxLength
  11145. /*
  11146. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  11147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  11148. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  11149. */
  11150. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  11151. //SendLocalListMaxLength
  11152. /*
  11153. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  11154. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11155. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  11156. */
  11157. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11158. //ReserveConnectorZeroSupported
  11159. /*
  11160. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11162. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11163. */
  11164. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11165. //* Smart Charging Profile */
  11166. //ChargeProfileMaxStackLevel
  11167. /*
  11168. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11169. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11170. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11171. */
  11172. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11173. // ChargingScheduleAllowedChargingRateUnit
  11174. /*
  11175. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11176. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11177. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  11178. */
  11179. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11180. // ChargingScheduleMaxPeriods
  11181. /*
  11182. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11183. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11184. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11185. */
  11186. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11187. // ConnectorSwitch3to1PhaseSupported
  11188. /*
  11189. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11190. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11191. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  11192. */
  11193. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11194. // MaxChargingProfilesInstalled
  11195. /*
  11196. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11197. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11198. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  11199. */
  11200. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11201. fclose(outfile);
  11202. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11203. }
  11204. void getKeyValue(char *keyReq)
  11205. {
  11206. int isEmpty = FALSE;
  11207. int isKnowKey = FALSE;
  11208. DEBUG_INFO("keyReq = %s\n", keyReq);
  11209. if((keyReq == NULL) || (strlen(keyReq) == 0))
  11210. isEmpty = TRUE;
  11211. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  11212. {
  11213. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  11214. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  11215. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11216. {
  11217. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  11218. }
  11219. else
  11220. {
  11221. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  11222. }
  11223. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  11224. isKnowKey = TRUE;
  11225. }
  11226. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  11227. {
  11228. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  11229. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  11230. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11231. {
  11232. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  11233. }
  11234. else
  11235. {
  11236. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  11237. }
  11238. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  11239. isKnowKey = TRUE;
  11240. }
  11241. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  11242. {
  11243. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  11244. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  11245. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11246. {
  11247. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  11248. }
  11249. else
  11250. {
  11251. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  11252. }
  11253. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  11254. isKnowKey = TRUE;
  11255. }
  11256. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  11257. {
  11258. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  11259. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  11260. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11261. {
  11262. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  11263. }
  11264. else
  11265. {
  11266. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  11267. }
  11268. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  11269. isKnowKey = TRUE;
  11270. }
  11271. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  11272. {
  11273. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  11274. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  11275. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11276. {
  11277. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  11278. }
  11279. else
  11280. {
  11281. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  11282. }
  11283. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  11284. isKnowKey = TRUE;
  11285. }
  11286. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  11287. {
  11288. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  11289. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  11290. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11291. {
  11292. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  11293. }
  11294. else
  11295. {
  11296. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  11297. }
  11298. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  11299. isKnowKey = TRUE;
  11300. }
  11301. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  11302. {
  11303. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  11304. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  11305. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11306. {
  11307. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  11308. }
  11309. else
  11310. {
  11311. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  11312. }
  11313. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  11314. isKnowKey = TRUE;
  11315. }
  11316. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  11317. {
  11318. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  11319. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  11320. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11321. {
  11322. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  11323. }
  11324. else
  11325. {
  11326. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  11327. }
  11328. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  11329. isKnowKey = TRUE;
  11330. }
  11331. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  11332. {
  11333. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  11334. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  11335. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11336. {
  11337. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  11338. }
  11339. else
  11340. {
  11341. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  11342. }
  11343. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  11344. isKnowKey = TRUE;
  11345. }
  11346. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  11347. {
  11348. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  11349. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  11350. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11351. {
  11352. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  11353. }
  11354. else
  11355. {
  11356. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  11357. }
  11358. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  11359. isKnowKey = TRUE;
  11360. }
  11361. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  11362. {
  11363. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  11364. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  11365. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11366. {
  11367. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  11368. }
  11369. else
  11370. {
  11371. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  11372. }
  11373. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  11374. isKnowKey = TRUE;
  11375. }
  11376. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  11377. {
  11378. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  11379. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  11380. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11381. {
  11382. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11383. }
  11384. else
  11385. {
  11386. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11387. }
  11388. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  11389. isKnowKey = TRUE;
  11390. }
  11391. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  11392. {
  11393. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  11394. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11395. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11396. {
  11397. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11398. }
  11399. else
  11400. {
  11401. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11402. }
  11403. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11404. isKnowKey = TRUE;
  11405. }
  11406. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11407. {
  11408. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11409. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11410. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11411. {
  11412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11413. }
  11414. else
  11415. {
  11416. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11417. }
  11418. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11419. isKnowKey = TRUE;
  11420. }
  11421. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11422. {
  11423. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11424. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11425. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11426. {
  11427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11428. }
  11429. else
  11430. {
  11431. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11432. }
  11433. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11434. isKnowKey = TRUE;
  11435. }
  11436. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11437. {
  11438. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11439. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11440. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11441. {
  11442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11443. }
  11444. else
  11445. {
  11446. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11447. }
  11448. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11449. isKnowKey = TRUE;
  11450. }
  11451. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11452. {
  11453. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11454. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11455. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11456. {
  11457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11458. }
  11459. else
  11460. {
  11461. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11462. }
  11463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11464. isKnowKey = TRUE;
  11465. }
  11466. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11467. {
  11468. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11469. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11470. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11471. {
  11472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11473. }
  11474. else
  11475. {
  11476. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11477. }
  11478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11479. isKnowKey = TRUE;
  11480. }
  11481. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11482. {
  11483. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11484. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11485. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11486. {
  11487. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11488. }
  11489. else
  11490. {
  11491. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11492. }
  11493. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  11494. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11495. isKnowKey = TRUE;
  11496. }
  11497. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11498. {
  11499. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11500. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11501. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11502. {
  11503. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11504. }
  11505. else
  11506. {
  11507. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11508. }
  11509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11510. isKnowKey = TRUE;
  11511. }
  11512. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11513. {
  11514. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11515. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11516. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11517. {
  11518. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11519. }
  11520. else
  11521. {
  11522. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11523. }
  11524. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11525. isKnowKey = TRUE;
  11526. }
  11527. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11528. {
  11529. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11530. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11531. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11532. {
  11533. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11534. }
  11535. else
  11536. {
  11537. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11538. }
  11539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11540. isKnowKey = TRUE;
  11541. }
  11542. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11543. {
  11544. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11545. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11546. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11547. {
  11548. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11549. }
  11550. else
  11551. {
  11552. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11553. }
  11554. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11555. isKnowKey = TRUE;
  11556. }
  11557. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11558. {
  11559. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11560. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11561. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11562. {
  11563. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11564. }
  11565. else
  11566. {
  11567. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11568. }
  11569. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11570. isKnowKey = TRUE;
  11571. }
  11572. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11573. {
  11574. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11575. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11576. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11577. {
  11578. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11579. }
  11580. else
  11581. {
  11582. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11583. }
  11584. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11585. isKnowKey = TRUE;
  11586. }
  11587. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11588. {
  11589. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11590. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11591. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11592. {
  11593. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11594. }
  11595. else
  11596. {
  11597. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11598. }
  11599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11600. isKnowKey = TRUE;
  11601. }
  11602. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11603. {
  11604. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11605. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11606. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11607. {
  11608. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11609. }
  11610. else
  11611. {
  11612. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11613. }
  11614. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11615. isKnowKey = TRUE;
  11616. }
  11617. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11618. {
  11619. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11620. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11621. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11622. {
  11623. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11624. }
  11625. else
  11626. {
  11627. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11628. }
  11629. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11630. isKnowKey = TRUE;
  11631. }
  11632. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11633. {
  11634. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11635. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11636. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11637. {
  11638. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11639. }
  11640. else
  11641. {
  11642. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11643. }
  11644. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11645. isKnowKey = TRUE;
  11646. }
  11647. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11648. {
  11649. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11650. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11651. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11652. {
  11653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11654. }
  11655. else
  11656. {
  11657. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11658. }
  11659. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11660. isKnowKey = TRUE;
  11661. }
  11662. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11663. {
  11664. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11665. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11666. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11667. {
  11668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11669. }
  11670. else
  11671. {
  11672. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11673. }
  11674. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11675. isKnowKey = TRUE;
  11676. }
  11677. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11678. {
  11679. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11680. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11681. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11682. {
  11683. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11684. }
  11685. else
  11686. {
  11687. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11688. }
  11689. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11690. isKnowKey = TRUE;
  11691. }
  11692. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11693. {
  11694. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11695. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11696. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11697. {
  11698. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11699. }
  11700. else
  11701. {
  11702. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11703. }
  11704. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11705. isKnowKey = TRUE;
  11706. }
  11707. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11708. {
  11709. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11710. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11711. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11712. {
  11713. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11714. }
  11715. else
  11716. {
  11717. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11718. }
  11719. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11720. isKnowKey = TRUE;
  11721. }
  11722. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  11723. {
  11724. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  11725. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  11726. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  11727. {
  11728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  11729. }
  11730. else
  11731. {
  11732. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  11733. }
  11734. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  11735. isKnowKey = TRUE;
  11736. }
  11737. /*
  11738. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  11739. {
  11740. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  11741. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  11742. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  11743. {
  11744. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  11745. }
  11746. else
  11747. {
  11748. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  11749. }
  11750. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  11751. isKnowKey = TRUE;
  11752. }*/
  11753. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  11754. {
  11755. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  11756. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  11757. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  11758. {
  11759. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  11760. }
  11761. else
  11762. {
  11763. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  11764. }
  11765. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  11766. isKnowKey = TRUE;
  11767. }
  11768. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  11769. {
  11770. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  11771. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  11772. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  11773. {
  11774. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  11775. }
  11776. else
  11777. {
  11778. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  11779. }
  11780. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  11781. isKnowKey = TRUE;
  11782. }
  11783. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  11784. {
  11785. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  11786. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  11787. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  11788. {
  11789. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  11790. }
  11791. else
  11792. {
  11793. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  11794. }
  11795. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  11796. isKnowKey = TRUE;
  11797. }
  11798. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  11799. {
  11800. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  11801. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  11802. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  11803. {
  11804. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  11805. }
  11806. else
  11807. {
  11808. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  11809. }
  11810. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  11811. isKnowKey = TRUE;
  11812. }
  11813. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  11814. {
  11815. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  11816. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  11817. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  11818. {
  11819. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  11820. }
  11821. else
  11822. {
  11823. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  11824. }
  11825. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  11826. isKnowKey = TRUE;
  11827. }
  11828. #if 1
  11829. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11830. {
  11831. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11832. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11833. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11834. {
  11835. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11836. }
  11837. else
  11838. {
  11839. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11840. }
  11841. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11842. isKnowKey = TRUE;
  11843. }
  11844. #endif
  11845. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11846. {
  11847. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11848. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11849. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11850. {
  11851. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11852. }
  11853. else
  11854. {
  11855. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11856. }
  11857. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11858. isKnowKey = TRUE;
  11859. }
  11860. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11861. {
  11862. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11863. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11864. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11865. {
  11866. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11867. }
  11868. else
  11869. {
  11870. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11871. }
  11872. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11873. isKnowKey = TRUE;
  11874. }
  11875. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11876. {
  11877. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11878. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11879. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11880. {
  11881. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11882. }
  11883. else
  11884. {
  11885. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11886. }
  11887. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11888. isKnowKey = TRUE;
  11889. }
  11890. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11891. {
  11892. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11893. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11894. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11895. {
  11896. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11897. }
  11898. else
  11899. {
  11900. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11901. }
  11902. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11903. isKnowKey = TRUE;
  11904. }
  11905. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11906. {
  11907. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11908. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11909. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11910. {
  11911. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11912. }
  11913. else
  11914. {
  11915. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11916. }
  11917. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11918. isKnowKey = TRUE;
  11919. }
  11920. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11921. {
  11922. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11923. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11924. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11925. {
  11926. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11927. }
  11928. else
  11929. {
  11930. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11931. }
  11932. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11933. isKnowKey = TRUE;
  11934. }
  11935. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11936. {
  11937. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11938. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11939. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11940. {
  11941. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11942. }
  11943. else
  11944. {
  11945. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11946. }
  11947. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11948. isKnowKey = TRUE;
  11949. }
  11950. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11951. {
  11952. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11953. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11954. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11955. {
  11956. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11957. }
  11958. else
  11959. {
  11960. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11961. }
  11962. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11963. isKnowKey = TRUE;
  11964. }
  11965. //=========================================================
  11966. if(!isEmpty && !isKnowKey)
  11967. {
  11968. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11969. strcpy(unknownkey[UnknownKeynum], keyReq);
  11970. UnknownKeynum = UnknownKeynum + 1;
  11971. }
  11972. }
  11973. void processUnkownKey(void)
  11974. {
  11975. DEBUG_INFO("processUnkownKey...\n");
  11976. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11977. for(int index=0; index < UnknownKeynum; index++)
  11978. {
  11979. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11980. {
  11981. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11982. }
  11983. }
  11984. }
  11985. int setKeyValue(char *key, char *value)
  11986. {
  11987. int isSuccess = NotSupported;
  11988. int check_ascii=0;
  11989. char str[256]={0};
  11990. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  11991. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11992. {
  11993. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11994. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11995. {
  11996. strcpy(str, (const char*)value);
  11997. for(int i = 0; str[i]; i++){
  11998. str[i] = tolower(str[i]);
  11999. }
  12000. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12001. isSuccess = ConfigurationStatus_Accepted;
  12002. }
  12003. else
  12004. {
  12005. isSuccess = ConfigurationStatus_Rejected;
  12006. }
  12007. }
  12008. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  12009. {
  12010. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  12011. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  12012. {
  12013. strcpy(str, (const char*)value);
  12014. for(int i = 0; str[i]; i++){
  12015. str[i] = tolower(str[i]);
  12016. }
  12017. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12018. isSuccess = ConfigurationStatus_Accepted;
  12019. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  12020. }
  12021. else
  12022. {
  12023. isSuccess = ConfigurationStatus_Rejected;
  12024. }
  12025. }
  12026. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  12027. {
  12028. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  12029. {
  12030. strcpy(str, (const char*)value);
  12031. for(int i = 0; str[i]; i++)
  12032. {
  12033. str[i] = tolower(str[i]);
  12034. }
  12035. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  12036. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12037. isSuccess = ConfigurationStatus_Accepted;
  12038. }
  12039. else
  12040. {
  12041. isSuccess = ConfigurationStatus_Rejected;
  12042. }
  12043. }
  12044. if(strcmp(key, "BlinkRepeat") == 0)
  12045. {
  12046. //Charger.BlinkRepeat = Integer.parseInt(value);
  12047. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  12048. {
  12049. check_ascii = value[0];
  12050. if( (check_ascii < 48) || (check_ascii > 57) )
  12051. {
  12052. isSuccess = ConfigurationStatus_Rejected;
  12053. }
  12054. else
  12055. {
  12056. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  12057. isSuccess = ConfigurationStatus_Accepted;
  12058. }
  12059. }
  12060. else
  12061. {
  12062. isSuccess = ConfigurationStatus_Rejected;
  12063. }
  12064. }
  12065. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  12066. {
  12067. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  12068. {
  12069. check_ascii = value[0];
  12070. if( (check_ascii < 48) || (check_ascii > 57) )
  12071. {
  12072. isSuccess = ConfigurationStatus_Rejected;
  12073. }
  12074. else
  12075. {
  12076. if((atoi(value) == 0) || (atoi(value) >= 10))
  12077. {
  12078. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  12079. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  12080. isSuccess = ConfigurationStatus_Accepted;
  12081. }
  12082. else
  12083. isSuccess = ConfigurationStatus_Rejected;
  12084. }
  12085. }
  12086. else
  12087. {
  12088. isSuccess = ConfigurationStatus_Rejected;
  12089. }
  12090. }
  12091. if(strcmp(key, "ConnectionTimeOut") == 0 )
  12092. {
  12093. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  12094. {
  12095. check_ascii = value[0];
  12096. if( (check_ascii < 48) || (check_ascii > 57) )
  12097. {
  12098. isSuccess = ConfigurationStatus_Rejected;
  12099. }
  12100. else
  12101. {
  12102. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  12103. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  12104. isSuccess = ConfigurationStatus_Accepted;
  12105. }
  12106. }
  12107. else
  12108. {
  12109. isSuccess = ConfigurationStatus_Rejected;
  12110. }
  12111. }
  12112. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  12113. {
  12114. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  12115. {
  12116. check_ascii = value[0];
  12117. if( (check_ascii < 48) || (check_ascii > 57) )
  12118. {
  12119. isSuccess = ConfigurationStatus_Rejected;
  12120. }
  12121. else
  12122. {
  12123. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  12124. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  12125. isSuccess = ConfigurationStatus_Accepted;
  12126. }
  12127. }
  12128. else
  12129. {
  12130. isSuccess = ConfigurationStatus_Rejected;
  12131. }
  12132. }
  12133. if(strcmp(key, "HeartbeatInterval") == 0)
  12134. {
  12135. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  12136. {
  12137. check_ascii = value[0];
  12138. if( (check_ascii < 48) || (check_ascii > 57) )
  12139. {
  12140. isSuccess = ConfigurationStatus_Rejected;
  12141. }
  12142. else
  12143. {
  12144. if((atoi(value) == 0) || (atoi(value) >= 10))
  12145. {
  12146. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  12147. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  12148. HeartBeatWaitTime = atoi(value);
  12149. isSuccess = ConfigurationStatus_Accepted;
  12150. }
  12151. else
  12152. {
  12153. isSuccess = ConfigurationStatus_Rejected;
  12154. }
  12155. }
  12156. }
  12157. else
  12158. {
  12159. isSuccess = ConfigurationStatus_Rejected;
  12160. }
  12161. }
  12162. if(strcmp(key, "LightIntensity") == 0)
  12163. {
  12164. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  12165. {
  12166. check_ascii = value[0];
  12167. if( (check_ascii < 48) || (check_ascii > 57) )
  12168. {
  12169. isSuccess = ConfigurationStatus_Rejected;
  12170. }
  12171. else
  12172. {
  12173. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  12174. isSuccess = ConfigurationStatus_Accepted;
  12175. }
  12176. }
  12177. else
  12178. {
  12179. isSuccess = ConfigurationStatus_Rejected;
  12180. }
  12181. }
  12182. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  12183. {
  12184. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  12185. {
  12186. strcpy(str, (const char*)value);
  12187. for(int i = 0; str[i]; i++)
  12188. {
  12189. str[i] = tolower(str[i]);
  12190. }
  12191. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12192. isSuccess = ConfigurationStatus_Accepted;
  12193. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12194. }
  12195. else
  12196. {
  12197. isSuccess = ConfigurationStatus_Rejected;
  12198. }
  12199. }
  12200. if(strcmp(key, "LocalPreAuthorize") == 0)
  12201. {
  12202. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12203. {
  12204. strcpy(str, (const char*)value);
  12205. for(int i = 0; str[i]; i++)
  12206. {
  12207. str[i] = tolower(str[i]);
  12208. }
  12209. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12210. isSuccess = ConfigurationStatus_Accepted;
  12211. }
  12212. else
  12213. {
  12214. isSuccess = ConfigurationStatus_Rejected;
  12215. }
  12216. }
  12217. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  12218. {
  12219. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].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. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  12229. isSuccess = ConfigurationStatus_Accepted;
  12230. }
  12231. }
  12232. else
  12233. {
  12234. isSuccess = ConfigurationStatus_Rejected;
  12235. }
  12236. }
  12237. if(strcmp(key, "MeterValuesAlignedData") == 0)
  12238. {
  12239. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12240. {
  12241. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  12242. isSuccess = ConfigurationStatus_Accepted;
  12243. }
  12244. else
  12245. {
  12246. isSuccess = ConfigurationStatus_Rejected;
  12247. }
  12248. }
  12249. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  12250. {
  12251. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12252. {
  12253. check_ascii = value[0];
  12254. if( (check_ascii < 48) || (check_ascii > 57) )
  12255. {
  12256. isSuccess = ConfigurationStatus_Rejected;
  12257. }
  12258. else
  12259. {
  12260. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12261. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  12262. isSuccess = ConfigurationStatus_Accepted;
  12263. }
  12264. }
  12265. else
  12266. {
  12267. isSuccess = ConfigurationStatus_Rejected;
  12268. }
  12269. }
  12270. if(strcmp(key, "MeterValuesSampledData") == 0 )
  12271. {
  12272. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12273. {
  12274. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  12275. isSuccess = ConfigurationStatus_Accepted;
  12276. }
  12277. else
  12278. {
  12279. isSuccess = ConfigurationStatus_Rejected;
  12280. }
  12281. }
  12282. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  12283. {
  12284. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12285. {
  12286. check_ascii = value[0];
  12287. if( (check_ascii < 48) || (check_ascii > 57) )
  12288. {
  12289. isSuccess = ConfigurationStatus_Rejected;
  12290. }
  12291. else
  12292. {
  12293. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12294. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  12295. isSuccess = ConfigurationStatus_Accepted;
  12296. }
  12297. }
  12298. else
  12299. {
  12300. isSuccess = ConfigurationStatus_Rejected;
  12301. }
  12302. }
  12303. if(strcmp(key, "MeterValueSampleInterval") == 0)
  12304. {
  12305. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12306. {
  12307. check_ascii = value[0];
  12308. if( (check_ascii < 48) || (check_ascii > 57) )
  12309. {
  12310. isSuccess = ConfigurationStatus_Rejected;
  12311. }
  12312. else
  12313. {
  12314. if((atoi(value) == 0) || (atoi(value) >= 10))
  12315. {
  12316. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12317. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  12318. isSuccess = ConfigurationStatus_Accepted;
  12319. }
  12320. else
  12321. {
  12322. isSuccess = ConfigurationStatus_Rejected;
  12323. }
  12324. }
  12325. }
  12326. else
  12327. {
  12328. isSuccess = ConfigurationStatus_Rejected;
  12329. }
  12330. }
  12331. if(strcmp(key, "MinimumStatusDuration") == 0)
  12332. {
  12333. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12334. {
  12335. check_ascii = value[0];
  12336. if( (check_ascii < 48) || (check_ascii > 57) )
  12337. {
  12338. isSuccess = ConfigurationStatus_Rejected;
  12339. }
  12340. else
  12341. {
  12342. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  12343. {
  12344. isSuccess = ConfigurationStatus_Rejected;
  12345. }
  12346. else
  12347. {
  12348. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  12349. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  12350. server_cycle_Status = atoi(value); //StatusNotification Cycle
  12351. isSuccess = ConfigurationStatus_Accepted;
  12352. }
  12353. }
  12354. }
  12355. else
  12356. {
  12357. isSuccess = ConfigurationStatus_Rejected;
  12358. }
  12359. }
  12360. if(strcmp(key, "NumberOfConnectors") == 0)
  12361. {
  12362. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12363. {
  12364. check_ascii = value[0];
  12365. if( (check_ascii < 48) || (check_ascii > 57) )
  12366. {
  12367. isSuccess = ConfigurationStatus_Rejected;
  12368. }
  12369. else
  12370. {
  12371. //Charger.ResetRetries = Integer.parseInt(value);
  12372. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  12373. isSuccess = ConfigurationStatus_Accepted;
  12374. }
  12375. }
  12376. else
  12377. {
  12378. isSuccess = ConfigurationStatus_Rejected;
  12379. }
  12380. }
  12381. if(strcmp(key, "ResetRetries") == 0)
  12382. {
  12383. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12384. {
  12385. check_ascii = value[0];
  12386. if( (check_ascii < 48) || (check_ascii > 57) )
  12387. {
  12388. isSuccess = ConfigurationStatus_Rejected;
  12389. }
  12390. else
  12391. {
  12392. //Charger.ResetRetries = Integer.parseInt(value);
  12393. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  12394. isSuccess = ConfigurationStatus_Accepted;
  12395. }
  12396. }
  12397. else
  12398. {
  12399. isSuccess = ConfigurationStatus_Rejected;
  12400. }
  12401. }
  12402. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  12403. {
  12404. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12405. {
  12406. strcpy(str, (const char*)value);
  12407. for(int i = 0; str[i]; i++)
  12408. {
  12409. str[i] = tolower(str[i]);
  12410. }
  12411. if(strcmp(str, "notapplicable")== 0)
  12412. {
  12413. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12414. isSuccess = ConfigurationStatus_Accepted;
  12415. }
  12416. else if(strcmp(str, "unknown")== 0)
  12417. {
  12418. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12419. isSuccess = ConfigurationStatus_Accepted;
  12420. }
  12421. else if(strcmp(str, "rst")== 0)
  12422. {
  12423. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12424. isSuccess = ConfigurationStatus_Accepted;
  12425. }
  12426. else if(strcmp(str, "rts")== 0)
  12427. {
  12428. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12429. isSuccess = ConfigurationStatus_Accepted;
  12430. }
  12431. else if(strcmp(str, "srt")== 0)
  12432. {
  12433. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12434. isSuccess = ConfigurationStatus_Accepted;
  12435. }
  12436. else if(strcmp(str, "str")== 0)
  12437. {
  12438. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12439. isSuccess = ConfigurationStatus_Accepted;
  12440. }
  12441. else if(strcmp(str, "trs")== 0)
  12442. {
  12443. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12444. isSuccess = ConfigurationStatus_Accepted;
  12445. }
  12446. else if(strcmp(str, "tsr")== 0)
  12447. {
  12448. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12449. isSuccess = ConfigurationStatus_Accepted;
  12450. }
  12451. else
  12452. {
  12453. isSuccess = ConfigurationStatus_Rejected;
  12454. }
  12455. }
  12456. else
  12457. {
  12458. isSuccess = ConfigurationStatus_Rejected;
  12459. }
  12460. }
  12461. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12462. {
  12463. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12464. {
  12465. check_ascii = value[0];
  12466. if( (check_ascii < 48) || (check_ascii > 57) )
  12467. {
  12468. isSuccess = ConfigurationStatus_Rejected;
  12469. }
  12470. else
  12471. {
  12472. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12473. isSuccess = ConfigurationStatus_Accepted;
  12474. }
  12475. }
  12476. else
  12477. {
  12478. isSuccess = ConfigurationStatus_Rejected;
  12479. }
  12480. }
  12481. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12482. {
  12483. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12484. {
  12485. strcpy(str, (const char*)value);
  12486. for(int i = 0; str[i]; i++)
  12487. {
  12488. str[i] = tolower(str[i]);
  12489. }
  12490. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12491. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12492. isSuccess = ConfigurationStatus_Accepted;
  12493. }
  12494. else
  12495. {
  12496. isSuccess = ConfigurationStatus_Rejected;
  12497. }
  12498. }
  12499. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12500. {
  12501. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12502. {
  12503. strcpy(str, (const char*)value);
  12504. for(int i = 0; str[i]; i++)
  12505. {
  12506. str[i] = tolower(str[i]);
  12507. }
  12508. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12509. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12510. isSuccess = ConfigurationStatus_Accepted;
  12511. }
  12512. else
  12513. {
  12514. isSuccess = ConfigurationStatus_Rejected;
  12515. }
  12516. }
  12517. if(strcmp(key, "StopTxnAlignedData") == 0)
  12518. {
  12519. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12520. {
  12521. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12522. isSuccess = ConfigurationStatus_Accepted;
  12523. }
  12524. else
  12525. {
  12526. isSuccess = ConfigurationStatus_Rejected;
  12527. }
  12528. }
  12529. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12530. {
  12531. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].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[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12541. isSuccess = ConfigurationStatus_Accepted;
  12542. }
  12543. }
  12544. else
  12545. {
  12546. isSuccess = ConfigurationStatus_Rejected;
  12547. }
  12548. }
  12549. if(strcmp(key, "StopTxnSampledData") == 0)
  12550. {
  12551. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12552. {
  12553. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12554. isSuccess = ConfigurationStatus_Accepted;
  12555. }
  12556. else
  12557. {
  12558. isSuccess = ConfigurationStatus_Rejected;
  12559. }
  12560. }
  12561. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12562. {
  12563. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].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[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12573. isSuccess = ConfigurationStatus_Accepted;
  12574. }
  12575. }
  12576. else
  12577. {
  12578. isSuccess = ConfigurationStatus_Rejected;
  12579. }
  12580. }
  12581. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12582. {
  12583. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12584. {
  12585. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12586. isSuccess = ConfigurationStatus_Accepted;
  12587. }
  12588. else
  12589. {
  12590. isSuccess = ConfigurationStatus_Rejected;
  12591. }
  12592. }
  12593. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12594. {
  12595. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12596. {
  12597. check_ascii = value[0];
  12598. if( (check_ascii < 48) || (check_ascii > 57) )
  12599. {
  12600. isSuccess = ConfigurationStatus_Rejected;
  12601. }
  12602. else
  12603. {
  12604. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12605. isSuccess = ConfigurationStatus_Accepted;
  12606. }
  12607. }
  12608. else
  12609. {
  12610. isSuccess = ConfigurationStatus_Rejected;
  12611. }
  12612. }
  12613. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12614. {
  12615. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12616. {
  12617. check_ascii = value[0];
  12618. if( (check_ascii < 48) || (check_ascii > 57) )
  12619. {
  12620. isSuccess = ConfigurationStatus_Rejected;
  12621. }
  12622. else
  12623. {
  12624. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12625. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12626. TransactionMessageAttemptsValue = atoi(value);
  12627. isSuccess = ConfigurationStatus_Accepted;
  12628. }
  12629. }
  12630. else
  12631. {
  12632. isSuccess = ConfigurationStatus_Rejected;
  12633. }
  12634. }
  12635. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12636. {
  12637. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12638. {
  12639. check_ascii = value[0];
  12640. if( (check_ascii < 48) || (check_ascii > 57) )
  12641. {
  12642. isSuccess = ConfigurationStatus_Rejected;
  12643. }
  12644. else
  12645. {
  12646. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12647. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12648. TransactionMessageRetryIntervalValue = atoi(value);
  12649. isSuccess = ConfigurationStatus_Accepted;
  12650. }
  12651. }
  12652. else
  12653. {
  12654. isSuccess = ConfigurationStatus_Rejected;
  12655. }
  12656. }
  12657. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12658. {
  12659. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12660. {
  12661. strcpy(str, (const char*)value);
  12662. for(int i = 0; str[i]; i++)
  12663. {
  12664. str[i] = tolower(str[i]);
  12665. }
  12666. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12667. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12668. isSuccess = ConfigurationStatus_Accepted;
  12669. }
  12670. else
  12671. {
  12672. isSuccess = ConfigurationStatus_Rejected;
  12673. }
  12674. }
  12675. if(strcmp(key, "WebSocketPingInterval") == 0)
  12676. {
  12677. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12678. {
  12679. check_ascii = value[0];
  12680. if( (check_ascii < 48) || (check_ascii > 57) )
  12681. {
  12682. isSuccess = ConfigurationStatus_Rejected;
  12683. }
  12684. else
  12685. {
  12686. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12687. isSuccess = ConfigurationStatus_Accepted;
  12688. }
  12689. }
  12690. else
  12691. {
  12692. isSuccess = ConfigurationStatus_Rejected;
  12693. }
  12694. }
  12695. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  12696. {
  12697. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12698. {
  12699. strcpy(str, (const char*)value);
  12700. for(int i = 0; str[i]; i++)
  12701. {
  12702. str[i] = tolower(str[i]);
  12703. }
  12704. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12705. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12706. isSuccess = ConfigurationStatus_Accepted;
  12707. }
  12708. else
  12709. {
  12710. isSuccess = ConfigurationStatus_Rejected;
  12711. }
  12712. }
  12713. if(strcmp(key, "AuthorizationKey") == 0)
  12714. {
  12715. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  12716. {
  12717. strcpy(str, (const char*)value);
  12718. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  12719. isSuccess = ConfigurationStatus_Accepted;
  12720. }
  12721. else
  12722. {
  12723. isSuccess = ConfigurationStatus_Rejected;
  12724. }
  12725. }
  12726. if(strcmp(key, "SecurityProfile") == 0)
  12727. {
  12728. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  12729. {
  12730. check_ascii = value[0];
  12731. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  12732. {
  12733. isSuccess = ConfigurationStatus_Rejected;
  12734. }
  12735. else if(check_ascii == 0x33)
  12736. {
  12737. isSuccess = NotSupported;
  12738. }
  12739. else
  12740. {
  12741. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  12742. {
  12743. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  12744. isSuccess = ConfigurationStatus_Accepted;
  12745. }
  12746. else
  12747. isSuccess = ConfigurationStatus_Rejected;
  12748. }
  12749. }
  12750. else
  12751. {
  12752. isSuccess = ConfigurationStatus_Rejected;
  12753. }
  12754. }
  12755. if(strcmp(key, "DefaultPrice") == 0)
  12756. {
  12757. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  12758. {
  12759. strcpy(str, (const char*)value);
  12760. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  12761. isSuccess = ConfigurationStatus_Accepted;
  12762. }
  12763. else
  12764. {
  12765. isSuccess = ConfigurationStatus_Rejected;
  12766. }
  12767. }
  12768. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  12769. {
  12770. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  12771. {
  12772. strcpy(str, (const char*)value);
  12773. for(int i = 0; str[i]; i++)
  12774. {
  12775. str[i] = tolower(str[i]);
  12776. }
  12777. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12778. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12779. isSuccess = ConfigurationStatus_Accepted;
  12780. }
  12781. else
  12782. {
  12783. isSuccess = ConfigurationStatus_Rejected;
  12784. }
  12785. }
  12786. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  12787. {
  12788. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  12789. {
  12790. strcpy(str, (const char*)value);
  12791. for(int i = 0; str[i]; i++)
  12792. {
  12793. str[i] = tolower(str[i]);
  12794. }
  12795. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12796. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12797. isSuccess = ConfigurationStatus_Accepted;
  12798. }
  12799. else
  12800. {
  12801. isSuccess = ConfigurationStatus_Rejected;
  12802. }
  12803. }
  12804. #if 0
  12805. //For OCPP Test Case
  12806. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12807. {
  12808. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12809. {
  12810. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12811. isSuccess = ConfigurationStatus_Accepted;
  12812. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12813. }
  12814. else
  12815. {
  12816. isSuccess = ConfigurationStatus_Rejected;
  12817. }
  12818. }
  12819. #endif
  12820. #if 1
  12821. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12822. {
  12823. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12824. {
  12825. strcpy(str, (const char*)value);
  12826. for(int i = 0; str[i]; i++)
  12827. {
  12828. str[i] = tolower(str[i]);
  12829. }
  12830. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12831. isSuccess = ConfigurationStatus_Accepted;
  12832. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12833. }
  12834. else
  12835. {
  12836. isSuccess = ConfigurationStatus_Rejected;
  12837. }
  12838. }
  12839. #endif
  12840. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12841. {
  12842. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12843. {
  12844. check_ascii = value[0];
  12845. if( (check_ascii < 48) || (check_ascii > 57) )
  12846. {
  12847. isSuccess = ConfigurationStatus_Rejected;
  12848. }
  12849. else
  12850. {
  12851. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12852. isSuccess = ConfigurationStatus_Accepted;
  12853. }
  12854. }
  12855. else
  12856. {
  12857. isSuccess = ConfigurationStatus_Rejected;
  12858. }
  12859. }
  12860. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12861. {
  12862. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12863. {
  12864. check_ascii = value[0];
  12865. if( (check_ascii < 48) || (check_ascii > 57) )
  12866. {
  12867. isSuccess = ConfigurationStatus_Rejected;
  12868. }
  12869. else
  12870. {
  12871. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12872. isSuccess = ConfigurationStatus_Accepted;
  12873. }
  12874. }
  12875. else
  12876. {
  12877. isSuccess = ConfigurationStatus_Rejected;
  12878. }
  12879. }
  12880. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12881. {
  12882. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12883. {
  12884. strcpy(str, (const char*)value);
  12885. for(int i = 0; str[i]; i++)
  12886. {
  12887. str[i] = tolower(str[i]);
  12888. }
  12889. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12890. isSuccess = ConfigurationStatus_Accepted;
  12891. }
  12892. else
  12893. {
  12894. isSuccess = ConfigurationStatus_Rejected;
  12895. }
  12896. }
  12897. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12898. {
  12899. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].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[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12909. isSuccess = ConfigurationStatus_Accepted;
  12910. }
  12911. }
  12912. else
  12913. {
  12914. isSuccess = ConfigurationStatus_Rejected;
  12915. }
  12916. }
  12917. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12918. {
  12919. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12920. {
  12921. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12922. isSuccess = ConfigurationStatus_Accepted;
  12923. }
  12924. else
  12925. {
  12926. isSuccess = ConfigurationStatus_Rejected;
  12927. }
  12928. }
  12929. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12930. {
  12931. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12932. {
  12933. check_ascii = value[0];
  12934. if( (check_ascii < 48) || (check_ascii > 57) )
  12935. {
  12936. isSuccess = ConfigurationStatus_Rejected;
  12937. }
  12938. else
  12939. {
  12940. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12941. isSuccess = ConfigurationStatus_Accepted;
  12942. }
  12943. }
  12944. else
  12945. {
  12946. isSuccess = ConfigurationStatus_Rejected;
  12947. }
  12948. }
  12949. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12950. {
  12951. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12952. {
  12953. strcpy(str, (const char*)value);
  12954. for(int i = 0; str[i]; i++)
  12955. {
  12956. str[i] = tolower(str[i]);
  12957. }
  12958. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12959. isSuccess = ConfigurationStatus_Accepted;
  12960. }
  12961. else
  12962. {
  12963. isSuccess = ConfigurationStatus_Rejected;
  12964. }
  12965. }
  12966. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12967. {
  12968. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12969. {
  12970. check_ascii = value[0];
  12971. if( (check_ascii < 48) || (check_ascii > 57) )
  12972. {
  12973. isSuccess = ConfigurationStatus_Rejected;
  12974. }
  12975. else
  12976. {
  12977. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12978. isSuccess = ConfigurationStatus_Accepted;
  12979. }
  12980. }
  12981. else
  12982. {
  12983. isSuccess = ConfigurationStatus_Rejected;
  12984. }
  12985. }
  12986. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12987. return isSuccess;
  12988. }
  12989. int TransactionMessageAttemptsGet(void)
  12990. {
  12991. return TransactionMessageAttemptsValue;
  12992. }
  12993. int FirstHeartBeatResponse(void)
  12994. {
  12995. return FirstHeartBeat;
  12996. }
  12997. int TransactionMessageRetryIntervalGet(void)
  12998. {
  12999. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13000. }
  13001. int ReadHttpStatus(int sock)
  13002. {
  13003. //char c;
  13004. char buff[1024]="",*ptr=buff+1;
  13005. int bytes_received, status;
  13006. DEBUG_INFO("Begin Response ..\n");
  13007. while((bytes_received = recv(sock, ptr, 1, 0))){
  13008. if(bytes_received==-1){
  13009. perror("ReadHttpStatus");
  13010. exit(1);
  13011. }
  13012. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  13013. ptr++;
  13014. }
  13015. *ptr=0;
  13016. ptr=buff+1;
  13017. sscanf(ptr,"%*s %d ", &status);
  13018. DEBUG_INFO("%s\n",ptr);
  13019. DEBUG_INFO("status=%d\n",status);
  13020. DEBUG_INFO("End Response ..\n");
  13021. return (bytes_received>0)?status:0;
  13022. }
  13023. //the only filed that it parsed is 'Content-Length'
  13024. int ParseHeader(int sock)
  13025. {
  13026. //char c;
  13027. char buff[1024]="",*ptr=buff+4;
  13028. int bytes_received;
  13029. DEBUG_INFO("Begin HEADER ..\n");
  13030. while((bytes_received = recv(sock, ptr, 1, 0))){
  13031. if(bytes_received==-1){
  13032. perror("Parse Header");
  13033. exit(1);
  13034. }
  13035. if(
  13036. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  13037. (ptr[-1]=='\r') && (*ptr=='\n' )
  13038. ) break;
  13039. ptr++;
  13040. }
  13041. *ptr=0;
  13042. ptr=buff+4;
  13043. //printf("%s",ptr);
  13044. if(bytes_received){
  13045. ptr=strstr(ptr,"Content-Length:");
  13046. if(ptr){
  13047. sscanf(ptr,"%*s %d",&bytes_received);
  13048. }else
  13049. bytes_received=-1; //unknown size
  13050. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  13051. }
  13052. DEBUG_INFO("End HEADER ..\n");
  13053. return bytes_received ;
  13054. }
  13055. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  13056. {
  13057. int result = TRUE;
  13058. char rmFileCmd[100]={0};
  13059. char FilePath[100]={0};
  13060. char ftpbuf[200];
  13061. int systemresult;
  13062. //DEBUG_INFO("filename=%s\n",filename);
  13063. //DEBUG_INFO("url=%s\n",url);
  13064. sprintf(FilePath,"/mnt/%s",filename);
  13065. system("ping 8.8.8.8 &");
  13066. if((access(FilePath,F_OK))!=-1)
  13067. {
  13068. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13069. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13070. system(rmFileCmd);
  13071. }
  13072. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13073. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  13074. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13075. systemresult = system(ftpbuf);
  13076. //DEBUG_INFO("systemresult=%d\n",systemresult);
  13077. if(systemresult != 0)
  13078. {
  13079. DEBUG_INFO("http DownLoad error!\n");
  13080. result = FALSE;
  13081. }
  13082. system("pkill ping");
  13083. return result;
  13084. }
  13085. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  13086. {
  13087. int result = TRUE;
  13088. char rmFileCmd[100]={0};
  13089. char FilePath[100]={0};
  13090. char ftpbuf[200];
  13091. int systemresult;
  13092. //char temp[100];
  13093. sprintf(FilePath,"/mnt/%s",filename);
  13094. system("ping 8.8.8.8 &");
  13095. if((access(FilePath,F_OK))!=-1)
  13096. {
  13097. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13098. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13099. system(rmFileCmd);
  13100. }
  13101. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13102. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  13103. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  13104. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  13105. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13106. systemresult = system(ftpbuf);
  13107. //DEBUG_INFO("systemresult=%d\n",systemresult);
  13108. if(systemresult != 0)
  13109. {
  13110. printf("wget error!\n");
  13111. result = FALSE;
  13112. }
  13113. system("pkill ping");
  13114. return result;
  13115. }
  13116. int httpUploadFile(char *location, char *path, char *filename,char *url)
  13117. {
  13118. char rmFileCmd[100]={0};
  13119. char FilePath[100]={0};
  13120. char buf[512];
  13121. int systemresult = 0;
  13122. //DEBUG_INFO("filename=%s\n",filename);
  13123. //DEBUG_INFO("url=%s\n",url);
  13124. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  13125. if((access(FilePath,F_OK))!=-1)
  13126. {
  13127. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13128. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13129. system(rmFileCmd);
  13130. }
  13131. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  13132. if(fp == NULL)
  13133. {
  13134. DEBUG_INFO("log is NULL\n");
  13135. return FALSE;
  13136. }
  13137. else
  13138. {
  13139. fprintf(fp, "%s\n", url);
  13140. fprintf(fp, "%s\n", filename);
  13141. fclose(fp);
  13142. }
  13143. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  13144. if(phpFP == NULL)
  13145. {
  13146. DEBUG_INFO("PHP upload fail.\n");
  13147. return FALSE;
  13148. }
  13149. else
  13150. {
  13151. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  13152. {
  13153. if(strstr(buf, "result") != NULL)
  13154. {
  13155. sscanf(buf, "result: %d", &systemresult);
  13156. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  13157. }
  13158. }
  13159. pclose(phpFP);
  13160. }
  13161. if(systemresult != 1)
  13162. {
  13163. DEBUG_INFO("HTTP upload error!\n");
  13164. return FALSE;
  13165. }
  13166. return TRUE;
  13167. }
  13168. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  13169. {
  13170. struct hostent* server;
  13171. char *IPbuffer;
  13172. char ftpbuf[200];
  13173. int systemresult;
  13174. // To retrieve host information
  13175. server = gethostbyname(location);
  13176. // To convert an Internet network
  13177. // address into ASCII string
  13178. IPbuffer = inet_ntoa(*((struct in_addr*)
  13179. server->h_addr_list[0]));
  13180. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13181. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  13182. /* format : ftpput -u username -p passwd IP target source*/
  13183. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  13184. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  13185. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13186. systemresult = system(ftpbuf);
  13187. DEBUG_INFO("systemresult=%d\n",systemresult);
  13188. if(systemresult != 0)
  13189. {
  13190. DEBUG_INFO("ftpput error!\n");
  13191. return FALSE;
  13192. }
  13193. return TRUE;
  13194. }
  13195. /**
  13196. * Place the contents of the specified file into a memory buffer
  13197. *
  13198. * @param[in] filename The path and name of the file to read
  13199. * @param[out] filebuffer A pointer to the contents in memory
  13200. * @return status 0 success, 1 on failure
  13201. */
  13202. int get_file_contents(const char* filename, char** outbuffer) {
  13203. FILE* file = NULL;
  13204. long filesize;
  13205. const int blocksize = 1;
  13206. size_t readsize;
  13207. char* filebuffer;
  13208. // Open the file
  13209. file = fopen(filename, "r");
  13210. if (NULL == file)
  13211. {
  13212. printf("'%s' not opened\n", filename);
  13213. exit(EXIT_FAILURE);
  13214. }
  13215. // Determine the file size
  13216. fseek(file, 0, SEEK_END);
  13217. filesize = ftell(file);
  13218. rewind (file);
  13219. // Allocate memory for the file contents
  13220. filebuffer = (char*) malloc(sizeof(char) * filesize);
  13221. *outbuffer = filebuffer;
  13222. if (filebuffer == NULL)
  13223. {
  13224. fputs ("malloc out-of-memory", stderr);
  13225. exit(EXIT_FAILURE);
  13226. }
  13227. // Read in the file
  13228. readsize = fread(filebuffer, blocksize, filesize, file);
  13229. if (readsize != filesize)
  13230. {
  13231. fputs ("didn't read file completely",stderr);
  13232. exit(EXIT_FAILURE);
  13233. }
  13234. // Clean exit
  13235. fclose(file);
  13236. return EXIT_SUCCESS;
  13237. }
  13238. static int selectSqlCount = 0;
  13239. static int callback(void *data, int argc, char **argv, char **azColName){
  13240. int i;
  13241. //printf("%s: ", (const char*)data);
  13242. selectSqlCount = argc;
  13243. for(i = 0; i<argc; i++){
  13244. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  13245. }
  13246. //printf("\n");
  13247. return 0;
  13248. }
  13249. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  13250. //int i;
  13251. //printf("%s:\n", (const char*)data);
  13252. localversion = argv[5] ? atoi(argv[5]) : 0;
  13253. //printf("localversion=%d\n", localversion);
  13254. return 0;
  13255. }
  13256. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  13257. //printf("%s:\n", (const char*)data);
  13258. //idTag
  13259. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  13260. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  13261. //parentIdTag
  13262. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  13263. //expir_date
  13264. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  13265. //status
  13266. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  13267. //version
  13268. if(columenCount > 5)
  13269. idTagQuery.listVersionInt = atoi(columnValue[5]);
  13270. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  13271. return 0;
  13272. }
  13273. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  13274. {
  13275. // localversion = argv[5] ? atoi(argv[5]) : 0;
  13276. // printf("localversion=%d\n", localversion);
  13277. return 0;
  13278. }
  13279. //=========================================
  13280. // Sqlite3 related function
  13281. //=========================================
  13282. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  13283. {
  13284. for (int i = 0; i < n_columns; i++)
  13285. {
  13286. DEBUG_INFO("%s\t", col_values[i]);
  13287. }
  13288. DEBUG_INFO("\n");
  13289. return 0;
  13290. }
  13291. int OCPP_cleanLocalCache()
  13292. {
  13293. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  13294. char *errMsg = 0;
  13295. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  13296. if (SQLITE_OK != rc)
  13297. {
  13298. DEBUG_INFO("SQL error: %s\n",errMsg);
  13299. return FALSE;
  13300. }
  13301. return TRUE;
  13302. }
  13303. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  13304. {
  13305. int isSuccess = TRUE;
  13306. int ret = 0;
  13307. //const char* data = "Callback function called";
  13308. char sql[300];
  13309. char zErrMsg[200];
  13310. memset(sql, 0, 300);
  13311. memset(zErrMsg, 0, 200);
  13312. 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);
  13313. //* Execute SQL statement */
  13314. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  13315. if( ret != SQLITE_OK )
  13316. {
  13317. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13318. isSuccess = FALSE;
  13319. }
  13320. return isSuccess;
  13321. }
  13322. void OCPP_getIdTagFromLocalCache(char idTag[])
  13323. {
  13324. int rc = 0;
  13325. char sql[100];
  13326. char zErrMsg[100];
  13327. memset(sql, 0, 100);
  13328. memset(zErrMsg, 0, 100);
  13329. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  13330. memset(&idTagQuery, 0, sizeof(idTagQuery));
  13331. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  13332. /* Execute SQL statement */
  13333. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  13334. if( rc != SQLITE_OK )
  13335. {
  13336. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13337. }
  13338. }
  13339. void OCPP_getListVerion()
  13340. {
  13341. int rc = 0;
  13342. // const char* data = "Callback function called";
  13343. char sql[100];
  13344. char zErrMsg[100];
  13345. memset(sql, 0, 100);
  13346. memset(zErrMsg, 0, 100);
  13347. strcpy(sql, "select * from ocpp_auth_local order by idx");
  13348. /* Execute SQL statement */
  13349. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  13350. if( rc != SQLITE_OK )
  13351. {
  13352. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13353. }
  13354. }
  13355. void OCPP_get_TableAuthlocalAllData(void)
  13356. {
  13357. int rc = 0;
  13358. char sql[100];
  13359. char zErrMsg[100];
  13360. memset(sql, 0, 100);
  13361. memset(zErrMsg, 0, 100);
  13362. sprintf(sql,"select * from ocpp_auth_local ");
  13363. /* Execute SQL statement */
  13364. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  13365. if( rc != SQLITE_OK )
  13366. {
  13367. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13368. }
  13369. //return ver;
  13370. }
  13371. int OCPP_cleanLocalList()
  13372. {
  13373. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  13374. char *errMsg = 0;
  13375. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  13376. if (SQLITE_OK != rc)
  13377. {
  13378. DEBUG_INFO("%s\n",errMsg);
  13379. return FALSE;
  13380. }
  13381. return TRUE;
  13382. }
  13383. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  13384. {
  13385. int isSuccess = FALSE;
  13386. int ret = 0;
  13387. //const char* data = "Callback function called";
  13388. char sql[300];
  13389. char zErrMsg[200];
  13390. memset(sql, 0, 300);
  13391. memset(zErrMsg, 0, 200);
  13392. 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);
  13393. //* Execute SQL statement */
  13394. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  13395. if( ret != SQLITE_OK )
  13396. {
  13397. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13398. return isSuccess;
  13399. }
  13400. memset(sql, 0, 300);
  13401. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  13402. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  13403. if( ret != SQLITE_OK )
  13404. {
  13405. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13406. return isSuccess;
  13407. }
  13408. isSuccess = TRUE;
  13409. return isSuccess;
  13410. }
  13411. void OCPP_getIdTagFromLocalList(char idTag[])
  13412. {
  13413. int rc = 0;
  13414. // const char* data = "Callback function called";
  13415. char sql[100];
  13416. char zErrMsg[100];
  13417. memset(sql, 0, 100);
  13418. memset(zErrMsg, 0, 100);
  13419. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  13420. memset(&idTagQuery, 0, sizeof(idTagQuery));
  13421. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  13422. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  13423. /* Execute SQL statement */
  13424. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  13425. if( rc != SQLITE_OK )
  13426. {
  13427. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13428. }
  13429. //return ver;
  13430. }
  13431. void OCPP_deleteIdTagFromLocalList(char idTag[])
  13432. {
  13433. //int ver = 0;
  13434. //int isSuccess = FALSE;
  13435. int rc = 0;
  13436. char sql[100];
  13437. char zErrMsg[100];
  13438. memset(sql, 0, 100);
  13439. memset(zErrMsg, 0, 100);
  13440. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  13441. //* Execute SQL statement */
  13442. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  13443. if( rc != SQLITE_OK )
  13444. {
  13445. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13446. }
  13447. }
  13448. int GetOcppServerURL()
  13449. {
  13450. int result = FALSE;
  13451. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  13452. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  13453. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  13454. struct yuarel url;
  13455. char urlStr[512];
  13456. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  13457. {
  13458. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  13459. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13460. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  13461. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  13462. if(yuarel_parse(&url, urlStr) != -1)
  13463. {
  13464. sprintf(OcppProtocol, "%s", url.scheme);
  13465. sprintf(OcppHost, "%s", url.host);
  13466. if(url.path == NULL)
  13467. OcppTempPath[0] = '\0';
  13468. else
  13469. {
  13470. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  13471. {
  13472. sprintf(OcppTempPath, "%s/", url.path);
  13473. }
  13474. else
  13475. {
  13476. sprintf(OcppTempPath, "%s", url.path);
  13477. }
  13478. }
  13479. if(url.port == 0)
  13480. {
  13481. if(strcmp(OcppProtocol, "wss") == 0)
  13482. OcppPort = 443;
  13483. else
  13484. OcppPort = 80;
  13485. }
  13486. else
  13487. OcppPort = url.port;
  13488. result = TRUE;
  13489. }
  13490. }
  13491. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  13492. {
  13493. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  13494. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13495. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  13496. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  13497. if(yuarel_parse(&url, urlStr) != -1)
  13498. {
  13499. sprintf(OcppProtocol, "%s", url.scheme);
  13500. sprintf(OcppHost, "%s", url.host);
  13501. if(url.path == NULL)
  13502. OcppTempPath[0] = '\0';
  13503. else
  13504. sprintf(OcppTempPath, "%s", url.path);
  13505. if(url.port == 0)
  13506. {
  13507. if(strcmp(OcppProtocol, "wss") == 0)
  13508. OcppPort = 443;
  13509. else
  13510. OcppPort = 80;
  13511. }
  13512. else
  13513. OcppPort = url.port;
  13514. result = TRUE;
  13515. }
  13516. }
  13517. else
  13518. {
  13519. strcpy(OcppHost,"");
  13520. }
  13521. return result;
  13522. }
  13523. int GetOcppPath()
  13524. {
  13525. int result = FALSE;
  13526. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  13527. {
  13528. if(OcppTempPath == NULL)
  13529. {
  13530. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13531. }
  13532. else
  13533. {
  13534. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13535. }
  13536. result = TRUE;
  13537. goto End;
  13538. }
  13539. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  13540. {
  13541. if(OcppTempPath == NULL)
  13542. {
  13543. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  13544. }
  13545. else
  13546. {
  13547. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  13548. }
  13549. result = TRUE;
  13550. goto End;
  13551. }
  13552. else
  13553. {
  13554. strcpy(OcppPath,"");
  13555. }
  13556. End:
  13557. return result;
  13558. }
  13559. int GetOcppPort()
  13560. {
  13561. return OcppPort;
  13562. }
  13563. int GetOcppConnStatus(void)
  13564. {
  13565. return ShmOCPP16Data->OcppConnStatus;
  13566. }
  13567. void SetOcppConnStatus(uint8_t status)
  13568. {
  13569. ShmOCPP16Data->OcppConnStatus = status;
  13570. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  13571. }
  13572. int GetHeartBeatWithNOResponse(void)
  13573. {
  13574. return HeartBeatWithNOResponse;
  13575. }
  13576. void SetHeartBeatWithNOResponse(void)
  13577. {
  13578. HeartBeatWithNOResponse = 0;
  13579. }
  13580. void GetStartTransactionIdTag(int gun_index)
  13581. {
  13582. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  13583. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13584. }
  13585. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  13586. {
  13587. char ch;
  13588. FILE *fptr1;
  13589. int temptransactionId;
  13590. char str[100]={0};
  13591. temptransactionId = 0;
  13592. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  13593. {
  13594. DEBUG_INFO("IdTag is empty.\n");
  13595. return temptransactionId;
  13596. }
  13597. /*------ Read the file ----------------*/
  13598. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  13599. if (!fptr1)
  13600. {
  13601. DEBUG_INFO("QueueTransactionId file open error.\n");
  13602. //printf(" File not found or unable to open the input file!!\n");
  13603. return temptransactionId;
  13604. }
  13605. ch=fgetc(fptr1);
  13606. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13607. rewind(fptr1);
  13608. if(ch!=EOF)
  13609. {
  13610. // printf("%c",ch);
  13611. while (fgets(str, 100, fptr1) != NULL)
  13612. {
  13613. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13614. if(str[0]=='\0')
  13615. {
  13616. break;
  13617. }
  13618. char *revbuf[8] = {0}; // Variable store string split
  13619. int num = 0;// Quantity after string split
  13620. DEBUG_INFO("Transaction queue data= %s\n", str);
  13621. splitstring(str,",",revbuf,&num); // String split
  13622. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  13623. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  13624. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  13625. DEBUG_INFO("------------------------------\n");
  13626. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13627. {
  13628. if(isStopTransaction)
  13629. {
  13630. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  13631. {
  13632. temptransactionId = atoi(revbuf[2]);
  13633. //break;
  13634. }
  13635. }
  13636. else
  13637. {
  13638. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13639. {
  13640. temptransactionId = atoi(revbuf[2]);
  13641. //break;
  13642. }
  13643. }
  13644. }
  13645. }
  13646. }
  13647. else
  13648. DEBUG_INFO("EOF\n");
  13649. fclose(fptr1);
  13650. /*------- End of reading ---------------*/
  13651. return temptransactionId;
  13652. }
  13653. void SetTransactionIdZero(int transactionId)
  13654. {
  13655. char ch;
  13656. FILE *fptr1, *fptr2;
  13657. int temptransactionId = 0;
  13658. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13659. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13660. if (!fptr1)
  13661. {
  13662. //printf(" File not found or unable to open the input file!!\n");
  13663. return ;
  13664. }
  13665. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13666. if (!fptr2)
  13667. {
  13668. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  13669. fclose(fptr1);
  13670. return ;
  13671. }
  13672. ch=fgetc(fptr1);
  13673. rewind(fptr1);
  13674. if(ch!=EOF)
  13675. {
  13676. // copy all contents to the temporary file except the specific line
  13677. while (fgets(str, 100, fptr1) != NULL)
  13678. {
  13679. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13680. if(str[0]=='\0')
  13681. {
  13682. break;
  13683. }
  13684. char *revbuf[8] = {0};
  13685. int num = 0;
  13686. strcpy(strtemp, str);
  13687. splitstring(str,",",revbuf,&num);
  13688. if(revbuf[2][0] != '\0')
  13689. {
  13690. temptransactionId = atoi(revbuf[2]);
  13691. if(transactionId != temptransactionId)
  13692. {
  13693. fprintf(fptr2, "%s\n", strtemp);
  13694. }
  13695. }
  13696. }
  13697. }
  13698. fclose(fptr1);
  13699. fclose(fptr2);
  13700. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13701. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13702. /*------ Read the file ----------------*/
  13703. }
  13704. int InternetDisconnect(void)
  13705. {
  13706. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13707. }
  13708. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  13709. void storeTempStopTransaction(int gun_index)
  13710. {
  13711. char guid[37]={0};
  13712. int tempIndex = 0;
  13713. char TempStopTransaction[256];
  13714. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  13715. DEBUG_INFO("storeTempStopTransaction...\n");
  13716. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  13717. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  13718. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  13719. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13720. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  13721. {
  13722. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13723. {
  13724. tempIndex = ((gun_index==2) ? 1: 0);
  13725. }
  13726. else
  13727. {
  13728. tempIndex = gun_index;
  13729. }
  13730. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13731. {
  13732. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13733. {
  13734. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  13735. }
  13736. }// END OF CHAdeMO_QUANTITY
  13737. }
  13738. else if(gunType[gun_index] == GUN_TYPE_CCS)
  13739. {
  13740. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13741. {
  13742. tempIndex = ((gun_index==2) ? 1: 0);
  13743. }
  13744. else
  13745. {
  13746. tempIndex = gun_index;
  13747. }
  13748. for (int index = 0; index < CCS_QUANTITY; index++)
  13749. {
  13750. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13751. {
  13752. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  13753. }
  13754. }// END OF CCS_QUANTITY
  13755. }
  13756. else if(gunType[gun_index] == GUN_TYPE_GBT)
  13757. {
  13758. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13759. {
  13760. tempIndex = ((gun_index==2) ? 1: 0);
  13761. }
  13762. else
  13763. {
  13764. tempIndex = gun_index;
  13765. }
  13766. for (int index = 0; index < GB_QUANTITY; index++)
  13767. {
  13768. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13769. {
  13770. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  13771. }
  13772. }// END OF GB_QUANTITY
  13773. }
  13774. else if(gunType[gun_index] == GUN_TYPE_DO)
  13775. {
  13776. tempIndex = gun_index;
  13777. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13778. {
  13779. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13780. {
  13781. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  13782. }
  13783. }
  13784. }
  13785. else
  13786. {
  13787. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13788. {
  13789. tempIndex = 2;
  13790. }
  13791. else
  13792. {
  13793. tempIndex = gun_index;
  13794. }
  13795. for (int index = 0; index < AC_QUANTITY; index++)
  13796. {
  13797. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13798. {
  13799. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  13800. }
  13801. }// END OF AC_QUANTITY
  13802. }
  13803. //Stop Transaction Time
  13804. struct timeval tmnow;
  13805. struct tm *tm;
  13806. char buf[28];//, usec_buf[6];
  13807. gettimeofday(&tmnow, NULL);
  13808. time_t t;
  13809. t = time(NULL);
  13810. /*UTC time and date*/
  13811. tm = gmtime(&t);
  13812. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  13813. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  13814. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  13815. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13816. random_uuid(guid);
  13817. /***********************************transactionData******************************************************/
  13818. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  13819. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  13820. //=================================
  13821. //1. Transaction_Begin
  13822. //=================================
  13823. //============================== Energy.Active.Import.Interval ===========================================
  13824. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  13825. {
  13826. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  13827. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  13828. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  13829. 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*/]);
  13830. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13831. 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))
  13832. {
  13833. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  13834. }
  13835. else
  13836. {
  13837. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  13838. }
  13839. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  13840. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13841. }
  13842. //=================================
  13843. //2. Transaction_End
  13844. //=================================
  13845. //2.1====================================== Current.Import L1 ==============================================
  13846. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  13847. {
  13848. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  13849. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  13850. {
  13851. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13852. {
  13853. tempIndex = ((gun_index==2) ? 1: 0);
  13854. }
  13855. else
  13856. {
  13857. tempIndex = gun_index;
  13858. }
  13859. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13860. {
  13861. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13862. {
  13863. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13864. }
  13865. }// End of for CHAdeMO_QUANTITY
  13866. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13867. }
  13868. else if(gunType[gun_index] == GUN_TYPE_CCS)
  13869. {
  13870. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13871. {
  13872. tempIndex = ((gun_index==2) ? 1: 0);
  13873. }
  13874. else
  13875. {
  13876. tempIndex = gun_index;
  13877. }
  13878. for (int index = 0; index < CCS_QUANTITY; index++)
  13879. {
  13880. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13881. {
  13882. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13883. }
  13884. }// End of for CCS_QUANTITY
  13885. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13886. }
  13887. else if(gunType[gun_index] == GUN_TYPE_GBT)
  13888. {
  13889. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13890. {
  13891. tempIndex = ((gun_index==2) ? 1: 0);
  13892. }
  13893. else
  13894. {
  13895. tempIndex = gun_index;
  13896. }
  13897. for (int index = 0; index < GB_QUANTITY; index++)
  13898. {
  13899. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13900. {
  13901. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13902. }
  13903. }// End of for GB_QUANTITY
  13904. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13905. }
  13906. else if(gunType[gun_index] == GUN_TYPE_DO)
  13907. {
  13908. tempIndex = gun_index;
  13909. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13910. {
  13911. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13912. {
  13913. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13914. }
  13915. }
  13916. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13917. }
  13918. else
  13919. {
  13920. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13921. {
  13922. tempIndex = 2;
  13923. }
  13924. else
  13925. {
  13926. tempIndex = gun_index;
  13927. }
  13928. for (int index = 0; index < AC_QUANTITY; index++)
  13929. {
  13930. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13931. {
  13932. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  13933. }
  13934. }// End of for AC_QUANTITY
  13935. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13936. }
  13937. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13938. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  13939. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  13940. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13941. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  13942. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13943. }
  13944. //2.2===================================== Energy.Active.Import.Interval ==========================================
  13945. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  13946. {
  13947. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13948. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  13949. {
  13950. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13951. {
  13952. tempIndex = ((gun_index==2) ? 1: 0);
  13953. }
  13954. else
  13955. {
  13956. tempIndex = gun_index;
  13957. }
  13958. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13959. {
  13960. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13961. {
  13962. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13963. }
  13964. }// END OF CHAdeMO_QUANTITY
  13965. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13966. }
  13967. else if(gunType[gun_index] == GUN_TYPE_CCS)
  13968. {
  13969. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13970. {
  13971. tempIndex = ((gun_index==2) ? 1: 0);
  13972. }
  13973. else
  13974. {
  13975. tempIndex = gun_index;
  13976. }
  13977. for (int index = 0; index < CCS_QUANTITY; index++)
  13978. {
  13979. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13980. {
  13981. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13982. }
  13983. }// END OF CCS_QUANTITY
  13984. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13985. }
  13986. else if(gunType[gun_index] == GUN_TYPE_GBT)
  13987. {
  13988. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13989. {
  13990. tempIndex = ((gun_index==2) ? 1: 0);
  13991. }
  13992. else
  13993. {
  13994. tempIndex = gun_index;
  13995. }
  13996. for (int index = 0; index < GB_QUANTITY; index++)
  13997. {
  13998. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13999. {
  14000. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14001. }
  14002. }// END OF GB_QUANTITY
  14003. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14004. }
  14005. else if(gunType[gun_index] == GUN_TYPE_DO)
  14006. {
  14007. tempIndex = gun_index;
  14008. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14009. {
  14010. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14011. {
  14012. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14013. }
  14014. }
  14015. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14016. }
  14017. else
  14018. {
  14019. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14020. {
  14021. tempIndex = 2;
  14022. }
  14023. else
  14024. {
  14025. tempIndex = gun_index;
  14026. }
  14027. for (int index = 0; index < AC_QUANTITY; index++)
  14028. {
  14029. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14030. {
  14031. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14032. }
  14033. }// END OF AC_QUANTITY
  14034. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14035. }
  14036. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14037. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  14038. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  14039. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14040. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  14041. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14042. }
  14043. //2.3====================================== Power.Active.Import =========================================
  14044. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  14045. {
  14046. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14047. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14048. {
  14049. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14050. {
  14051. tempIndex = ((gun_index==2) ? 1: 0);
  14052. }
  14053. else
  14054. {
  14055. tempIndex = gun_index;
  14056. }
  14057. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14058. {
  14059. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14060. {
  14061. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14062. }
  14063. } // End for CHAdeMO_QUANTITY
  14064. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14065. }
  14066. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14067. {
  14068. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14069. {
  14070. tempIndex = ((gun_index==2) ? 1: 0);
  14071. }
  14072. else
  14073. {
  14074. tempIndex = gun_index;
  14075. }
  14076. for (int index = 0; index < CCS_QUANTITY; index++)
  14077. {
  14078. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14079. {
  14080. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14081. }
  14082. } // END for CCS_QUANTITY
  14083. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14084. }
  14085. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14086. {
  14087. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14088. {
  14089. tempIndex = ((gun_index==2) ? 1: 0);
  14090. }
  14091. else
  14092. {
  14093. tempIndex = gun_index;
  14094. }
  14095. for (int index = 0; index < GB_QUANTITY; index++)
  14096. {
  14097. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14098. {
  14099. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14100. }
  14101. }// END for GB_QUANTITY
  14102. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14103. }
  14104. else if(gunType[gun_index] == GUN_TYPE_DO)
  14105. {
  14106. tempIndex = gun_index;
  14107. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14108. {
  14109. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14110. {
  14111. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14112. }
  14113. }
  14114. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14115. }
  14116. else
  14117. {
  14118. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14119. {
  14120. tempIndex = 2;
  14121. }
  14122. else
  14123. {
  14124. tempIndex = gun_index;
  14125. }
  14126. for (int index = 0; index < AC_QUANTITY; index++)
  14127. {
  14128. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14129. {
  14130. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14131. }
  14132. } // END for AC_QUANTITY
  14133. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14134. }
  14135. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14136. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  14137. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  14138. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14139. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  14140. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  14141. }
  14142. //2.4====================================== Voltage L1 ====================================================
  14143. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  14144. {
  14145. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14146. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14147. {
  14148. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14149. {
  14150. tempIndex = ((gun_index==2) ? 1: 0);
  14151. }
  14152. else
  14153. {
  14154. tempIndex = gun_index;
  14155. }
  14156. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14157. {
  14158. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14159. {
  14160. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14161. }
  14162. } // END OF FOR CHAdeMO_QUANTITY
  14163. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14164. }
  14165. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14166. {
  14167. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14168. {
  14169. tempIndex = ((gun_index==2) ? 1: 0);
  14170. }
  14171. else
  14172. {
  14173. tempIndex = gun_index;
  14174. }
  14175. for (int index = 0; index < CCS_QUANTITY; index++)
  14176. {
  14177. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14178. {
  14179. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14180. }
  14181. } // END OF FOR CCS_QUANTITY
  14182. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14183. }
  14184. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14185. {
  14186. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14187. {
  14188. tempIndex = ((gun_index==2) ? 1: 0);
  14189. }
  14190. else
  14191. {
  14192. tempIndex = gun_index;
  14193. }
  14194. for (int index = 0; index < GB_QUANTITY; index++)
  14195. {
  14196. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14197. {
  14198. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14199. }
  14200. } // END OF FOR GB_QUANTITY
  14201. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14202. }
  14203. else if(gunType[gun_index] == GUN_TYPE_DO)
  14204. {
  14205. tempIndex = gun_index;
  14206. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14207. {
  14208. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14209. {
  14210. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14211. }
  14212. }
  14213. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14214. }
  14215. else
  14216. {
  14217. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14218. {
  14219. tempIndex = 2;
  14220. }
  14221. else
  14222. {
  14223. tempIndex = gun_index;
  14224. }
  14225. for (int index = 0; index < AC_QUANTITY; index++)
  14226. {
  14227. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14228. {
  14229. 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
  14230. }
  14231. } // END OF FOR AC_QUANTITY
  14232. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  14233. }
  14234. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14235. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  14236. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  14237. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  14238. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  14239. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14240. }
  14241. //2.5============================================== End SoC =========================================================
  14242. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  14243. {
  14244. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14245. 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))
  14246. {
  14247. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  14248. {
  14249. tempIndex = ((gun_index==2) ? 1: 0);
  14250. }
  14251. else
  14252. {
  14253. tempIndex = gun_index;
  14254. }
  14255. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14256. {
  14257. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14258. {
  14259. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14260. {
  14261. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  14262. }
  14263. }
  14264. }
  14265. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14266. {
  14267. for (int index = 0; index < CCS_QUANTITY; index++)
  14268. {
  14269. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14270. {
  14271. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  14272. }
  14273. }
  14274. }
  14275. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14276. {
  14277. for (int index = 0; index < GB_QUANTITY; index++)
  14278. {
  14279. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14280. {
  14281. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  14282. }
  14283. }
  14284. }
  14285. else if(gunType[gun_index] == GUN_TYPE_DO)
  14286. {
  14287. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14288. {
  14289. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14290. {
  14291. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  14292. }
  14293. }
  14294. }
  14295. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14296. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  14297. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  14298. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  14299. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  14300. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  14301. } // END FOR DC CASE
  14302. }
  14303. //2.6====================================== Current.Import L2 ==============================================
  14304. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  14305. {
  14306. // AC 3 phase L2 current
  14307. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14308. {
  14309. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14310. {
  14311. tempIndex = 2;
  14312. }
  14313. else
  14314. {
  14315. tempIndex = gun_index;
  14316. }
  14317. for (int index = 0; index < AC_QUANTITY; index++)
  14318. {
  14319. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14320. {
  14321. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  14322. }
  14323. }// End of for AC_QUANTITY
  14324. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  14325. }
  14326. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14327. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  14328. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  14329. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  14330. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14331. }
  14332. //2.7====================================== Current.Import L3 ==============================================
  14333. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  14334. {
  14335. // AC 3 phase L3 current
  14336. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14337. {
  14338. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14339. {
  14340. tempIndex = 2;
  14341. }
  14342. else
  14343. {
  14344. tempIndex = gun_index;
  14345. }
  14346. for (int index = 0; index < AC_QUANTITY; index++)
  14347. {
  14348. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14349. {
  14350. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  14351. }
  14352. }// End of for AC_QUANTITY
  14353. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  14354. }
  14355. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14356. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  14357. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  14358. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  14359. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14360. }
  14361. //2.9====================================== Voltage L2 ====================================================
  14362. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  14363. {
  14364. // AC 3 phase L2 volatge
  14365. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14366. {
  14367. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14368. {
  14369. tempIndex = 2;
  14370. }
  14371. else
  14372. {
  14373. tempIndex = gun_index;
  14374. }
  14375. for (int index = 0; index < AC_QUANTITY; index++)
  14376. {
  14377. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14378. {
  14379. 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
  14380. }
  14381. } // END OF FOR AC_QUANTITY
  14382. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  14383. }
  14384. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14385. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  14386. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  14387. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  14388. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14389. }
  14390. //2.10====================================== Voltage L3 ====================================================
  14391. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  14392. {
  14393. // AC 3 phase L3 volatge
  14394. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14395. {
  14396. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14397. {
  14398. tempIndex = 2;
  14399. }
  14400. else
  14401. {
  14402. tempIndex = gun_index;
  14403. }
  14404. for (int index = 0; index < AC_QUANTITY; index++)
  14405. {
  14406. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14407. {
  14408. 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
  14409. }
  14410. } // END OF FOR AC_QUANTITY
  14411. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  14412. }
  14413. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14414. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  14415. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  14416. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  14417. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14418. }
  14419. //====================== Start SoC ================================
  14420. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  14421. {
  14422. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14423. 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))
  14424. {
  14425. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  14426. {
  14427. tempIndex = ((gun_index==2) ? 1: 0);
  14428. }
  14429. else
  14430. {
  14431. tempIndex = gun_index;
  14432. }
  14433. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14434. {
  14435. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14436. {
  14437. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14438. {
  14439. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  14440. }
  14441. }
  14442. }
  14443. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14444. {
  14445. for (int index = 0; index < CCS_QUANTITY; index++)
  14446. {
  14447. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14448. {
  14449. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  14450. }
  14451. }
  14452. }
  14453. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14454. {
  14455. for (int index = 0; index < GB_QUANTITY; index++)
  14456. {
  14457. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14458. {
  14459. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  14460. }
  14461. }
  14462. }
  14463. else if(gunType[gun_index] == GUN_TYPE_DO)
  14464. {
  14465. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14466. {
  14467. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14468. {
  14469. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  14470. }
  14471. }
  14472. }
  14473. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  14474. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  14475. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  14476. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  14477. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  14478. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  14479. } // END FOR DC CASE
  14480. }
  14481. //======================================== Message create ==============================================
  14482. json_object *StopTransaction = json_object_new_object();
  14483. json_object *transactionDatas = json_object_new_array();
  14484. json_object *sampledValues = json_object_new_array();
  14485. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  14486. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  14487. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  14488. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  14489. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  14490. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  14491. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  14492. {
  14493. json_object *transactionData = json_object_new_object();
  14494. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  14495. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  14496. {
  14497. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  14498. {
  14499. json_object *sampledValue = json_object_new_object();
  14500. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  14501. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  14502. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  14503. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  14504. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  14505. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  14506. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  14507. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  14508. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  14509. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  14510. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  14511. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  14512. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  14513. json_object_array_add(sampledValues, sampledValue);
  14514. }
  14515. }
  14516. json_object_object_add(transactionData, "sampledValue", sampledValues);
  14517. json_object_array_add(transactionDatas, transactionData);
  14518. }
  14519. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  14520. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  14521. ,MESSAGE_TYPE_CALL
  14522. ,guid
  14523. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  14524. json_object_put(StopTransaction);
  14525. // Check File "TempStopTransaction" Exist
  14526. if((access(TempStopTransaction,F_OK))!=-1)
  14527. {
  14528. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  14529. fclose(fopen(TempStopTransaction, "w"));
  14530. }
  14531. else
  14532. {
  14533. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  14534. FILE *log = fopen(TempStopTransaction, "w+");
  14535. if(log == NULL)
  14536. {
  14537. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  14538. return ;
  14539. }
  14540. else
  14541. {
  14542. fclose(log);
  14543. }
  14544. }
  14545. //Add TempStopTransaction | Update TempStopTransaction
  14546. // open file for writing
  14547. FILE *outfile;
  14548. outfile = fopen (TempStopTransaction, "a");
  14549. //DEBUG_INFO("data = %s\n", queuedata);
  14550. fputs(queuedata, outfile);
  14551. fputs("\n", outfile);
  14552. fclose (outfile);
  14553. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14554. }
  14555. void checkTempStopTransaction(int gun_index)
  14556. {
  14557. FILE *fptr1;
  14558. char ch;
  14559. char str[QUEUE_MESSAGE_LENGTH]={0};
  14560. char guid[37]={0};
  14561. char tempdata[65]={0};
  14562. char connectorStr[2]={0};
  14563. char TempStopTransaction[256];
  14564. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  14565. fptr1 = fopen(TempStopTransaction, "r");
  14566. //TempStopTransaction格式: 槍號,StopTransaction封包
  14567. if (!fptr1)
  14568. {
  14569. //printf(" File not found or unable to open the input file!!\n");
  14570. return ;
  14571. }
  14572. ch=fgetc(fptr1);
  14573. //printf(" Now the content of the file %s is : \n",fname);
  14574. rewind(fptr1);
  14575. if(ch!=EOF)
  14576. {
  14577. // copy all contents to the temporary file except the specific line
  14578. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  14579. {
  14580. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14581. if(str[0]=='\0')
  14582. {
  14583. break;
  14584. }
  14585. //TempStopTransaction格式: 槍號,StopTransaction封包
  14586. strncpy(connectorStr, str, 1);
  14587. if(atoi(connectorStr) != (gun_index+1))
  14588. {
  14589. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  14590. fclose(fptr1);
  14591. return ;
  14592. }
  14593. //random_uuid(guid);
  14594. strncpy(guid, str+6, 36); //copy guid
  14595. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  14596. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  14597. {
  14598. //DEBUG_INFO("StopTransaction mapitem pass\n");
  14599. }
  14600. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  14601. memset(str,0,ARRAY_SIZE(str));
  14602. }
  14603. }
  14604. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  14605. fclose(fptr1);
  14606. remove(TempStopTransaction); // remove the original file
  14607. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14608. }
  14609. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  14610. {
  14611. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  14612. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  14613. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  14614. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  14615. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14616. }
  14617. int GetWebSocketPingInterval(void)
  14618. {
  14619. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14620. }
  14621. int GetServerSign(void)
  14622. {
  14623. return server_sign;
  14624. }
  14625. uint8_t GetOcppSecurityProfile()
  14626. {
  14627. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14628. }
  14629. void GetOcppChargerBoxId(uint8_t *data)
  14630. {
  14631. sprintf((char*)data, "%s", ShmOCPP16Data->ChargeBoxId);
  14632. }
  14633. void GetOcppSecurityPassword(uint8_t *data)
  14634. {
  14635. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14636. }
  14637. void SetOcppVersion(uint8_t *version)
  14638. {
  14639. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  14640. DEBUG_INFO("ocpp version: %s\n", version);
  14641. if(strstr((char*)version, "ocpp1.6") != NULL)
  14642. {
  14643. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  14644. }
  14645. else if(strstr((char*)version, "ocpp2.0") != NULL)
  14646. {
  14647. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  14648. system("pkill OcppBackend");
  14649. }
  14650. }
  14651. void SetServerSign(int value)
  14652. {
  14653. server_sign = value;
  14654. }
  14655. int GetBootNotificationInterval(void)
  14656. {
  14657. return BootNotificationInterval;
  14658. }
  14659. int GetInternetConn(void)
  14660. {
  14661. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  14662. }
  14663. int isConnectorInitMode(int gun_index)
  14664. {
  14665. int tempIndex = 0;
  14666. int result = TRUE;
  14667. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14668. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14669. {
  14670. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14671. {
  14672. tempIndex = ((gun_index==2) ? 1: 0);
  14673. }
  14674. else
  14675. {
  14676. tempIndex = gun_index;
  14677. }
  14678. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14679. {
  14680. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  14681. {
  14682. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  14683. } //end of the same index
  14684. }//end of for CHAdeMO_QUANTITY
  14685. }
  14686. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14687. {
  14688. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14689. {
  14690. tempIndex = ((gun_index==2) ? 1: 0);
  14691. }
  14692. else
  14693. {
  14694. tempIndex = gun_index;
  14695. }
  14696. for (int index = 0; index < CCS_QUANTITY; index++)
  14697. {
  14698. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14699. {
  14700. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  14701. } //end of the same index
  14702. } // end of for CCS_QUANTITY
  14703. }
  14704. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14705. {
  14706. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14707. {
  14708. tempIndex = ((gun_index==2) ? 1: 0);
  14709. }
  14710. else
  14711. {
  14712. tempIndex = gun_index;
  14713. }
  14714. for (int index = 0; index < GB_QUANTITY; index++)
  14715. {
  14716. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14717. {
  14718. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  14719. } //end of the same index
  14720. } // end of for GB_QUANTITY
  14721. }
  14722. else if(gunType[gun_index] == GUN_TYPE_DO)
  14723. {
  14724. tempIndex = gun_index;
  14725. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14726. {
  14727. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14728. {
  14729. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  14730. } //end of the same index
  14731. }
  14732. }
  14733. else
  14734. {
  14735. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14736. {
  14737. tempIndex = 2;
  14738. }
  14739. else
  14740. {
  14741. tempIndex = gun_index;
  14742. }
  14743. for (int index = 0; index < AC_QUANTITY; index++)
  14744. {
  14745. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14746. {
  14747. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  14748. }//end of the same index
  14749. }//end of for AC_QUANTITY
  14750. }
  14751. return result;
  14752. }
  14753. void refreshProcDogTimer()
  14754. {
  14755. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  14756. }
  14757. void InitialSystemValue(void)
  14758. {
  14759. int connectorIndex = 0;
  14760. //int valueASCII = 0;
  14761. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14762. gunTotalNumber=0;
  14763. SystemInitial = 0;
  14764. localversion=0;
  14765. BootNotificationInterval = 0;
  14766. authorizeRetryTimes = 0;
  14767. GunStatusInterval = 10;
  14768. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14769. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14770. //Hear Beat
  14771. HeartBeatWithNOResponse = 0;
  14772. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  14773. FirstHeartBeat = 0;
  14774. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  14775. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  14776. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  14777. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  14778. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  14779. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  14780. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  14781. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  14782. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  14783. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  14784. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  14785. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  14786. memset(gunType, 0, ARRAY_SIZE(gunType));
  14787. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14788. {
  14789. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O')
  14790. {
  14791. // DO series
  14792. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  14793. {
  14794. SystemInitial = SystemInitial + 1;
  14795. gunTotalNumber = gunTotalNumber + 1;
  14796. gunType[connectorIndex] = GUN_TYPE_DO;
  14797. connectorIndex = connectorIndex + 1;
  14798. }
  14799. }
  14800. else
  14801. {
  14802. // DM, DW, DS series
  14803. //check connector / socket type (index: 8, 9, 10)
  14804. for(int index=7; index <10 ; index++)
  14805. {
  14806. if(index != 8)
  14807. {
  14808. // DC Connector
  14809. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  14810. {
  14811. SystemInitial = SystemInitial + 1;
  14812. gunTotalNumber = gunTotalNumber + 1;
  14813. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  14814. connectorIndex = connectorIndex + 1;
  14815. }
  14816. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  14817. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  14818. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  14819. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  14820. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  14821. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  14822. {
  14823. SystemInitial = SystemInitial + 1;
  14824. gunTotalNumber = gunTotalNumber + 1;
  14825. gunType[connectorIndex] = GUN_TYPE_CCS;
  14826. connectorIndex = connectorIndex + 1;
  14827. }
  14828. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  14829. {
  14830. SystemInitial = SystemInitial + 1;
  14831. gunTotalNumber = gunTotalNumber + 1;
  14832. gunType[connectorIndex] = GUN_TYPE_GBT;
  14833. connectorIndex = connectorIndex + 1;
  14834. }
  14835. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  14836. {
  14837. SystemInitial = SystemInitial + 1;
  14838. gunTotalNumber = gunTotalNumber + 1;
  14839. gunType[connectorIndex] = GUN_TYPE_DO;
  14840. connectorIndex = connectorIndex + 1;
  14841. }
  14842. }
  14843. else
  14844. {
  14845. // AC Connector
  14846. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14847. {
  14848. SystemInitial = SystemInitial + 1;
  14849. gunTotalNumber = gunTotalNumber + 1;
  14850. gunType[connectorIndex] = GUN_TYPE_AC;
  14851. connectorIndex = connectorIndex + 1;
  14852. }
  14853. }
  14854. }
  14855. }
  14856. //DEBUG_INFO("DC ...\n");
  14857. }
  14858. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  14859. {
  14860. //check connector / socket type (index: 8, 9, 10)
  14861. for(int index=7; index <10 ; index++)
  14862. {
  14863. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14864. {
  14865. SystemInitial = SystemInitial + 1;
  14866. gunTotalNumber = gunTotalNumber + 1;
  14867. gunType[connectorIndex] = GUN_TYPE_AC;
  14868. connectorIndex = connectorIndex + 1;
  14869. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  14870. }
  14871. }
  14872. }
  14873. //Status && ConnectorPlugIn Setting
  14874. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14875. {
  14876. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  14877. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  14878. }
  14879. for (int index = 0; index < CCS_QUANTITY; index++)
  14880. {
  14881. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  14882. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  14883. }
  14884. for (int index = 0; index < GB_QUANTITY; index++)
  14885. {
  14886. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  14887. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  14888. }
  14889. for (int index = 0; index < AC_QUANTITY; index++)
  14890. {
  14891. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  14892. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  14893. }
  14894. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14895. {
  14896. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  14897. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  14898. }
  14899. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  14900. {
  14901. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14902. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  14903. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  14904. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  14905. }
  14906. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  14907. clientTime.Heartbeat=time((time_t*)NULL);
  14908. sleep(1);
  14909. }
  14910. void LWS_Send(char * str)
  14911. {
  14912. //=====================================================
  14913. // Check InternetConn 0: disconnected, 1: connected
  14914. //====================================================
  14915. if(GetOcppConnStatus() == 0)
  14916. {
  14917. DEBUG_INFO("offline now !!!\n");
  14918. return;
  14919. }
  14920. pthread_mutex_lock(&lock_send);
  14921. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14922. sprintf((char *)SendBuffer, "%s", str);
  14923. SendBufLen = strlen(str);
  14924. pthread_mutex_unlock(&lock_send);
  14925. lws_callback_on_writable(wsi_client);
  14926. //lws_service(context, 0);
  14927. //sleep(1);
  14928. }
  14929. void LWS_SendNow(char * str)
  14930. {
  14931. //=====================================================
  14932. // Check InternetConn 0: disconnected, 1: connected
  14933. //====================================================
  14934. if(GetOcppConnStatus() == 0)
  14935. {
  14936. DEBUG_INFO("offline now !!!\n");
  14937. return;
  14938. }
  14939. pthread_mutex_lock(&lock_send);
  14940. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14941. sprintf((char *)SendBuffer, "%s", str);
  14942. SendBufLen = strlen(str);
  14943. pthread_mutex_unlock(&lock_send);
  14944. lws_callback_on_writable(wsi_client);
  14945. lws_service(context, 0);
  14946. //sleep(1);
  14947. }