MessageHandler.c 762 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941
  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[21];
  75. char parentIdTag[21];
  76. char expiryDate[36];
  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. // Sqlite3 related function
  355. //=========================================
  356. static int selectSqlCount = 0;
  357. static int callback(void *data, int argc, char **argv, char **azColName){
  358. int i;
  359. //printf("%s: ", (const char*)data);
  360. selectSqlCount = argc;
  361. for(i = 0; i<argc; i++){
  362. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  363. }
  364. //printf("\n");
  365. return 0;
  366. }
  367. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  368. //int i;
  369. //printf("%s:\n", (const char*)data);
  370. localversion = argv[5] ? atoi(argv[5]) : 0;
  371. //printf("localversion=%d\n", localversion);
  372. return 0;
  373. }
  374. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  375. //printf("%s:\n", (const char*)data);
  376. //idTag
  377. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  378. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  379. //parentIdTag
  380. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  381. //expir_date
  382. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  383. //status
  384. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  385. //version
  386. if(columenCount > 5)
  387. idTagQuery.listVersionInt = atoi(columnValue[5]);
  388. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  389. return 0;
  390. }
  391. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  392. {
  393. // localversion = argv[5] ? atoi(argv[5]) : 0;
  394. // printf("localversion=%d\n", localversion);
  395. return 0;
  396. }
  397. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  398. {
  399. for (int i = 0; i < n_columns; i++)
  400. {
  401. DEBUG_INFO("%s\t", col_values[i]);
  402. }
  403. DEBUG_INFO("\n");
  404. return 0;
  405. }
  406. int OCPP_cleanLocalCache()
  407. {
  408. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  409. char *errMsg = 0;
  410. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  411. if (SQLITE_OK != rc)
  412. {
  413. DEBUG_INFO("SQL error: %s\n",errMsg);
  414. return FALSE;
  415. }
  416. return TRUE;
  417. }
  418. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  419. {
  420. int isSuccess = TRUE;
  421. int ret = 0;
  422. //const char* data = "Callback function called";
  423. char sql[300];
  424. char zErrMsg[200];
  425. memset(sql, 0, 300);
  426. memset(zErrMsg, 0, 200);
  427. 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);
  428. //* Execute SQL statement */
  429. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  430. if( ret != SQLITE_OK )
  431. {
  432. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  433. isSuccess = FALSE;
  434. }
  435. return isSuccess;
  436. }
  437. void OCPP_getIdTagFromLocalCache(char idTag[])
  438. {
  439. int rc = 0;
  440. char sql[100];
  441. char zErrMsg[100];
  442. memset(sql, 0, 100);
  443. memset(zErrMsg, 0, 100);
  444. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  445. memset(&idTagQuery, 0, sizeof(idTagQuery));
  446. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  447. /* Execute SQL statement */
  448. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  449. if( rc != SQLITE_OK )
  450. {
  451. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  452. }
  453. }
  454. void OCPP_getListVerion()
  455. {
  456. int rc = 0;
  457. // const char* data = "Callback function called";
  458. char sql[100];
  459. char zErrMsg[100];
  460. memset(sql, 0, 100);
  461. memset(zErrMsg, 0, 100);
  462. strcpy(sql, "select * from ocpp_auth_local order by idx");
  463. /* Execute SQL statement */
  464. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  465. if( rc != SQLITE_OK )
  466. {
  467. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  468. }
  469. }
  470. void OCPP_get_TableAuthlocalAllData(void)
  471. {
  472. int rc = 0;
  473. char sql[100];
  474. char zErrMsg[100];
  475. memset(sql, 0, 100);
  476. memset(zErrMsg, 0, 100);
  477. sprintf(sql,"select * from ocpp_auth_local ");
  478. /* Execute SQL statement */
  479. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  480. if( rc != SQLITE_OK )
  481. {
  482. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  483. }
  484. //return ver;
  485. }
  486. int OCPP_cleanLocalList()
  487. {
  488. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  489. char *errMsg = 0;
  490. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  491. if (SQLITE_OK != rc)
  492. {
  493. DEBUG_INFO("%s\n",errMsg);
  494. return FALSE;
  495. }
  496. return TRUE;
  497. }
  498. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  499. {
  500. int isSuccess = FALSE;
  501. int ret = 0;
  502. //const char* data = "Callback function called";
  503. char sql[300];
  504. char zErrMsg[200];
  505. memset(sql, 0, 300);
  506. memset(zErrMsg, 0, 200);
  507. 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);
  508. //* Execute SQL statement */
  509. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  510. if( ret != SQLITE_OK )
  511. {
  512. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  513. return isSuccess;
  514. }
  515. memset(sql, 0, 300);
  516. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  517. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  518. if( ret != SQLITE_OK )
  519. {
  520. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  521. return isSuccess;
  522. }
  523. isSuccess = TRUE;
  524. return isSuccess;
  525. }
  526. void OCPP_getIdTagFromLocalList(char idTag[])
  527. {
  528. int rc = 0;
  529. // const char* data = "Callback function called";
  530. char sql[100];
  531. char zErrMsg[100];
  532. memset(sql, 0, 100);
  533. memset(zErrMsg, 0, 100);
  534. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  535. memset(&idTagQuery, 0, sizeof(idTagQuery));
  536. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  537. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  538. /* Execute SQL statement */
  539. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  540. if( rc != SQLITE_OK )
  541. {
  542. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  543. }
  544. //return ver;
  545. }
  546. void OCPP_deleteIdTagFromLocalList(char idTag[])
  547. {
  548. //int ver = 0;
  549. //int isSuccess = FALSE;
  550. int rc = 0;
  551. char sql[100];
  552. char zErrMsg[100];
  553. memset(sql, 0, 100);
  554. memset(zErrMsg, 0, 100);
  555. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  556. //* Execute SQL statement */
  557. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  558. if( rc != SQLITE_OK )
  559. {
  560. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  561. }
  562. }
  563. int getCurrentYear()
  564. {
  565. int result = 0;
  566. time_t CurrentTime;
  567. struct tm *tm;
  568. CurrentTime = time(NULL);
  569. tm=localtime(&CurrentTime);
  570. result = (tm->tm_year + 1900);
  571. return result;
  572. }
  573. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  574. {
  575. int result = PASS;
  576. char* errMsg = NULL;
  577. char sqlStr[8192];
  578. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  579. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  580. {
  581. result = FAIL;
  582. DEBUG_INFO( "Insert local transaction record error message: %s\n", errMsg);
  583. }
  584. sprintf(sqlStr, "delete from ocpp_transaction_record where (idx < (select idx from ocpp_transaction_record order by idx desc limit 1)-2000) and (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  585. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  586. {
  587. result = FAIL;
  588. DEBUG_INFO( "delete local transaction record error message: %s\n", errMsg);
  589. }
  590. return result;
  591. }
  592. //==========================================
  593. // Check time passed since today
  594. //==========================================
  595. long long DiffTimebWithNow(struct timeb ST)
  596. {
  597. //return milli-second
  598. struct timeb ET;
  599. long long StartTime,StopTime;
  600. ftime(&ET);
  601. StartTime=(long long)ST.time;
  602. StopTime=(long long)ET.time;
  603. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  604. }
  605. int getTimePassSinceToday()
  606. {
  607. int result = -1;
  608. static time_t lastTime;
  609. time_t t;
  610. struct tm *tmStartToday;
  611. struct timeb tbStartToday;
  612. t=time(NULL);
  613. if(difftime(t, lastTime)>0)
  614. {
  615. tmStartToday=localtime(&t);
  616. tmStartToday->tm_hour = 0;
  617. tmStartToday->tm_min = 0;
  618. tmStartToday->tm_sec = 0;
  619. tbStartToday.time = mktime(tmStartToday);
  620. tbStartToday.millitm = 0;
  621. result = DiffTimebWithNow(tbStartToday)/1000;
  622. lastTime = t;
  623. }
  624. return result;
  625. }
  626. void getNowDatetime(uint8_t *data)
  627. {
  628. time_t t = time(NULL);
  629. struct tm tm = *localtime(&t);
  630. 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);
  631. }
  632. int syncDateTimeRTC(uint8_t *data)
  633. {
  634. struct ParsingResult
  635. {
  636. int result;
  637. int scanedElement;
  638. int year;
  639. int month;
  640. int mday;
  641. int hour;
  642. int min;
  643. int sec;
  644. int tz_hour;
  645. int tz_min;
  646. float minSec;
  647. }result;
  648. struct tm tmOrg;
  649. struct tm *tmTarget;
  650. struct timeb tbTarget;
  651. char buf[128];
  652. memset(&result, 0x00, sizeof(struct ParsingResult));
  653. result.result = PASS;
  654. if(strstr((char*)data, ".") != NULL)
  655. {
  656. // Original data with mini second
  657. if(strstr((char*)data, "Z") != NULL)
  658. {
  659. // Original data with Z
  660. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  661. &result.year,
  662. &result.month,
  663. &result.mday,
  664. &result.hour,
  665. &result.min,
  666. &result.sec,
  667. &result.minSec);
  668. }
  669. else
  670. {
  671. // Original data without Z
  672. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  673. &result.year,
  674. &result.month,
  675. &result.mday,
  676. &result.hour,
  677. &result.min,
  678. &result.sec,
  679. &result.minSec,
  680. &result.tz_hour,
  681. &result.tz_min);
  682. }
  683. }
  684. else
  685. {
  686. // Original data without mini second
  687. if(strstr((char*)data, "Z") != NULL)
  688. {
  689. // Original data with Z
  690. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  691. &result.year,
  692. &result.month,
  693. &result.mday,
  694. &result.hour,
  695. &result.min,
  696. &result.sec);
  697. }
  698. else
  699. {
  700. // Original data without Z
  701. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  702. &result.year,
  703. &result.month,
  704. &result.mday,
  705. &result.hour,
  706. &result.min,
  707. &result.sec,
  708. &result.tz_hour,
  709. &result.tz_min);
  710. }
  711. }
  712. tmOrg.tm_year = result.year - 1900;
  713. tmOrg.tm_mon = result.month - 1;
  714. tmOrg.tm_mday = result.mday;
  715. tmOrg.tm_hour = result.hour;
  716. tmOrg.tm_min = result.min;
  717. tmOrg.tm_sec = result.sec;
  718. tmOrg.tm_gmtoff = 0;
  719. tbTarget.time = mktime(&tmOrg);
  720. tbTarget.timezone = 0;
  721. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  722. tmTarget = gmtime(&tbTarget.time);
  723. sprintf(buf, "date -s '%04d-%02d-%02d %02d:%02d:%02d'", (tmTarget->tm_year+1900), (tmTarget->tm_mon+1), tmTarget->tm_mday, tmTarget->tm_hour, tmTarget->tm_min, tmTarget->tm_sec);
  724. //DEBUG_INFO(" org date time: %s\n", data);
  725. //DEBUG_INFO("parse date time: %s\n", buf);
  726. system(buf);
  727. system("/sbin/hwclock -w --systohc");
  728. if(result.scanedElement < 6)
  729. result.result = FAIL;
  730. return result.result;
  731. }
  732. //==========================================
  733. // GetCompositeSchedule logic related function
  734. //==========================================
  735. int DiffTimebSec(struct timeb ST, struct timeb ET)
  736. {
  737. //return milli-second
  738. unsigned int StartTime,StopTime;
  739. StartTime=(unsigned int)ST.time;
  740. StopTime=(unsigned int)ET.time;
  741. return (StopTime-StartTime);
  742. }
  743. int DiffTimebWithNowSec(struct timeb ST)
  744. {
  745. //return milli-second
  746. struct timeb ET;
  747. unsigned int StartTime,StopTime;
  748. ftime(&ET);
  749. StartTime=(unsigned int)ST.time;
  750. StopTime=(unsigned int)ET.time;
  751. return (StopTime-StartTime);
  752. }
  753. int getStartStop(uint8_t *start, uint8_t *stop)
  754. {
  755. int result = -1;
  756. struct tm tmStart;
  757. struct timeb tbStart;
  758. struct tm tmStop;
  759. struct timeb tbStop;
  760. 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) &&
  761. (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))
  762. {
  763. //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);
  764. //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);
  765. tmStart.tm_year -= 1900;
  766. tmStart.tm_mon -= 1;
  767. tbStart.time = mktime(&tmStart);
  768. tbStart.millitm = 0;
  769. tmStop.tm_year -= 1900;
  770. tmStop.tm_mon -= 1;
  771. tbStop.time = mktime(&tmStop);
  772. tbStop.millitm = 0;
  773. result = DiffTimebSec(tbStart, tbStop);
  774. //DEBUG_INFO("getStartStop(): %d\n", result);
  775. }
  776. else
  777. {
  778. DEBUG_WARN("Start or stop date parsing error.\r\n");
  779. }
  780. return result;
  781. }
  782. int isOvertNow(uint8_t *start)
  783. {
  784. int result = NO;
  785. struct tm tmStart;
  786. struct timeb tbStart;
  787. 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))
  788. {
  789. //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);
  790. tmStart.tm_year -= 1900;
  791. tmStart.tm_mon -= 1;
  792. tbStart.time = mktime(&tmStart);
  793. tbStart.millitm = 0;
  794. if(DiffTimebWithNowSec(tbStart) <= 0)
  795. result = NO;
  796. else
  797. result = YES;
  798. }
  799. else
  800. {
  801. DEBUG_WARN("Start date parsing error.\n");
  802. }
  803. return result;
  804. }
  805. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  806. {
  807. int result = -1;
  808. struct tm tmStart;
  809. struct timeb tbStart;
  810. struct tm tmStop;
  811. struct timeb tbStop;
  812. 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) &&
  813. (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))
  814. {
  815. tmStart.tm_year -= 1900;
  816. tmStart.tm_mon -= 1;
  817. tbStart.time = mktime(&tmStart);
  818. tbStart.millitm = 0;
  819. tmStop.tm_year -= 1900;
  820. tmStop.tm_mon -= 1;
  821. tbStop.time = mktime(&tmStop);
  822. tbStop.millitm = 0;
  823. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  824. }
  825. return result;
  826. }
  827. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  828. {
  829. FILE *fp;
  830. char profileFileName[128];
  831. char *line = NULL;
  832. size_t len = 0;
  833. time_t CurrentTime;
  834. struct tm *tmComposite;
  835. struct StructChargingProfile maxProfile;
  836. struct StructChargingProfile defaultTxProfile;
  837. struct StructChargingProfile txProfile;
  838. struct StructChargingSchedulePeriod tmpPeriod;
  839. uint8_t limitMax=0;
  840. uint8_t limitDef=0;
  841. uint8_t limitTx=0;
  842. int compositePeriodIdx = 0;
  843. CurrentTime = time(NULL);
  844. tmComposite=localtime(&CurrentTime);
  845. 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);
  846. if(isUnitA)
  847. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  848. else
  849. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  850. compositeProfile->ChargingSchedule.Duration = durationReq;
  851. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  852. {
  853. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  854. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  855. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  856. }
  857. compositeProfile->ChargingProfileId = 0;
  858. compositeProfile->StackLevel = 99 ;
  859. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  860. maxProfile.ChargingProfileId = -1;
  861. defaultTxProfile.ChargingProfileId = -1;
  862. txProfile.ChargingProfileId = -1;
  863. maxProfile.ChargingSchedule.Duration = -1;
  864. defaultTxProfile.ChargingSchedule.Duration = -1;
  865. txProfile.ChargingSchedule.Duration = -1;
  866. system("yes|rm /tmp/*.json");
  867. system("cp /Storage/OCPP/*.json /tmp");
  868. /*
  869. * Search valid charging profile
  870. */
  871. //DEBUG_INFO("====================================\n");
  872. // Search tx profile
  873. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  874. if((access(profileFileName, F_OK))!=-1)
  875. {
  876. fp = fopen(profileFileName, "r");
  877. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  878. {
  879. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  880. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  881. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  882. }
  883. txProfile.ChargingProfileId = -1;
  884. txProfile.StackLevel = -1;
  885. while(getline(&line, &len, fp) != -1)
  886. {
  887. json_object *obj = NULL;
  888. obj = json_tokener_parse(line);
  889. if(is_error(obj))
  890. {
  891. DEBUG_ERROR("Parse txProfile from file error.\n");
  892. }
  893. else
  894. {
  895. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  896. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  897. )
  898. {
  899. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  900. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  901. )
  902. {
  903. struct tm tmFrom, tmTo;
  904. struct timeb tbFrom, tbTo;
  905. 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) &&
  906. (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))
  907. {
  908. tmFrom.tm_year -= 1900;
  909. tmFrom.tm_mon -= 1;
  910. tbFrom.time = mktime(&tmFrom);
  911. tmTo.tm_year -= 1900;
  912. tmTo.tm_mon -= 1;
  913. tbTo.time = mktime(&tmTo);
  914. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  915. {
  916. if(txProfile.ChargingProfileId == -1)
  917. DEBUG_INFO("TxProfile found.\n");
  918. else
  919. DEBUG_INFO("TxProfile updated.\n");
  920. // Required item
  921. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  922. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  923. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  924. if(isUnitA)
  925. {
  926. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  927. 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++)
  928. {
  929. 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"));
  930. 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?
  931. 3:
  932. 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")));
  933. 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")));
  934. }
  935. }
  936. else
  937. {
  938. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  939. 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++)
  940. {
  941. 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"));
  942. 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?
  943. 3:
  944. 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")));
  945. 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));
  946. }
  947. }
  948. // Optional item
  949. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  950. {
  951. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  952. }
  953. else
  954. {
  955. sprintf((char*)txProfile.ValidFrom, " ");
  956. }
  957. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  958. {
  959. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  960. }
  961. else
  962. {
  963. sprintf((char*)txProfile.ValidTo, " ");
  964. }
  965. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  966. {
  967. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  968. }
  969. else
  970. {
  971. sprintf((char*)txProfile.RecurrencyKind, " ");
  972. }
  973. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  974. {
  975. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  976. }
  977. else
  978. {
  979. txProfile.TransactionId = -1;
  980. }
  981. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  982. {
  983. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  984. }
  985. else
  986. {
  987. txProfile.ChargingSchedule.Duration = 86400;
  988. }
  989. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  990. {
  991. 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")));
  992. }
  993. else
  994. {
  995. 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));
  996. }
  997. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  998. {
  999. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1000. }
  1001. else
  1002. {
  1003. txProfile.ChargingSchedule.MinChargingRate = -1;
  1004. }
  1005. }
  1006. }
  1007. }
  1008. else
  1009. {
  1010. if(txProfile.ChargingProfileId == -1)
  1011. DEBUG_INFO("TxProfile found.\n");
  1012. else
  1013. DEBUG_INFO("TxProfile updated.\n");
  1014. // Required item
  1015. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1016. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1017. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1018. if(isUnitA)
  1019. {
  1020. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1021. 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++)
  1022. {
  1023. 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"));
  1024. 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?
  1025. 3:
  1026. 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")));
  1027. 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")));
  1028. }
  1029. }
  1030. else
  1031. {
  1032. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1033. 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++)
  1034. {
  1035. 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"));
  1036. 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?
  1037. 3:
  1038. 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")));
  1039. 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));
  1040. }
  1041. }
  1042. // Optional item
  1043. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1044. {
  1045. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1046. }
  1047. else
  1048. {
  1049. sprintf((char*)txProfile.ValidFrom, " ");
  1050. }
  1051. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1052. {
  1053. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1054. }
  1055. else
  1056. {
  1057. sprintf((char*)txProfile.ValidTo, " ");
  1058. }
  1059. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1060. {
  1061. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1062. }
  1063. else
  1064. {
  1065. sprintf((char*)txProfile.RecurrencyKind, " ");
  1066. }
  1067. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1068. {
  1069. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1070. }
  1071. else
  1072. {
  1073. txProfile.TransactionId = -1;
  1074. }
  1075. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1076. {
  1077. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1078. }
  1079. else
  1080. {
  1081. txProfile.ChargingSchedule.Duration = 86400;
  1082. }
  1083. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1084. {
  1085. 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")));
  1086. }
  1087. else
  1088. {
  1089. 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));
  1090. }
  1091. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1092. {
  1093. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1094. }
  1095. else
  1096. {
  1097. txProfile.ChargingSchedule.MinChargingRate = -1;
  1098. }
  1099. }
  1100. }
  1101. }
  1102. json_object_put(obj);
  1103. }
  1104. fclose(fp);
  1105. /*
  1106. if(txProfile.ChargingProfileId != -1)
  1107. {
  1108. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1109. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1110. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1111. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1112. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1113. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1114. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1115. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1116. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1117. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1118. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1119. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1120. {
  1121. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1122. {
  1123. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1124. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1125. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1126. }
  1127. }
  1128. }
  1129. else
  1130. DEBUG_INFO("TxProfile not found.\n");*/
  1131. }
  1132. // Search default tx profile
  1133. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1134. if((access(profileFileName, F_OK))==-1)
  1135. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1136. if((access(profileFileName, F_OK))!=-1)
  1137. {
  1138. fp = fopen(profileFileName, "r");
  1139. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1140. {
  1141. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1142. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1143. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1144. }
  1145. defaultTxProfile.ChargingProfileId = -1;
  1146. defaultTxProfile.StackLevel = -1;
  1147. while(getline(&line, &len, fp) != -1)
  1148. {
  1149. json_object *obj = NULL;
  1150. obj = json_tokener_parse(line);
  1151. if(is_error(obj))
  1152. {
  1153. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1154. }
  1155. else
  1156. {
  1157. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1158. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1159. )
  1160. {
  1161. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1162. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1163. )
  1164. {
  1165. struct tm tmFrom, tmTo;
  1166. struct timeb tbFrom, tbTo;
  1167. 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) &&
  1168. (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))
  1169. {
  1170. tmFrom.tm_year -= 1900;
  1171. tmFrom.tm_mon -= 1;
  1172. tbFrom.time = mktime(&tmFrom);
  1173. tmTo.tm_year -= 1900;
  1174. tmTo.tm_mon -= 1;
  1175. tbTo.time = mktime(&tmTo);
  1176. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1177. {
  1178. if(defaultTxProfile.ChargingProfileId == -1)
  1179. DEBUG_INFO("TxDefaultProfile found.\n");
  1180. else
  1181. DEBUG_INFO("TxDefaultProfile updated.\n");
  1182. // Required item
  1183. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1184. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1185. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1186. if(isUnitA)
  1187. {
  1188. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1189. 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++)
  1190. {
  1191. 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"));
  1192. 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?
  1193. 3:
  1194. 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")));
  1195. 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")));
  1196. }
  1197. }
  1198. else
  1199. {
  1200. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1201. 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++)
  1202. {
  1203. 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"));
  1204. 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?
  1205. 3:
  1206. 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")));
  1207. 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));
  1208. }
  1209. }
  1210. // Optional item
  1211. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1212. {
  1213. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1214. }
  1215. else
  1216. {
  1217. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1218. }
  1219. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1220. {
  1221. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1222. }
  1223. else
  1224. {
  1225. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1226. }
  1227. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1228. {
  1229. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1230. }
  1231. else
  1232. {
  1233. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1234. }
  1235. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1236. {
  1237. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1238. }
  1239. else
  1240. {
  1241. defaultTxProfile.TransactionId = -1;
  1242. }
  1243. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1244. {
  1245. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1246. }
  1247. else
  1248. {
  1249. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1250. }
  1251. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1252. {
  1253. 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")));
  1254. }
  1255. else
  1256. {
  1257. 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));
  1258. }
  1259. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1260. {
  1261. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1262. }
  1263. else
  1264. {
  1265. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1266. }
  1267. }
  1268. }
  1269. }
  1270. else
  1271. {
  1272. if(defaultTxProfile.ChargingProfileId == -1)
  1273. DEBUG_INFO("TxDefaultProfile found.\n");
  1274. else
  1275. DEBUG_INFO("TxDefaultProfile updated.\n");
  1276. // Required item
  1277. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1278. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1279. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1280. if(isUnitA)
  1281. {
  1282. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1283. 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++)
  1284. {
  1285. 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"));
  1286. 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?
  1287. 3:
  1288. 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")));
  1289. 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")));
  1290. }
  1291. }
  1292. else
  1293. {
  1294. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1295. 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++)
  1296. {
  1297. 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"));
  1298. 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?
  1299. 3:
  1300. 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")));
  1301. 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));
  1302. }
  1303. }
  1304. // Optional item
  1305. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1306. {
  1307. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1308. }
  1309. else
  1310. {
  1311. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1312. }
  1313. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1314. {
  1315. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1316. }
  1317. else
  1318. {
  1319. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1320. }
  1321. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1322. {
  1323. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1324. }
  1325. else
  1326. {
  1327. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1328. }
  1329. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1330. {
  1331. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1332. }
  1333. else
  1334. {
  1335. defaultTxProfile.TransactionId = -1;
  1336. }
  1337. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1338. {
  1339. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1340. }
  1341. else
  1342. {
  1343. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1344. }
  1345. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1346. {
  1347. 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")));
  1348. }
  1349. else
  1350. {
  1351. 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));
  1352. }
  1353. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1354. {
  1355. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1356. }
  1357. else
  1358. {
  1359. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1360. }
  1361. }
  1362. }
  1363. }
  1364. json_object_put(obj);
  1365. }
  1366. fclose(fp);
  1367. /*
  1368. if(defaultTxProfile.ChargingProfileId != -1)
  1369. {
  1370. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1371. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1372. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1373. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1374. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1375. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1376. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1377. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  1378. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1379. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1380. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1381. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1382. {
  1383. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1384. {
  1385. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1386. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1387. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1388. }
  1389. }
  1390. }
  1391. else
  1392. DEBUG_INFO("TxDefaultProfile not found.\n");
  1393. DEBUG_INFO("------------------------------------\n");*/
  1394. }
  1395. // Search max profile
  1396. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1397. if((access(profileFileName, F_OK))!=-1)
  1398. {
  1399. fp = fopen(profileFileName, "r");
  1400. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1401. {
  1402. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1403. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1404. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1405. }
  1406. maxProfile.ChargingProfileId = -1;
  1407. maxProfile.StackLevel = -1;
  1408. while(getline(&line, &len, fp) != -1)
  1409. {
  1410. json_object *obj = NULL;
  1411. obj = json_tokener_parse(line);
  1412. if(is_error(obj))
  1413. {
  1414. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1415. }
  1416. else
  1417. {
  1418. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1419. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1420. )
  1421. {
  1422. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1423. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1424. )
  1425. {
  1426. struct tm tmFrom, tmTo;
  1427. struct timeb tbFrom, tbTo;
  1428. 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) &&
  1429. (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))
  1430. {
  1431. tmFrom.tm_year -= 1900;
  1432. tmFrom.tm_mon -= 1;
  1433. tbFrom.time = mktime(&tmFrom);
  1434. tmTo.tm_year -= 1900;
  1435. tmTo.tm_mon -= 1;
  1436. tbTo.time = mktime(&tmTo);
  1437. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1438. {
  1439. if(maxProfile.ChargingProfileId == -1)
  1440. DEBUG_INFO("MaxProfile found.\n");
  1441. else
  1442. DEBUG_INFO("MaxProfile updated.\n");
  1443. // Required item
  1444. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1445. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1446. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1447. if(isUnitA)
  1448. {
  1449. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1450. 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++)
  1451. {
  1452. 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"));
  1453. 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?
  1454. 3:
  1455. 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")));
  1456. 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")));
  1457. }
  1458. }
  1459. else
  1460. {
  1461. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1462. 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++)
  1463. {
  1464. 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"));
  1465. 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?
  1466. 3:
  1467. 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")));
  1468. 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));
  1469. }
  1470. }
  1471. // Optional item
  1472. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1473. {
  1474. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1475. }
  1476. else
  1477. {
  1478. sprintf((char*)maxProfile.ValidFrom, " ");
  1479. }
  1480. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1481. {
  1482. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1483. }
  1484. else
  1485. {
  1486. sprintf((char*)maxProfile.ValidTo, " ");
  1487. }
  1488. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1489. {
  1490. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1491. }
  1492. else
  1493. {
  1494. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1495. }
  1496. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1497. {
  1498. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1499. }
  1500. else
  1501. {
  1502. maxProfile.TransactionId = -1;
  1503. }
  1504. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1505. {
  1506. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1507. }
  1508. else
  1509. {
  1510. maxProfile.ChargingSchedule.Duration = 86400;
  1511. }
  1512. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1513. {
  1514. 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")));
  1515. }
  1516. else
  1517. {
  1518. 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));
  1519. }
  1520. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1521. {
  1522. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1523. }
  1524. else
  1525. {
  1526. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1527. }
  1528. }
  1529. }
  1530. }
  1531. else
  1532. {
  1533. if(maxProfile.ChargingProfileId == -1)
  1534. DEBUG_INFO("MaxProfile found.\n");
  1535. else
  1536. DEBUG_INFO("MaxProfile updated.\n");
  1537. // Required item
  1538. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1539. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1540. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1541. if(isUnitA)
  1542. {
  1543. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1544. 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++)
  1545. {
  1546. 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"));
  1547. 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?
  1548. 3:
  1549. 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")));
  1550. 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")));
  1551. }
  1552. }
  1553. else
  1554. {
  1555. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1556. 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++)
  1557. {
  1558. 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"));
  1559. 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?
  1560. 3:
  1561. 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")));
  1562. 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));
  1563. }
  1564. }
  1565. // Optional item
  1566. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1567. {
  1568. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1569. }
  1570. else
  1571. {
  1572. sprintf((char*)maxProfile.ValidFrom, " ");
  1573. }
  1574. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1575. {
  1576. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1577. }
  1578. else
  1579. {
  1580. sprintf((char*)maxProfile.ValidTo, " ");
  1581. }
  1582. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1583. {
  1584. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1585. }
  1586. else
  1587. {
  1588. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1589. }
  1590. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1591. {
  1592. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1593. }
  1594. else
  1595. {
  1596. maxProfile.TransactionId = -1;
  1597. }
  1598. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1599. {
  1600. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1601. }
  1602. else
  1603. {
  1604. maxProfile.ChargingSchedule.Duration = 86400;
  1605. }
  1606. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1607. {
  1608. 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")));
  1609. }
  1610. else
  1611. {
  1612. 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));
  1613. }
  1614. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1615. {
  1616. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1617. }
  1618. else
  1619. {
  1620. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1621. }
  1622. }
  1623. }
  1624. }
  1625. json_object_put(obj);
  1626. }
  1627. fclose(fp);
  1628. /*
  1629. if(maxProfile.ChargingProfileId !=-1)
  1630. {
  1631. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1632. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1633. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1634. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1635. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1636. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1637. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1638. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1639. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1640. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1641. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1642. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1643. {
  1644. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1645. {
  1646. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1647. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1648. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1649. }
  1650. }
  1651. }
  1652. else
  1653. DEBUG_INFO("MaxProfile not found.\n");
  1654. DEBUG_INFO("------------------------------------\n");*/
  1655. }
  1656. /*
  1657. * Align found profile start schedule & periods
  1658. */
  1659. //DEBUG_INFO("====================================\n");
  1660. /*
  1661. // For local test usage, force modify found profile start schedule info
  1662. 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);
  1663. 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);
  1664. 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);
  1665. */
  1666. if(txProfile.ChargingProfileId != -1)
  1667. {
  1668. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1669. {
  1670. if(txProfile.ChargingSchedule.Duration != -1)
  1671. {
  1672. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1673. 0:
  1674. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1675. }
  1676. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1677. {
  1678. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1679. {
  1680. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1681. 0:
  1682. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1683. if(idxPeriod > 0)
  1684. {
  1685. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1686. {
  1687. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1688. }
  1689. }
  1690. }
  1691. }
  1692. }
  1693. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1694. {
  1695. if(txProfile.ChargingSchedule.Duration != -1)
  1696. {
  1697. 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?
  1698. 0:
  1699. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1700. }
  1701. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1702. {
  1703. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1704. {
  1705. 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?
  1706. 0:
  1707. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1708. if(idxPeriod > 0)
  1709. {
  1710. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1711. {
  1712. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1713. }
  1714. }
  1715. }
  1716. }
  1717. }
  1718. else
  1719. {
  1720. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1721. {
  1722. if(txProfile.ChargingSchedule.Duration != -1)
  1723. {
  1724. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1725. 0:
  1726. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1727. }
  1728. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1729. {
  1730. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1731. {
  1732. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1733. 0:
  1734. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1735. if(idxPeriod > 0)
  1736. {
  1737. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1738. {
  1739. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1740. }
  1741. }
  1742. }
  1743. }
  1744. }
  1745. else
  1746. {
  1747. if(txProfile.ChargingSchedule.Duration != -1)
  1748. {
  1749. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1750. 0:
  1751. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1752. }
  1753. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1754. {
  1755. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1756. {
  1757. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1758. 0:
  1759. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1760. if(idxPeriod > 0)
  1761. {
  1762. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1763. {
  1764. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1765. }
  1766. }
  1767. }
  1768. }
  1769. }
  1770. }
  1771. /*
  1772. DEBUG_INFO("txProfile after align.\n");
  1773. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1774. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1775. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1776. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1777. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1778. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1779. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1780. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1781. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1782. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1783. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1784. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1785. {
  1786. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1787. {
  1788. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1789. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1790. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1791. }
  1792. }*/
  1793. }
  1794. if(defaultTxProfile.ChargingProfileId != -1)
  1795. {
  1796. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1797. {
  1798. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1799. {
  1800. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1801. 0:
  1802. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1803. }
  1804. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1805. {
  1806. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1807. {
  1808. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1809. 0:
  1810. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1811. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1812. {
  1813. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1814. }
  1815. if(idxPeriod > 0)
  1816. {
  1817. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1818. {
  1819. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1820. }
  1821. }
  1822. }
  1823. }
  1824. }
  1825. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1826. {
  1827. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1828. {
  1829. 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?
  1830. 0:
  1831. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1832. }
  1833. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1834. {
  1835. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1836. {
  1837. 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?
  1838. 0:
  1839. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1840. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1841. {
  1842. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1843. }
  1844. if(idxPeriod > 0)
  1845. {
  1846. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1847. {
  1848. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1849. }
  1850. }
  1851. }
  1852. }
  1853. }
  1854. else
  1855. {
  1856. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1857. {
  1858. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1859. {
  1860. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1861. 0:
  1862. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1863. }
  1864. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1865. {
  1866. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1867. {
  1868. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1869. 0:
  1870. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1871. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1872. {
  1873. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1874. }
  1875. if(idxPeriod > 0)
  1876. {
  1877. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1878. {
  1879. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1880. }
  1881. }
  1882. }
  1883. }
  1884. }
  1885. else
  1886. {
  1887. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1888. {
  1889. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1890. 0:
  1891. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1892. }
  1893. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1894. {
  1895. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1896. {
  1897. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1898. 0:
  1899. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1900. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1901. {
  1902. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1903. }
  1904. if(idxPeriod > 0)
  1905. {
  1906. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1907. {
  1908. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1909. }
  1910. }
  1911. }
  1912. }
  1913. }
  1914. }
  1915. /*
  1916. DEBUG_INFO("defaultTxProfile after align.\n");
  1917. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1918. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1919. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1920. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1921. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1922. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1923. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1924. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1925. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1926. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1927. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1928. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1929. {
  1930. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1931. {
  1932. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1933. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1934. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1935. }
  1936. }
  1937. DEBUG_INFO("------------------------------------\n");*/
  1938. }
  1939. if(maxProfile.ChargingProfileId != -1)
  1940. {
  1941. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1942. {
  1943. if(maxProfile.ChargingSchedule.Duration != -1)
  1944. {
  1945. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1946. 0:
  1947. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1948. }
  1949. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1950. {
  1951. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1952. {
  1953. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1954. 0:
  1955. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1956. if(idxPeriod > 0)
  1957. {
  1958. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1959. {
  1960. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1961. }
  1962. }
  1963. }
  1964. }
  1965. }
  1966. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1967. {
  1968. if(maxProfile.ChargingSchedule.Duration != -1)
  1969. {
  1970. 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?
  1971. 0:
  1972. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1973. }
  1974. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1975. {
  1976. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1977. {
  1978. 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?
  1979. 0:
  1980. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1981. if(idxPeriod > 0)
  1982. {
  1983. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1984. {
  1985. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1986. }
  1987. }
  1988. }
  1989. }
  1990. }
  1991. else
  1992. {
  1993. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1994. {
  1995. if(maxProfile.ChargingSchedule.Duration != -1)
  1996. {
  1997. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1998. 0:
  1999. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2000. }
  2001. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2002. {
  2003. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2004. {
  2005. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2006. 0:
  2007. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2008. if(idxPeriod > 0)
  2009. {
  2010. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2011. {
  2012. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2013. }
  2014. }
  2015. }
  2016. }
  2017. }
  2018. else
  2019. {
  2020. if(maxProfile.ChargingSchedule.Duration != -1)
  2021. {
  2022. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2023. 0:
  2024. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2025. }
  2026. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2027. {
  2028. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2029. {
  2030. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2031. 0:
  2032. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2033. if(idxPeriod > 0)
  2034. {
  2035. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2036. {
  2037. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2038. }
  2039. }
  2040. }
  2041. }
  2042. }
  2043. }
  2044. /*
  2045. DEBUG_INFO("MaxProfile after align.\n");
  2046. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2047. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2048. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2049. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2050. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2051. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2052. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2053. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2054. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2055. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2056. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2057. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2058. {
  2059. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2060. {
  2061. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2062. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2063. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2064. }
  2065. }
  2066. DEBUG_INFO("------------------------------------\n");*/
  2067. }
  2068. /*
  2069. * Merge to conposite schedule
  2070. */
  2071. //DEBUG_INFO("====================================\n");
  2072. // Find each profile period quantity
  2073. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2074. {
  2075. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2076. limitMax = idx+1;
  2077. }
  2078. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2079. {
  2080. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2081. limitDef = idx+1;
  2082. }
  2083. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2084. {
  2085. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2086. limitTx = idx+1;
  2087. }
  2088. // TxProfile found, composite schedule based on it
  2089. if(txProfile.ChargingProfileId != -1)
  2090. {
  2091. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2092. {
  2093. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2094. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2095. (txProfile.ChargingSchedule.Duration > 0))
  2096. {
  2097. if(maxProfile.ChargingProfileId != -1)
  2098. {
  2099. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2100. {
  2101. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2102. {
  2103. if((maxProfile.ChargingSchedule.Duration > 0))
  2104. {
  2105. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2106. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2107. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2108. }
  2109. else
  2110. {
  2111. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2112. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2113. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2114. }
  2115. }
  2116. if(idxMaxPeriod == (limitMax-1))
  2117. {
  2118. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2119. {
  2120. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2121. {
  2122. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2123. compositePeriodIdx++;
  2124. }
  2125. else
  2126. {
  2127. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2128. }
  2129. }
  2130. }
  2131. }
  2132. }
  2133. else
  2134. {
  2135. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2136. {
  2137. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2138. compositePeriodIdx++;
  2139. }
  2140. else
  2141. {
  2142. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2143. }
  2144. }
  2145. }
  2146. if(idxTxPeriod == (limitTx-1))
  2147. {
  2148. if(defaultTxProfile.ChargingProfileId != -1)
  2149. {
  2150. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2151. {
  2152. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  2153. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2154. (defaultTxProfile.ChargingSchedule.Duration>0))
  2155. {
  2156. if(maxProfile.ChargingProfileId != -1)
  2157. {
  2158. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2159. {
  2160. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2161. {
  2162. if((maxProfile.ChargingSchedule.Duration > 0))
  2163. {
  2164. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2165. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2166. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2167. }
  2168. else
  2169. {
  2170. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2171. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2172. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2173. }
  2174. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2175. {
  2176. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2177. {
  2178. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2179. compositePeriodIdx++;
  2180. }
  2181. else
  2182. {
  2183. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2184. }
  2185. }
  2186. break;
  2187. }
  2188. }
  2189. }
  2190. else
  2191. {
  2192. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2193. {
  2194. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2195. compositePeriodIdx++;
  2196. }
  2197. else
  2198. {
  2199. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2200. }
  2201. }
  2202. }
  2203. }
  2204. }
  2205. }
  2206. }
  2207. }
  2208. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2209. else if(defaultTxProfile.ChargingProfileId != -1)
  2210. {
  2211. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2212. {
  2213. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2214. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2215. (defaultTxProfile.ChargingSchedule.Duration > 0))
  2216. {
  2217. if(maxProfile.ChargingProfileId != -1)
  2218. {
  2219. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2220. {
  2221. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2222. {
  2223. if((maxProfile.ChargingSchedule.Duration > 0))
  2224. {
  2225. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2226. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2227. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  2228. }
  2229. else
  2230. {
  2231. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2232. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2233. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2234. }
  2235. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2236. {
  2237. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2238. {
  2239. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2240. compositePeriodIdx++;
  2241. }
  2242. else
  2243. {
  2244. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2245. }
  2246. }
  2247. break;
  2248. }
  2249. }
  2250. }
  2251. else
  2252. {
  2253. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2254. {
  2255. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2256. compositePeriodIdx++;
  2257. }
  2258. else
  2259. {
  2260. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2261. }
  2262. }
  2263. }
  2264. }
  2265. }
  2266. // Fill other period by MaxProfile
  2267. if(maxProfile.ChargingProfileId != -1)
  2268. {
  2269. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2270. {
  2271. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2272. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2273. (maxProfile.ChargingSchedule.Duration > 0))
  2274. {
  2275. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  2276. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2277. {
  2278. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  2279. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  2280. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2281. }
  2282. if((maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2283. {
  2284. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.Duration;
  2285. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  2286. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2287. }
  2288. if(tmpPeriod.Limit != -1)
  2289. {
  2290. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2291. {
  2292. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2293. {
  2294. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2295. compositePeriodIdx++;
  2296. }
  2297. else
  2298. {
  2299. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2300. }
  2301. }
  2302. }
  2303. }
  2304. }
  2305. }
  2306. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  2307. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2308. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  2309. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  2310. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2311. {
  2312. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2313. {
  2314. compositeProfile->ChargingProfileId = 1;
  2315. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2316. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2317. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2318. }
  2319. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2320. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2321. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2322. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2323. }
  2324. if(line)
  2325. free(line);
  2326. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  2327. }
  2328. //==========================================
  2329. // Init all share memory
  2330. //==========================================
  2331. int InitShareMemory()
  2332. {
  2333. int result = PASS;
  2334. int MeterSMId;
  2335. //creat ShmSysConfigAndInfo
  2336. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  2337. {
  2338. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  2339. result = FAIL;
  2340. }
  2341. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2342. {
  2343. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  2344. result = FAIL;
  2345. }
  2346. else
  2347. {}
  2348. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  2349. {
  2350. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  2351. result = FAIL;
  2352. }
  2353. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2354. {
  2355. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  2356. result = FAIL;
  2357. }
  2358. else
  2359. {}
  2360. //creat ShmPsuData
  2361. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  2362. {
  2363. DEBUG_ERROR("shmget ShmPsuData NG\n");
  2364. result = FAIL;
  2365. }
  2366. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2367. {
  2368. DEBUG_ERROR("shmat ShmPsuData NG\n");
  2369. result = FAIL;
  2370. }
  2371. else
  2372. {}
  2373. //creat ShmOCPP16Data
  2374. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  2375. {
  2376. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  2377. result = FAIL;
  2378. }
  2379. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2380. {
  2381. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  2382. result = FAIL;
  2383. }
  2384. else
  2385. {}
  2386. /****************************** For Initial Settings************************************************/
  2387. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  2388. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  2389. // allocate Configuration memory address
  2390. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  2391. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  2392. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  2393. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  2394. //offline MeterValue Interval
  2395. TempMeterValueInterval = 0;
  2396. return result;
  2397. }
  2398. int ProcessShareMemory()
  2399. {
  2400. if(InitShareMemory() == FAIL)
  2401. {
  2402. DEBUG_ERROR("InitShareMemory NG\n");
  2403. if(ShmStatusCodeData!=NULL)
  2404. {
  2405. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  2406. }
  2407. sleep(5);
  2408. return FAIL;
  2409. }
  2410. return PASS;
  2411. }
  2412. void CheckSystemValue(void)
  2413. {
  2414. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  2415. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  2416. char filenmae[100]={0};
  2417. char str[100]={0};
  2418. int tempIndex = 0;
  2419. //===============================
  2420. // send Heartbeat
  2421. //===============================
  2422. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2423. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2424. {
  2425. clientTime.Heartbeat=time((time_t*)NULL);
  2426. if(server_sign == TRUE)
  2427. {
  2428. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2429. }
  2430. else
  2431. {
  2432. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2433. }
  2434. }
  2435. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  2436. {
  2437. //parameter for test
  2438. sendHeartbeatRequest(0);
  2439. //==============================================
  2440. // Reset Waiting Time
  2441. //==============================================
  2442. HeartBeatWithNOResponse += 1;
  2443. }
  2444. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2445. {
  2446. //==========================================
  2447. // csu trigger DataTransferReq
  2448. //==========================================
  2449. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2450. {
  2451. sendDataTransferRequest(gun_index);
  2452. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2453. }
  2454. //===============================
  2455. // CSU Trigger Reset Conf
  2456. //===============================
  2457. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  2458. {
  2459. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  2460. }
  2461. //===============================
  2462. // CSU Trigger Authorize Request
  2463. //===============================
  2464. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2465. {
  2466. sendAuthorizeRequest(0);
  2467. authorizeRetryTimes = authorizeRetryTimes + 1;
  2468. if(authorizeRetryTimes < 3)
  2469. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2470. }
  2471. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  2472. {
  2473. authorizeRetryTimes = 0;
  2474. SetOcppConnStatus(FALSE);
  2475. server_sign = FALSE;
  2476. }
  2477. 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))
  2478. {
  2479. sendAuthorizeRequest(0);
  2480. }
  2481. //==============================================
  2482. // CSU Trigger Smart Charging Profilw
  2483. //==============================================
  2484. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2485. {
  2486. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  2487. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2488. }
  2489. //==============================================
  2490. // Charger start transaction
  2491. //==============================================
  2492. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2493. {
  2494. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  2495. sendStartTransactionRequest(gun_index);
  2496. clientTime.StartTransaction = time((time_t*)NULL);
  2497. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2498. storeTempStopTransaction(gun_index);
  2499. }
  2500. //==============================================
  2501. // Charger stop transaction
  2502. //==============================================
  2503. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2504. {
  2505. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2506. sendStopTransactionRequest(gun_index);
  2507. clientTime.StopTransaction = time((time_t*)NULL);
  2508. }
  2509. //==============================================
  2510. // Charger status report
  2511. //==============================================
  2512. //--- Check Mode Change ---//
  2513. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2514. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2515. {
  2516. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2517. {
  2518. tempIndex = ((gun_index==2) ? 1: 0);
  2519. }
  2520. else
  2521. {
  2522. tempIndex = gun_index;
  2523. }
  2524. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2525. {
  2526. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2527. {
  2528. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  2529. {
  2530. // Sent unplug message for California pricing logic
  2531. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  2532. {
  2533. uint8_t ts[20];
  2534. getNowDatetime(ts);
  2535. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2536. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2537. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2538. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2539. }
  2540. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2541. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2542. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2543. statusModeChage[gun_index] = TRUE;
  2544. }
  2545. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2546. {
  2547. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2548. if((access(filenmae,F_OK))!=-1)
  2549. {
  2550. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2551. sprintf(str,"rm -f %s",filenmae);
  2552. system(str);
  2553. }
  2554. }
  2555. #if 1 // for TempStopTransaction
  2556. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2557. {
  2558. checkTempStopTransaction(gun_index);
  2559. }
  2560. #endif
  2561. }
  2562. }
  2563. }
  2564. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2565. {
  2566. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2567. {
  2568. tempIndex = ((gun_index==2) ? 1: 0);
  2569. }
  2570. else
  2571. {
  2572. tempIndex = gun_index;
  2573. }
  2574. for (int index = 0; index < CCS_QUANTITY; index++)
  2575. {
  2576. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2577. {
  2578. 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]*/ )
  2579. {
  2580. // Sent unplug message for California pricing logic
  2581. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  2582. {
  2583. uint8_t ts[20];
  2584. getNowDatetime(ts);
  2585. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2586. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2587. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2588. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2589. }
  2590. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2591. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2592. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2593. statusModeChage[gun_index] = TRUE;
  2594. }
  2595. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2596. {
  2597. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2598. if((access(filenmae,F_OK))!=-1)
  2599. {
  2600. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2601. sprintf(str,"rm -f %s",filenmae);
  2602. system(str);
  2603. }
  2604. }
  2605. #if 1 // for TempStopTransaction
  2606. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2607. {
  2608. checkTempStopTransaction(gun_index);
  2609. }
  2610. #endif
  2611. }
  2612. }
  2613. }
  2614. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2615. {
  2616. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2617. {
  2618. tempIndex = ((gun_index==2) ? 1: 0);
  2619. }
  2620. else
  2621. {
  2622. tempIndex = gun_index;
  2623. }
  2624. for (int index = 0; index < GB_QUANTITY; index++)
  2625. {
  2626. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2627. {
  2628. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2629. {
  2630. // Sent unplug message for California pricing logic
  2631. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  2632. {
  2633. uint8_t ts[20];
  2634. getNowDatetime(ts);
  2635. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2636. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2637. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2638. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2639. }
  2640. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2641. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2642. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2643. statusModeChage[gun_index] = TRUE;
  2644. }
  2645. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2646. {
  2647. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2648. if((access(filenmae,F_OK))!=-1)
  2649. {
  2650. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2651. sprintf(str,"rm -f %s",filenmae);
  2652. system(str);
  2653. }
  2654. }
  2655. #if 1 // for TempStopTransaction
  2656. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2657. {
  2658. checkTempStopTransaction(gun_index);
  2659. }
  2660. #endif
  2661. }
  2662. }
  2663. }
  2664. else if(gunType[gun_index] == GUN_TYPE_DO)
  2665. {
  2666. tempIndex = gun_index;
  2667. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2668. {
  2669. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2670. {
  2671. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  2672. {
  2673. // Sent unplug message for California pricing logic
  2674. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  2675. {
  2676. uint8_t ts[20];
  2677. getNowDatetime(ts);
  2678. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2679. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2680. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2681. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2682. }
  2683. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  2684. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  2685. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2686. statusModeChage[gun_index] = TRUE;
  2687. }
  2688. 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
  2689. {
  2690. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2691. if((access(filenmae,F_OK))!=-1)
  2692. {
  2693. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2694. sprintf(str,"rm -f %s",filenmae);
  2695. system(str);
  2696. }
  2697. }
  2698. #if 1 // for TempStopTransaction
  2699. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2700. {
  2701. checkTempStopTransaction(gun_index);
  2702. }
  2703. #endif
  2704. }
  2705. }
  2706. }
  2707. else
  2708. {
  2709. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2710. {
  2711. tempIndex = 2;
  2712. }
  2713. else
  2714. {
  2715. tempIndex = gun_index;
  2716. }
  2717. for (int index = 0; index < AC_QUANTITY; index++)
  2718. {
  2719. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2720. {
  2721. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2722. {
  2723. // Sent unplug message for California pricing logic
  2724. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)
  2725. {
  2726. uint8_t ts[20];
  2727. getNowDatetime(ts);
  2728. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2729. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2730. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2731. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2732. }
  2733. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2734. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2735. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2736. statusModeChage[gun_index] = TRUE;
  2737. }
  2738. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2739. {
  2740. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2741. if((access(filenmae,F_OK))!=-1)
  2742. {
  2743. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2744. sprintf(str,"rm -f %s",filenmae);
  2745. system(str);
  2746. }
  2747. }
  2748. #if 1 // for TempStopTransaction
  2749. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2750. {
  2751. checkTempStopTransaction(gun_index);
  2752. }
  2753. #endif
  2754. }
  2755. }// END
  2756. }
  2757. if(isWebsocketSendable && (server_sign == TRUE) &&
  2758. (
  2759. (statusModeChage[gun_index] == TRUE) ||
  2760. //((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index))) ||
  2761. ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 10))
  2762. )
  2763. )
  2764. {
  2765. if(SystemInitial > 0)
  2766. SystemInitial -= 1;
  2767. sendStatusNotificationRequest(gun_index);
  2768. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2769. statusModeChage[gun_index] = FALSE;
  2770. }
  2771. //==============================================
  2772. // Meter report
  2773. //==============================================
  2774. // Trigger MeterValue
  2775. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  2776. {
  2777. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  2778. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  2779. }
  2780. // ClockAlign MeterValue
  2781. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  2782. {
  2783. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2784. {
  2785. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2786. {
  2787. tempIndex = ((gun_index==2) ? 1: 0);
  2788. }
  2789. else
  2790. {
  2791. tempIndex = gun_index;
  2792. }
  2793. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2794. {
  2795. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2796. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2797. {
  2798. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2799. {
  2800. reqClockAlignMeter[gun_index] = 1;
  2801. }
  2802. }
  2803. }// End for CHAdeMO
  2804. }
  2805. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2806. {
  2807. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2808. {
  2809. tempIndex = ((gun_index==2) ? 1: 0);
  2810. }
  2811. else
  2812. {
  2813. tempIndex = gun_index;
  2814. }
  2815. for (int index = 0; index < CCS_QUANTITY; index++)
  2816. {
  2817. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2818. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2819. {
  2820. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2821. {
  2822. reqClockAlignMeter[gun_index] = 1;
  2823. }
  2824. }
  2825. } // End for CCS
  2826. }
  2827. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2828. {
  2829. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2830. {
  2831. tempIndex = ((gun_index==2) ? 1: 0);
  2832. }
  2833. else
  2834. {
  2835. tempIndex = gun_index;
  2836. }
  2837. for (int index = 0; index < GB_QUANTITY; index++)
  2838. {
  2839. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2840. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2841. {
  2842. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2843. {
  2844. reqClockAlignMeter[gun_index] = 1;
  2845. }
  2846. }
  2847. }// End for GB
  2848. }
  2849. else if(gunType[gun_index] == GUN_TYPE_DO)
  2850. {
  2851. tempIndex = gun_index;
  2852. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2853. {
  2854. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2855. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2856. {
  2857. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_CHARGING)
  2858. {
  2859. reqClockAlignMeter[gun_index] = 1;
  2860. }
  2861. }
  2862. }
  2863. }
  2864. else
  2865. {
  2866. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2867. {
  2868. tempIndex = 2;
  2869. }
  2870. else
  2871. {
  2872. tempIndex = gun_index;
  2873. }
  2874. for (int index = 0; index < AC_QUANTITY; index++)
  2875. {
  2876. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2877. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2878. {
  2879. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2880. {
  2881. reqClockAlignMeter[gun_index] = 1;
  2882. }
  2883. }
  2884. }//End for AC
  2885. }
  2886. if(reqClockAlignMeter[gun_index] == 1)
  2887. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2888. }
  2889. // Sample period MeterValue
  2890. if((((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1))))
  2891. {
  2892. //check Transaction active
  2893. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2894. {
  2895. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2896. {
  2897. tempIndex = ((gun_index==2) ? 1: 0);
  2898. }
  2899. else
  2900. {
  2901. tempIndex = gun_index;
  2902. }
  2903. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2904. {
  2905. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2906. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2907. {
  2908. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2909. {
  2910. reqSampleMeter[gun_index] = 1;
  2911. }
  2912. }
  2913. }// End for CHAdeMO
  2914. }
  2915. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2916. {
  2917. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2918. {
  2919. tempIndex = ((gun_index==2) ? 1: 0);
  2920. }
  2921. else
  2922. {
  2923. tempIndex = gun_index;
  2924. }
  2925. for (int index = 0; index < CCS_QUANTITY; index++)
  2926. {
  2927. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2928. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2929. {
  2930. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2931. {
  2932. reqSampleMeter[gun_index] = 1;
  2933. }
  2934. }
  2935. } // End for CCS
  2936. }
  2937. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2938. {
  2939. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2940. {
  2941. tempIndex = ((gun_index==2) ? 1: 0);
  2942. }
  2943. else
  2944. {
  2945. tempIndex = gun_index;
  2946. }
  2947. for (int index = 0; index < GB_QUANTITY; index++)
  2948. {
  2949. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2950. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2951. {
  2952. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2953. {
  2954. reqSampleMeter[gun_index] = 1;
  2955. }
  2956. }
  2957. }// End for GB
  2958. }
  2959. else if(gunType[gun_index] == GUN_TYPE_DO)
  2960. {
  2961. tempIndex = gun_index;
  2962. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2963. {
  2964. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2965. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2966. {
  2967. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  2968. {
  2969. reqSampleMeter[gun_index] = 1;
  2970. }
  2971. }
  2972. }
  2973. }
  2974. else
  2975. {
  2976. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2977. {
  2978. tempIndex = 2;
  2979. }
  2980. else
  2981. {
  2982. tempIndex = gun_index;
  2983. }
  2984. for (int index = 0; index < AC_QUANTITY; index++)
  2985. {
  2986. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2987. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2988. {
  2989. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  2990. {
  2991. reqSampleMeter[gun_index] = 1;
  2992. }
  2993. }
  2994. }//End for AC
  2995. }
  2996. if(reqSampleMeter[gun_index] == 1)
  2997. {
  2998. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  2999. storeTempStopTransaction(gun_index);
  3000. }
  3001. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3002. }
  3003. //==============================================
  3004. // Check Connector reserved
  3005. //==============================================
  3006. //===============================
  3007. // Check if Reserve is expired
  3008. //===============================
  3009. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  3010. {
  3011. double diff_t;
  3012. struct tm tp;
  3013. // current time
  3014. time_t t = time(NULL);
  3015. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  3016. tp.tm_isdst = -1;
  3017. time_t utc = mktime(&tp);
  3018. diff_t = difftime(utc, t);
  3019. if(diff_t <= 0)
  3020. {
  3021. DEBUG_INFO("reserve expired.\n");
  3022. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  3023. }
  3024. }//END OF Check if Reserve is expired
  3025. //==========================================
  3026. // csu trigger FirmwareStatusNotificationReq
  3027. //==========================================
  3028. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  3029. {
  3030. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  3031. }
  3032. //==========================================
  3033. // csu trigger DiagnosticsStatusNotificationReq
  3034. //==========================================
  3035. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  3036. {
  3037. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  3038. }
  3039. //==========================================
  3040. // csu trigger CancelReservationConf
  3041. //==========================================
  3042. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  3043. {
  3044. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  3045. }
  3046. //==========================================
  3047. // csu trigger ChangeAvailabilityConf
  3048. //==========================================
  3049. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  3050. {
  3051. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  3052. }
  3053. //==========================================
  3054. // csu trigger UnlockConnectorConf
  3055. //==========================================
  3056. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  3057. {
  3058. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  3059. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  3060. }
  3061. //==========================================
  3062. // csu trigger ReserveNowConf
  3063. //==========================================
  3064. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  3065. {
  3066. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  3067. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  3068. }
  3069. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  3070. {
  3071. sendSignCertificateRequest();
  3072. }
  3073. }
  3074. }
  3075. //==========================================
  3076. // send request routine
  3077. //==========================================
  3078. int sendAuthorizeRequest(int gun_index)
  3079. {
  3080. mtrace();
  3081. int result = FAIL;
  3082. char message[100]={0};
  3083. char guid[37];
  3084. char tempdata[65]={0};
  3085. DEBUG_INFO("sendAuthorizeRequest...\n");
  3086. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  3087. //Local Authorize
  3088. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  3089. {
  3090. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  3091. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  3092. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  3093. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  3094. result = PASS;
  3095. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3096. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3097. authorizeRetryTimes = 0;
  3098. return result;
  3099. }
  3100. 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))||
  3101. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  3102. {
  3103. // Query from cache
  3104. DEBUG_INFO("Authorize from cache.\n");
  3105. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3106. // Query from list
  3107. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3108. {
  3109. DEBUG_INFO("Authorize from list.\n");
  3110. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3111. }
  3112. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3113. {
  3114. if(strcmp(idTagQuery.idTagstr,"") == 0)
  3115. {
  3116. DEBUG_INFO("off-line Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  3117. }
  3118. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  3119. {
  3120. DEBUG_INFO("off-line Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  3121. }
  3122. DEBUG_INFO("off-line Local Authorization Fail !!!!\n");
  3123. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3124. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3125. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  3126. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3127. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3128. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3129. authorizeRetryTimes = 0;
  3130. return result;
  3131. }
  3132. else
  3133. {
  3134. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  3135. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3136. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3137. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  3138. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  3139. else
  3140. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  3141. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3142. result = PASS;
  3143. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3144. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3145. authorizeRetryTimes = 0;
  3146. return result;
  3147. }
  3148. }
  3149. //initialize struct Authorize
  3150. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  3151. //get data from shared memory
  3152. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3153. random_uuid(guid);
  3154. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  3155. LWS_Send(message);
  3156. sprintf(tempdata, "Authorize,%d", gun_index);
  3157. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3158. {
  3159. result = PASS;
  3160. DEBUG_INFO("Authorize mapItem pass\n");
  3161. }
  3162. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3163. return result;
  3164. }
  3165. int sendBootNotificationRequest(void)
  3166. {
  3167. mtrace();
  3168. int result = FAIL;
  3169. char message[500]={0}, payload[700]={0};
  3170. char guid[37]={0};
  3171. char tempdata[65]={0};
  3172. // Fill BootNotification fields
  3173. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  3174. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  3175. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  3176. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3177. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  3178. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  3179. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  3180. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  3181. ShmOCPP16Data->ChargeBoxId
  3182. ,ShmSysConfigAndInfo->SysConfig.ModelName
  3183. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  3184. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  3185. ,ShmOCPP16Data->BootNotification.CpFwVersion
  3186. ,ShmOCPP16Data->BootNotification.CpIccid
  3187. ,ShmOCPP16Data->BootNotification.CpImsi);
  3188. random_uuid(guid);
  3189. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  3190. LWS_Send(message);
  3191. sprintf(tempdata, "BootNotification,0");
  3192. 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*/)
  3193. {
  3194. result = PASS;
  3195. }
  3196. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3197. strcpy(queuedata,message);
  3198. return result;
  3199. }
  3200. int sendDataTransferRequest(int gun_index)
  3201. {
  3202. mtrace();
  3203. char message[1000]={0};
  3204. char guid[37]={0};
  3205. char tempdata[65]={0};
  3206. int result = FAIL;
  3207. random_uuid(guid);
  3208. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  3209. MESSAGE_TYPE_CALL,
  3210. guid,
  3211. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  3212. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  3213. ShmOCPP16Data->DataTransfer[gun_index].Data);
  3214. LWS_Send(message);
  3215. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  3216. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3217. {
  3218. result = PASS;
  3219. DEBUG_INFO("DataTransfer mapItem pass\n");
  3220. }
  3221. return result;
  3222. }
  3223. int sendDiagnosticsStatusNotificationRequest(char *status)
  3224. {
  3225. mtrace();
  3226. int result = FAIL;
  3227. char message[110]={0};
  3228. char guid[37]={0};
  3229. char tempdata[65]={0};
  3230. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  3231. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  3232. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  3233. random_uuid(guid);
  3234. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  3235. LWS_SendNow(message);
  3236. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  3237. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3238. {
  3239. result = PASS;
  3240. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  3241. }
  3242. //#ifdef SystemLogMessage
  3243. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  3244. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3245. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  3246. //#endif
  3247. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  3248. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  3249. //record status
  3250. if(strcmp(status,"Idle")==0)
  3251. {
  3252. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  3253. }
  3254. else if(strcmp(status,"Uploaded")==0)
  3255. {
  3256. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  3257. }
  3258. else if(strcmp(status,"UploadFailed")==0)
  3259. {
  3260. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  3261. }
  3262. else if(strcmp(status,"Uploading")==0)
  3263. {
  3264. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  3265. }
  3266. return result;
  3267. }
  3268. int sendFirmwareStatusNotificationRequest(char *status)
  3269. {
  3270. mtrace();
  3271. int result = FAIL;
  3272. char message[110]={0};
  3273. char guid[37]={0};
  3274. char tempdata[65]={0};
  3275. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  3276. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  3277. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  3278. random_uuid(guid);
  3279. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  3280. LWS_SendNow(message);
  3281. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  3282. 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*/)
  3283. {
  3284. result = PASS;
  3285. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  3286. }
  3287. //#ifdef SystemLogMessage
  3288. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  3289. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3290. //#endif
  3291. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  3292. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  3293. //record status
  3294. if(strcmp(status,"Downloaded")==0)
  3295. {
  3296. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  3297. }
  3298. else if(strcmp(status,"DownloadFailed")==0)
  3299. {
  3300. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  3301. }
  3302. else if(strcmp(status,"Downloading")==0)
  3303. {
  3304. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  3305. }
  3306. else if(strcmp(status,"Idle")==0)
  3307. {
  3308. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  3309. }
  3310. else if(strcmp(status,"InstallationFailed")==0)
  3311. {
  3312. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  3313. }
  3314. else if(strcmp(status,"Installing")==0)
  3315. {
  3316. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  3317. }
  3318. else if(strcmp(status,"Installed")==0)
  3319. {
  3320. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  3321. }
  3322. return result;
  3323. }
  3324. int sendHeartbeatRequest(int gun_index)
  3325. {
  3326. mtrace();
  3327. int result = FAIL;
  3328. char message[80]={0};
  3329. char guid[37]={0};
  3330. char tempdata[65]={0};
  3331. random_uuid(guid);
  3332. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  3333. , MESSAGE_TYPE_CALL
  3334. , guid );
  3335. LWS_Send(message);
  3336. sprintf(tempdata, "Heartbeat,%d", 0);
  3337. 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*/)
  3338. {
  3339. result = PASS;
  3340. }
  3341. return result;
  3342. }
  3343. int sendStartTransactionRequest(int gun_index)
  3344. {
  3345. mtrace();
  3346. int result = FAIL;
  3347. char message[250]={0};
  3348. char guid[37]={0};
  3349. struct timeval tmnow;
  3350. struct tm *tm;
  3351. char buf[28];//, usec_buf[6];
  3352. char tempdata[65]={0};
  3353. int tempIndex = 0;
  3354. DEBUG_INFO("sendStartTransactionRequest...\n");
  3355. gettimeofday(&tmnow, NULL);
  3356. time_t t;
  3357. t = time(NULL);
  3358. /*UTC time and date*/
  3359. tm = gmtime(&t);
  3360. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3361. #if 0 // remove temporally
  3362. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3363. strcat(buf,".");
  3364. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3365. strcat(buf,usec_buf);
  3366. #endif
  3367. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  3368. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  3369. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3370. // clear StartTransaction Response
  3371. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  3372. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  3373. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  3374. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  3375. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3376. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3377. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3378. {
  3379. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3380. {
  3381. tempIndex = ((gun_index==2) ? 1: 0);
  3382. }
  3383. else
  3384. {
  3385. tempIndex = gun_index;
  3386. }
  3387. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3388. {
  3389. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3390. {
  3391. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3392. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  3393. }
  3394. }
  3395. }
  3396. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3397. {
  3398. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3399. {
  3400. tempIndex = ((gun_index==2) ? 1: 0);
  3401. }
  3402. else
  3403. {
  3404. tempIndex = gun_index;
  3405. }
  3406. for (int index = 0; index < CCS_QUANTITY; index++)
  3407. {
  3408. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3409. {
  3410. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3411. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  3412. }
  3413. }
  3414. }
  3415. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3416. {
  3417. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3418. {
  3419. tempIndex = ((gun_index==2) ? 1: 0);
  3420. }
  3421. else
  3422. {
  3423. tempIndex = gun_index;
  3424. }
  3425. for (int index = 0; index < GB_QUANTITY; index++)
  3426. {
  3427. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3428. {
  3429. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3430. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  3431. }
  3432. }
  3433. }
  3434. else if(gunType[gun_index] == GUN_TYPE_DO)
  3435. {
  3436. tempIndex = gun_index;
  3437. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3438. {
  3439. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3440. {
  3441. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3442. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  3443. }
  3444. }
  3445. }
  3446. else
  3447. {
  3448. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3449. {
  3450. tempIndex = 2;
  3451. }
  3452. else
  3453. {
  3454. tempIndex = gun_index;
  3455. }
  3456. for (int index = 0; index < AC_QUANTITY; index++)
  3457. {
  3458. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3459. {
  3460. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3461. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  3462. }
  3463. }
  3464. }
  3465. random_uuid(guid);
  3466. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  3467. {
  3468. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  3469. , gun_index +1
  3470. , MESSAGE_TYPE_CALL
  3471. , guid
  3472. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3473. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3474. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3475. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3476. }
  3477. else
  3478. {
  3479. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  3480. , gun_index +1
  3481. , MESSAGE_TYPE_CALL
  3482. , guid
  3483. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3484. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3485. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3486. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  3487. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3488. }
  3489. #if 1
  3490. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  3491. 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*/)
  3492. {
  3493. result = PASS;
  3494. }
  3495. #endif
  3496. strcpy(queuedata, message);
  3497. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3498. OCPP_insert_transaction_msg(YES, queuedata);
  3499. return result;
  3500. }
  3501. int sendStatusNotificationRequest(int gun_index)
  3502. {
  3503. mtrace();
  3504. int result = FAIL;
  3505. char message[600]={0};
  3506. char guid[37];
  3507. int currentStatus = 0;
  3508. struct timeval tmnow;
  3509. struct tm *tm;
  3510. char buf[28];//, usec_buf[6];
  3511. char tempdata[65]={0};
  3512. int tempIndex = 0;
  3513. uint8_t isStateChanged = TRUE;
  3514. DEBUG_INFO("sendStatusNotificationRequest...\n");
  3515. gettimeofday(&tmnow, NULL);
  3516. time_t t;
  3517. t = time(NULL);
  3518. /*UTC time and date*/
  3519. tm = gmtime(&t);
  3520. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3521. #if 0 // remove temporally
  3522. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3523. strcat(buf,".");
  3524. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3525. strcat(buf,usec_buf);
  3526. #endif
  3527. printf("%s",buf);
  3528. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  3529. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  3530. // it's option
  3531. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  3532. /*
  3533. enum _SYSTEM_STATUS
  3534. {
  3535. S_BOOTING = 0,
  3536. S_IDLE, = 1
  3537. S_AUTHORIZING, =2
  3538. S_REASSIGN_CHECK, =3
  3539. S_REASSIGN, =4
  3540. S_PRECHARGE, =5
  3541. S_PREPARING_FOR_EV, =6
  3542. S_PREPARING_FOR_EVSE, =7
  3543. S_CHARGING, =8
  3544. S_TERMINATING, =9
  3545. S_COMPLETE, =10
  3546. S_ALARM, =11
  3547. S_FAULT =12
  3548. }
  3549. */
  3550. //check Transaction active
  3551. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3552. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3553. {
  3554. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3555. {
  3556. tempIndex = ((gun_index==2) ? 1: 0);
  3557. }
  3558. else
  3559. {
  3560. tempIndex = gun_index;
  3561. }
  3562. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3563. {
  3564. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  3565. {
  3566. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  3567. {
  3568. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3569. {
  3570. currentStatus = Preparing; //OCPP Status: Preparing
  3571. }
  3572. else
  3573. {
  3574. currentStatus = Available; //OCPP Status: Available
  3575. }
  3576. }
  3577. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3578. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3579. ) //S_PRECHARGE
  3580. {
  3581. currentStatus = Preparing; //OCPP Status: Preparing
  3582. }
  3583. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3584. {
  3585. currentStatus = Charging; //OCPP Status: Charging
  3586. }
  3587. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3588. {
  3589. currentStatus = Finishing; //OCPP Status: Finishing
  3590. }
  3591. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3592. {
  3593. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3594. }
  3595. 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
  3596. {
  3597. currentStatus = Unavailable; //OCPP Status: Unavailable
  3598. }
  3599. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3600. {
  3601. currentStatus = Faulted; //OCPP Status: Faulted
  3602. }
  3603. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3604. {
  3605. currentStatus = Reserved; //OCPP Status: Reserved
  3606. }
  3607. } //end of the same index
  3608. }//end of for CHAdeMO_QUANTITY
  3609. }
  3610. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3611. {
  3612. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3613. {
  3614. tempIndex = ((gun_index==2) ? 1: 0);
  3615. }
  3616. else
  3617. {
  3618. tempIndex = gun_index;
  3619. }
  3620. for (int index = 0; index < CCS_QUANTITY; index++)
  3621. {
  3622. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3623. {
  3624. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3625. {
  3626. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3627. {
  3628. currentStatus = Preparing; //OCPP Status: Preparing
  3629. }
  3630. else
  3631. {
  3632. currentStatus = Available; //OCPP Status: Available
  3633. }
  3634. }
  3635. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3636. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3637. ) //S_PRECHARGE
  3638. {
  3639. currentStatus = Preparing; //OCPP Status: Preparing
  3640. }
  3641. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3642. {
  3643. currentStatus = Charging; //OCPP Status: Charging
  3644. }
  3645. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3646. {
  3647. currentStatus = Finishing; //OCPP Status: Finishing
  3648. }
  3649. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3650. {
  3651. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3652. }
  3653. 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
  3654. {
  3655. currentStatus = Unavailable; //OCPP Status : Unavailable
  3656. }
  3657. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3658. {
  3659. currentStatus = Faulted; //OCPP Status: Faulted
  3660. }
  3661. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3662. {
  3663. currentStatus = Reserved; //OCPP Status: Reserved
  3664. }
  3665. } //end of the same index
  3666. } // end of for CCS_QUANTITY
  3667. }
  3668. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3669. {
  3670. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3671. {
  3672. tempIndex = ((gun_index==2) ? 1: 0);
  3673. }
  3674. else
  3675. {
  3676. tempIndex = gun_index;
  3677. }
  3678. for (int index = 0; index < GB_QUANTITY; index++)
  3679. {
  3680. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3681. {
  3682. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3683. {
  3684. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3685. {
  3686. currentStatus = Preparing; //OCPP Status: Preparing
  3687. }
  3688. else
  3689. {
  3690. currentStatus = Available; //OCPP Status: Available
  3691. }
  3692. }
  3693. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3694. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3695. ) //S_PRECHARGE
  3696. {
  3697. currentStatus = Preparing; //OCPP Status: Preparing
  3698. }
  3699. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3700. {
  3701. currentStatus = Charging; //OCPP Status: Charging
  3702. }
  3703. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3704. {
  3705. currentStatus = Finishing; //OCPP Status: Finishing
  3706. }
  3707. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3708. {
  3709. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3710. }
  3711. 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
  3712. {
  3713. currentStatus = Unavailable; //OCPP Status: Unavailable
  3714. }
  3715. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3716. {
  3717. currentStatus = Faulted; //OCPP Status: Faulted
  3718. }
  3719. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3720. {
  3721. currentStatus = Reserved; //OCPP Status: Reserved
  3722. }
  3723. } //end of the same index
  3724. } // end of for GB_QUANTITY
  3725. }
  3726. else if(gunType[gun_index] == GUN_TYPE_DO)
  3727. {
  3728. tempIndex = gun_index;
  3729. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3730. {
  3731. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3732. {
  3733. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3734. {
  3735. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3736. {
  3737. currentStatus = Preparing; //OCPP Status: Preparing
  3738. }
  3739. else
  3740. {
  3741. currentStatus = Available; //OCPP Status: Available
  3742. }
  3743. }
  3744. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3745. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3746. ) //S_PRECHARGE
  3747. {
  3748. currentStatus = Preparing; //OCPP Status: Preparing
  3749. }
  3750. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3751. {
  3752. currentStatus = Charging; //OCPP Status: Charging
  3753. }
  3754. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3755. {
  3756. currentStatus = Finishing; //OCPP Status: Finishing
  3757. }
  3758. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3759. {
  3760. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3761. }
  3762. 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
  3763. {
  3764. currentStatus = Unavailable; //OCPP Status: Unavailable
  3765. }
  3766. 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
  3767. {
  3768. currentStatus = Faulted; //OCPP Status: Faulted
  3769. }
  3770. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3771. {
  3772. currentStatus = Reserved; //OCPP Status: Reserved
  3773. }
  3774. } //end of the same index
  3775. }
  3776. }
  3777. else
  3778. {
  3779. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3780. {
  3781. tempIndex = 2;
  3782. }
  3783. else
  3784. {
  3785. tempIndex = gun_index;
  3786. }
  3787. for (int index = 0; index < AC_QUANTITY; index++)
  3788. {
  3789. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3790. {
  3791. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3792. {
  3793. 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))
  3794. {
  3795. currentStatus = Preparing; //OCPP Status: Preparing
  3796. }
  3797. else
  3798. {
  3799. currentStatus = Available; //OCPP Status: Available
  3800. }
  3801. }
  3802. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3803. {
  3804. currentStatus = Preparing; //OCPP Status: Preparing
  3805. }
  3806. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3807. {
  3808. currentStatus = Charging; //OCPP Status: Charging
  3809. }
  3810. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3811. {
  3812. currentStatus = Finishing; //OCPP Status: Finishing
  3813. }
  3814. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3815. {
  3816. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3817. }
  3818. 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
  3819. {
  3820. currentStatus = Unavailable; //OCPP Status: Unavailable
  3821. }
  3822. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3823. {
  3824. currentStatus = Faulted; //OCPP Status: Faulted
  3825. }
  3826. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3827. {
  3828. currentStatus = Reserved; //OCPP Status: Reserved
  3829. }
  3830. }//end of the same index
  3831. }//end of for AC_QUANTITY
  3832. }
  3833. //it's option
  3834. if((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) &&
  3835. !ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq)
  3836. {
  3837. isStateChanged = FALSE;
  3838. }
  3839. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  3840. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3841. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3842. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3843. random_uuid(guid);
  3844. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3845. , MESSAGE_TYPE_CALL
  3846. , guid
  3847. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3848. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3849. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3850. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3851. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3852. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3853. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3854. if((server_sign == TRUE) && isStateChanged)
  3855. {
  3856. LWS_Send(message);
  3857. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3858. 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*/)
  3859. {
  3860. //DEBUG_ERROR("statusNotification mapitem pass");
  3861. result = PASS;
  3862. }
  3863. }
  3864. else
  3865. {
  3866. result = PASS;
  3867. }
  3868. return result;
  3869. }
  3870. int sendStopTransactionRequest(int gun_index)
  3871. {
  3872. mtrace();
  3873. int result = FAIL;
  3874. //char message[1500]={0};
  3875. char guid[37]={0};
  3876. char tempdata[65]={0};
  3877. int tempIndex = 0;
  3878. char TempStopTransaction[256];
  3879. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  3880. //int idx_sample=0;
  3881. DEBUG_INFO("sendStopTransactionRequest \n");
  3882. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3883. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  3884. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3885. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3886. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3887. {
  3888. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3889. {
  3890. tempIndex = ((gun_index==2) ? 1: 0);
  3891. }
  3892. else
  3893. {
  3894. tempIndex = gun_index;
  3895. }
  3896. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3897. {
  3898. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3899. {
  3900. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3901. }
  3902. }// END OF CHAdeMO_QUANTITY
  3903. }
  3904. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3905. {
  3906. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3907. {
  3908. tempIndex = ((gun_index==2) ? 1: 0);
  3909. }
  3910. else
  3911. {
  3912. tempIndex = gun_index;
  3913. }
  3914. for (int index = 0; index < CCS_QUANTITY; index++)
  3915. {
  3916. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3917. {
  3918. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3919. }
  3920. }// END OF CCS_QUANTITY
  3921. }
  3922. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3923. {
  3924. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3925. {
  3926. tempIndex = ((gun_index==2) ? 1: 0);
  3927. }
  3928. else
  3929. {
  3930. tempIndex = gun_index;
  3931. }
  3932. for (int index = 0; index < GB_QUANTITY; index++)
  3933. {
  3934. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3935. {
  3936. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3937. }
  3938. }// END OF GB_QUANTITY
  3939. }
  3940. else if(gunType[gun_index] == GUN_TYPE_DO)
  3941. {
  3942. tempIndex = gun_index;
  3943. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3944. {
  3945. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3946. {
  3947. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3948. }
  3949. }// END OF GB_QUANTITY
  3950. }
  3951. else
  3952. {
  3953. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3954. {
  3955. tempIndex = 2;
  3956. }
  3957. else
  3958. {
  3959. tempIndex = gun_index;
  3960. }
  3961. for (int index = 0; index < AC_QUANTITY; index++)
  3962. {
  3963. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3964. {
  3965. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3966. }
  3967. }// END OF AC_QUANTITY
  3968. }
  3969. //====================================== Stop Transaction Time =====================================================
  3970. struct timeval tmnow;
  3971. struct tm *tm;
  3972. char buf[28];//, usec_buf[6];
  3973. gettimeofday(&tmnow, NULL);
  3974. time_t t;
  3975. t = time(NULL);
  3976. /*UTC time and date*/
  3977. tm = gmtime(&t);
  3978. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3979. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  3980. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  3981. random_uuid(guid);
  3982. /***********************************transactionData******************************************************/
  3983. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  3984. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  3985. //=================================
  3986. // Transaction_Begin
  3987. //=================================
  3988. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  3989. {
  3990. //============================================ Energy.Active.Import.Interval ================================
  3991. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  3992. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  3993. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  3994. 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*/]);
  3995. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3996. 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))
  3997. {
  3998. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  3999. }
  4000. else
  4001. {
  4002. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  4003. }
  4004. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  4005. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4006. }
  4007. //=================================
  4008. // Transaction_End
  4009. //=================================
  4010. // ================================= Current.Import L1 ===============================================
  4011. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4012. {
  4013. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  4014. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4015. {
  4016. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4017. {
  4018. tempIndex = ((gun_index==2) ? 1: 0);
  4019. }
  4020. else
  4021. {
  4022. tempIndex = gun_index;
  4023. }
  4024. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4025. {
  4026. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4027. {
  4028. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4029. }
  4030. }// End of for CHAdeMO_QUANTITY
  4031. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4032. }
  4033. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4034. {
  4035. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4036. {
  4037. tempIndex = ((gun_index==2) ? 1: 0);
  4038. }
  4039. else
  4040. {
  4041. tempIndex = gun_index;
  4042. }
  4043. for (int index = 0; index < CCS_QUANTITY; index++)
  4044. {
  4045. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4046. {
  4047. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4048. }
  4049. }// End of for CCS_QUANTITY
  4050. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4051. }
  4052. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4053. {
  4054. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4055. {
  4056. tempIndex = ((gun_index==2) ? 1: 0);
  4057. }
  4058. else
  4059. {
  4060. tempIndex = gun_index;
  4061. }
  4062. for (int index = 0; index < GB_QUANTITY; index++)
  4063. {
  4064. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4065. {
  4066. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4067. }
  4068. }// End of for GB_QUANTITY
  4069. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4070. }
  4071. else if(gunType[gun_index] == GUN_TYPE_DO)
  4072. {
  4073. tempIndex = gun_index;
  4074. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4075. {
  4076. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4077. {
  4078. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4079. }
  4080. }
  4081. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4082. }
  4083. else
  4084. {
  4085. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4086. {
  4087. tempIndex = 2;
  4088. }
  4089. else
  4090. {
  4091. tempIndex = gun_index;
  4092. }
  4093. for (int index = 0; index < AC_QUANTITY; index++)
  4094. {
  4095. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4096. {
  4097. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  4098. }
  4099. }// End of for AC_QUANTITY
  4100. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  4101. }
  4102. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4103. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  4104. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  4105. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  4106. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4107. }
  4108. // ================================= Energy.Active.Import.Interval ==============================================
  4109. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4110. {
  4111. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4112. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4113. {
  4114. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4115. {
  4116. tempIndex = ((gun_index==2) ? 1: 0);
  4117. }
  4118. else
  4119. {
  4120. tempIndex = gun_index;
  4121. }
  4122. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4123. {
  4124. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4125. {
  4126. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4127. }
  4128. }// END OF CHAdeMO_QUANTITY
  4129. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4130. }
  4131. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4132. {
  4133. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4134. {
  4135. tempIndex = ((gun_index==2) ? 1: 0);
  4136. }
  4137. else
  4138. {
  4139. tempIndex = gun_index;
  4140. }
  4141. for (int index = 0; index < CCS_QUANTITY; index++)
  4142. {
  4143. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4144. {
  4145. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4146. }
  4147. }// END OF CCS_QUANTITY
  4148. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4149. }
  4150. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4151. {
  4152. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4153. {
  4154. tempIndex = ((gun_index==2) ? 1: 0);
  4155. }
  4156. else
  4157. {
  4158. tempIndex = gun_index;
  4159. }
  4160. for (int index = 0; index < GB_QUANTITY; index++)
  4161. {
  4162. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4163. {
  4164. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4165. }
  4166. }// END OF GB_QUANTITY
  4167. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4168. }
  4169. else if(gunType[gun_index] == GUN_TYPE_DO)
  4170. {
  4171. tempIndex = gun_index;
  4172. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4173. {
  4174. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4175. {
  4176. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4177. }
  4178. }
  4179. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4180. }
  4181. else
  4182. {
  4183. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4184. {
  4185. tempIndex = 2;
  4186. }
  4187. else
  4188. {
  4189. tempIndex = gun_index;
  4190. }
  4191. for (int index = 0; index < AC_QUANTITY; index++)
  4192. {
  4193. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4194. {
  4195. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4196. }
  4197. }// END OF AC_QUANTITY
  4198. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  4199. }
  4200. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4201. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  4202. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  4203. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  4204. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4205. }
  4206. //=================================== Power.Active.Import ==================================================
  4207. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  4208. {
  4209. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4210. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4211. {
  4212. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4213. {
  4214. tempIndex = ((gun_index==2) ? 1: 0);
  4215. }
  4216. else
  4217. {
  4218. tempIndex = gun_index;
  4219. }
  4220. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4221. {
  4222. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4223. {
  4224. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4225. }
  4226. } // End for CHAdeMO_QUANTITY
  4227. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4228. }
  4229. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4230. {
  4231. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4232. {
  4233. tempIndex = ((gun_index==2) ? 1: 0);
  4234. }
  4235. else
  4236. {
  4237. tempIndex = gun_index;
  4238. }
  4239. for (int index = 0; index < CCS_QUANTITY; index++)
  4240. {
  4241. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4242. {
  4243. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4244. }
  4245. } // END for CCS_QUANTITY
  4246. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4247. }
  4248. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4249. {
  4250. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4251. {
  4252. tempIndex = ((gun_index==2) ? 1: 0);
  4253. }
  4254. else
  4255. {
  4256. tempIndex = gun_index;
  4257. }
  4258. for (int index = 0; index < GB_QUANTITY; index++)
  4259. {
  4260. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4261. {
  4262. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4263. }
  4264. }// END for GB_QUANTITY
  4265. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4266. }
  4267. else if(gunType[gun_index] == GUN_TYPE_DO)
  4268. {
  4269. tempIndex = gun_index;
  4270. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4271. {
  4272. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4273. {
  4274. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4275. }
  4276. }
  4277. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4278. }
  4279. else
  4280. {
  4281. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4282. {
  4283. tempIndex = 2;
  4284. }
  4285. else
  4286. {
  4287. tempIndex = gun_index;
  4288. }
  4289. for (int index = 0; index < AC_QUANTITY; index++)
  4290. {
  4291. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4292. {
  4293. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4294. }
  4295. } // END for AC_QUANTITY
  4296. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  4297. }
  4298. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4299. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  4300. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  4301. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  4302. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  4303. }
  4304. //============================ Voltage L1 ====================================
  4305. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4306. {
  4307. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4308. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4309. {
  4310. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4311. {
  4312. tempIndex = ((gun_index==2) ? 1: 0);
  4313. }
  4314. else
  4315. {
  4316. tempIndex = gun_index;
  4317. }
  4318. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4319. {
  4320. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4321. {
  4322. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4323. }
  4324. } // END OF FOR CHAdeMO_QUANTITY
  4325. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4326. }
  4327. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4328. {
  4329. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4330. {
  4331. tempIndex = ((gun_index==2) ? 1: 0);
  4332. }
  4333. else
  4334. {
  4335. tempIndex = gun_index;
  4336. }
  4337. for (int index = 0; index < CCS_QUANTITY; index++)
  4338. {
  4339. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4340. {
  4341. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4342. }
  4343. } // END OF FOR CCS_QUANTITY
  4344. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4345. }
  4346. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4347. {
  4348. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4349. {
  4350. tempIndex = ((gun_index==2) ? 1: 0);
  4351. }
  4352. else
  4353. {
  4354. tempIndex = gun_index;
  4355. }
  4356. for (int index = 0; index < GB_QUANTITY; index++)
  4357. {
  4358. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4359. {
  4360. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4361. }
  4362. } // END OF FOR GB_QUANTITY
  4363. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4364. }
  4365. else if(gunType[gun_index] == GUN_TYPE_DO)
  4366. {
  4367. tempIndex = gun_index;
  4368. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4369. {
  4370. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4371. {
  4372. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4373. }
  4374. }
  4375. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4376. }
  4377. else
  4378. {
  4379. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4380. {
  4381. tempIndex = 2;
  4382. }
  4383. else
  4384. {
  4385. tempIndex = gun_index;
  4386. }
  4387. for (int index = 0; index < AC_QUANTITY; index++)
  4388. {
  4389. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4390. {
  4391. 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
  4392. }
  4393. } // END OF FOR AC_QUANTITY
  4394. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  4395. }
  4396. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4397. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  4398. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  4399. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  4400. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4401. }
  4402. //====================== End SoC ================================
  4403. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4404. {
  4405. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4406. 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))
  4407. {
  4408. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4409. {
  4410. tempIndex = ((gun_index==2) ? 1: 0);
  4411. }
  4412. else
  4413. {
  4414. tempIndex = gun_index;
  4415. }
  4416. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4417. {
  4418. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4419. {
  4420. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4421. {
  4422. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  4423. }
  4424. }
  4425. }
  4426. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4427. {
  4428. for (int index = 0; index < CCS_QUANTITY; index++)
  4429. {
  4430. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4431. {
  4432. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  4433. }
  4434. }
  4435. }
  4436. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4437. {
  4438. for (int index = 0; index < GB_QUANTITY; index++)
  4439. {
  4440. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4441. {
  4442. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  4443. }
  4444. }
  4445. }
  4446. else if(gunType[gun_index] == GUN_TYPE_DO)
  4447. {
  4448. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4449. {
  4450. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4451. {
  4452. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  4453. }
  4454. }
  4455. }
  4456. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4457. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  4458. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4459. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  4460. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  4461. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4462. } // END FOR DC CASE
  4463. }
  4464. // ================================= Current.Import L2 ===============================================
  4465. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4466. {
  4467. // AC 3 phse L2 current
  4468. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4469. {
  4470. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4471. {
  4472. tempIndex = 2;
  4473. }
  4474. else
  4475. {
  4476. tempIndex = gun_index;
  4477. }
  4478. for (int index = 0; index < AC_QUANTITY; index++)
  4479. {
  4480. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4481. {
  4482. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  4483. }
  4484. }// End of for AC_QUANTITY
  4485. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  4486. }
  4487. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4488. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  4489. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  4490. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  4491. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4492. }
  4493. // ================================= Current.Import L3 ===============================================
  4494. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4495. {
  4496. // AC 3 phse L3 current
  4497. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4498. {
  4499. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4500. {
  4501. tempIndex = 2;
  4502. }
  4503. else
  4504. {
  4505. tempIndex = gun_index;
  4506. }
  4507. for (int index = 0; index < AC_QUANTITY; index++)
  4508. {
  4509. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4510. {
  4511. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  4512. }
  4513. }// End of for AC_QUANTITY
  4514. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  4515. }
  4516. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4517. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  4518. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  4519. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  4520. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4521. }
  4522. //============================ Voltage L2 ====================================
  4523. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4524. {
  4525. // AC 3 phse L2 voltage
  4526. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4527. {
  4528. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4529. {
  4530. tempIndex = 2;
  4531. }
  4532. else
  4533. {
  4534. tempIndex = gun_index;
  4535. }
  4536. for (int index = 0; index < AC_QUANTITY; index++)
  4537. {
  4538. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4539. {
  4540. 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
  4541. }
  4542. } // END OF FOR AC_QUANTITY
  4543. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  4544. }
  4545. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4546. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  4547. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  4548. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  4549. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4550. }
  4551. //============================ Voltage L3 ====================================
  4552. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4553. {
  4554. // AC 3 phse L3 voltage
  4555. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4556. {
  4557. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4558. {
  4559. tempIndex = 2;
  4560. }
  4561. else
  4562. {
  4563. tempIndex = gun_index;
  4564. }
  4565. for (int index = 0; index < AC_QUANTITY; index++)
  4566. {
  4567. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4568. {
  4569. 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
  4570. }
  4571. } // END OF FOR AC_QUANTITY
  4572. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  4573. }
  4574. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4575. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  4576. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  4577. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  4578. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4579. }
  4580. //====================== Start SoC ================================
  4581. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4582. {
  4583. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4584. 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))
  4585. {
  4586. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4587. {
  4588. tempIndex = ((gun_index==2) ? 1: 0);
  4589. }
  4590. else
  4591. {
  4592. tempIndex = gun_index;
  4593. }
  4594. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4595. {
  4596. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4597. {
  4598. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4599. {
  4600. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  4601. }
  4602. }
  4603. }
  4604. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4605. {
  4606. for (int index = 0; index < CCS_QUANTITY; index++)
  4607. {
  4608. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4609. {
  4610. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  4611. }
  4612. }
  4613. }
  4614. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4615. {
  4616. for (int index = 0; index < GB_QUANTITY; index++)
  4617. {
  4618. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4619. {
  4620. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  4621. }
  4622. }
  4623. }
  4624. else if(gunType[gun_index] == GUN_TYPE_DO)
  4625. {
  4626. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4627. {
  4628. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4629. {
  4630. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  4631. }
  4632. }
  4633. }
  4634. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4635. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  4636. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4637. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  4638. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  4639. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4640. } // END FOR DC CASE
  4641. }
  4642. //================================================ Message create ====================================================
  4643. json_object *StopTransaction = json_object_new_object();
  4644. json_object *transactionDatas = json_object_new_array();
  4645. json_object *sampledValues = json_object_new_array();
  4646. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  4647. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  4648. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  4649. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  4650. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  4651. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  4652. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  4653. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  4654. {
  4655. json_object *transactionData = json_object_new_object();
  4656. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  4657. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  4658. {
  4659. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  4660. {
  4661. json_object *sampledValue = json_object_new_object();
  4662. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  4663. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  4664. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  4665. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  4666. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  4667. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  4668. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  4669. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  4670. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  4671. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  4672. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  4673. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  4674. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  4675. json_object_array_add(sampledValues, sampledValue);
  4676. }
  4677. }
  4678. json_object_object_add(transactionData, "sampledValue", sampledValues);
  4679. json_object_array_add(transactionDatas, transactionData);
  4680. }
  4681. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  4682. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  4683. ,MESSAGE_TYPE_CALL
  4684. ,guid
  4685. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  4686. json_object_put(StopTransaction);
  4687. #if 1 // for TempStopTransaction
  4688. //Delete TempStopTransaction
  4689. if((access(TempStopTransaction,F_OK))!=-1)
  4690. {
  4691. remove(TempStopTransaction); // remove file "TempStopTransaction"
  4692. }
  4693. #endif
  4694. #if 1
  4695. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4696. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4697. {
  4698. result = PASS;
  4699. //DEBUG_INFO("StopTransaction mapitem pass\n");
  4700. }
  4701. #endif
  4702. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4703. OCPP_insert_transaction_msg(NO, queuedata);
  4704. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4705. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4706. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  4707. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4708. {
  4709. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4710. }
  4711. //for test
  4712. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4713. return result;
  4714. }
  4715. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4716. {
  4717. mtrace();
  4718. int result = FAIL;
  4719. char guid[37]={0};
  4720. char tempdata[65]={0};
  4721. int tempIndex = 0;
  4722. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4723. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4724. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  4725. //set value
  4726. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4727. 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) )?
  4728. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  4729. -1);
  4730. random_uuid(guid);
  4731. //UTC Date time
  4732. struct timeval tmnow;
  4733. struct tm *tm;
  4734. char buf[28];//, usec_buf[6];
  4735. gettimeofday(&tmnow, NULL);
  4736. time_t t;
  4737. t = time(NULL);
  4738. /*UTC time and date*/
  4739. tm = gmtime(&t);
  4740. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4741. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4742. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4743. //********************************(1)Current.Import L1************************************************/
  4744. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  4745. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  4746. (dataType == ReadingContext_Trigger))
  4747. {
  4748. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4749. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4750. {
  4751. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4752. {
  4753. tempIndex = ((gun_index==2) ? 1: 0);
  4754. }
  4755. else
  4756. {
  4757. tempIndex = gun_index;
  4758. }
  4759. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4760. {
  4761. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4762. {
  4763. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4764. }
  4765. }
  4766. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4767. }
  4768. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4769. {
  4770. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4771. {
  4772. tempIndex = ((gun_index==2) ? 1: 0);
  4773. }
  4774. else
  4775. {
  4776. tempIndex = gun_index;
  4777. }
  4778. for (int index = 0; index < CCS_QUANTITY; index++)
  4779. {
  4780. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4781. {
  4782. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4783. }
  4784. }
  4785. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4786. }
  4787. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4788. {
  4789. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4790. {
  4791. tempIndex = ((gun_index==2) ? 1: 0);
  4792. }
  4793. else
  4794. {
  4795. tempIndex = gun_index;
  4796. }
  4797. for (int index = 0; index < GB_QUANTITY; index++)
  4798. {
  4799. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4800. {
  4801. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4802. }
  4803. }
  4804. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4805. }
  4806. else if(gunType[gun_index] == GUN_TYPE_DO)
  4807. {
  4808. tempIndex = gun_index;
  4809. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4810. {
  4811. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4812. {
  4813. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  4814. }
  4815. }
  4816. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4817. }
  4818. else
  4819. {
  4820. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4821. {
  4822. tempIndex = 2;
  4823. }
  4824. else
  4825. {
  4826. tempIndex = gun_index;
  4827. }
  4828. for (int index = 0; index < AC_QUANTITY; index++)
  4829. {
  4830. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4831. {
  4832. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4833. }
  4834. }
  4835. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4836. }
  4837. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4838. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4839. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4840. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4841. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4842. }
  4843. //********************************(2)Energy.Active.Import.Register ************************************************/
  4844. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4845. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4846. (dataType == ReadingContext_Trigger))
  4847. {
  4848. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4849. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4850. {
  4851. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4852. {
  4853. tempIndex = ((gun_index==2) ? 1: 0);
  4854. }
  4855. else
  4856. {
  4857. tempIndex = gun_index;
  4858. }
  4859. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4860. {
  4861. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4862. {
  4863. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4864. }
  4865. }
  4866. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4867. }
  4868. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4869. {
  4870. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4871. {
  4872. tempIndex = ((gun_index==2) ? 1: 0);
  4873. }
  4874. else
  4875. {
  4876. tempIndex = gun_index;
  4877. }
  4878. for (int index = 0; index < CCS_QUANTITY; index++)
  4879. {
  4880. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4881. {
  4882. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4883. }
  4884. }
  4885. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4886. }
  4887. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4888. {
  4889. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4890. {
  4891. tempIndex = ((gun_index==2) ? 1: 0);
  4892. }
  4893. else
  4894. {
  4895. tempIndex = gun_index;
  4896. }
  4897. for (int index = 0; index < GB_QUANTITY; index++)
  4898. {
  4899. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4900. {
  4901. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4902. }
  4903. }
  4904. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4905. }
  4906. else if(gunType[gun_index] == GUN_TYPE_DO)
  4907. {
  4908. tempIndex = gun_index;
  4909. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4910. {
  4911. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4912. {
  4913. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  4914. }
  4915. }
  4916. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4917. }
  4918. else
  4919. {
  4920. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4921. {
  4922. tempIndex = 2;
  4923. }
  4924. else
  4925. {
  4926. tempIndex = gun_index;
  4927. }
  4928. for (int index = 0; index < AC_QUANTITY; index++)
  4929. {
  4930. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4931. {
  4932. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4933. }
  4934. }
  4935. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4936. }
  4937. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  4938. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4939. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4940. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4941. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4942. }
  4943. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  4944. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  4945. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  4946. (dataType == ReadingContext_Trigger))
  4947. {
  4948. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4949. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4950. {
  4951. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4952. {
  4953. tempIndex = ((gun_index==2) ? 1: 0);
  4954. }
  4955. else
  4956. {
  4957. tempIndex = gun_index;
  4958. }
  4959. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4960. {
  4961. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4962. {
  4963. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4964. }
  4965. } // END OF FOR CHAdeMO_QUANTITY
  4966. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4967. }
  4968. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4969. {
  4970. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4971. {
  4972. tempIndex = ((gun_index==2) ? 1: 0);
  4973. }
  4974. else
  4975. {
  4976. tempIndex = gun_index;
  4977. }
  4978. for (int index = 0; index < CCS_QUANTITY; index++)
  4979. {
  4980. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4981. {
  4982. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  4983. }
  4984. } // END OF CCS_QUANTITY
  4985. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4986. }
  4987. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4988. {
  4989. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4990. {
  4991. tempIndex = ((gun_index==2) ? 1: 0);
  4992. }
  4993. else
  4994. {
  4995. tempIndex = gun_index;
  4996. }
  4997. for (int index = 0; index < GB_QUANTITY; index++)
  4998. {
  4999. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5000. {
  5001. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  5002. }
  5003. } // END OF GB_QUANTITY
  5004. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5005. }
  5006. else if(gunType[gun_index] == GUN_TYPE_DO)
  5007. {
  5008. tempIndex = gun_index;
  5009. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5010. {
  5011. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5012. {
  5013. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  5014. }
  5015. }
  5016. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5017. }
  5018. else
  5019. {
  5020. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5021. {
  5022. tempIndex = 2;
  5023. }
  5024. else
  5025. {
  5026. tempIndex = gun_index;
  5027. }
  5028. for (int index = 0; index < AC_QUANTITY; index++)
  5029. {
  5030. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5031. {
  5032. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  5033. }
  5034. }
  5035. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  5036. }
  5037. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  5038. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  5039. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  5040. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  5041. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5042. }
  5043. //********************************(4)Power.Active.Import************************************************/
  5044. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Power.Active.Import") != NULL)) ||
  5045. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Power.Active.Import") != NULL)) ||
  5046. (dataType == ReadingContext_Trigger))
  5047. {
  5048. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5049. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5050. {
  5051. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5052. {
  5053. tempIndex = ((gun_index==2) ? 1: 0);
  5054. }
  5055. else
  5056. {
  5057. tempIndex = gun_index;
  5058. }
  5059. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5060. {
  5061. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5062. {
  5063. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  5064. }
  5065. } // END OF FOR
  5066. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5067. }
  5068. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5069. {
  5070. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5071. {
  5072. tempIndex = ((gun_index==2) ? 1: 0);
  5073. }
  5074. else
  5075. {
  5076. tempIndex = gun_index;
  5077. }
  5078. for (int index = 0; index < CCS_QUANTITY; index++)
  5079. {
  5080. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5081. {
  5082. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  5083. }
  5084. }
  5085. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5086. }
  5087. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5088. {
  5089. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5090. {
  5091. tempIndex = ((gun_index==2) ? 1: 0);
  5092. }
  5093. else
  5094. {
  5095. tempIndex = gun_index;
  5096. }
  5097. for (int index = 0; index < GB_QUANTITY; index++)
  5098. {
  5099. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5100. {
  5101. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5102. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  5103. }
  5104. }
  5105. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5106. }
  5107. else if(gunType[gun_index] == GUN_TYPE_DO)
  5108. {
  5109. tempIndex = gun_index;
  5110. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5111. {
  5112. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5113. {
  5114. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5115. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  5116. }
  5117. }
  5118. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5119. }
  5120. else
  5121. {
  5122. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5123. {
  5124. tempIndex = 2;
  5125. }
  5126. else
  5127. {
  5128. tempIndex = gun_index;
  5129. }
  5130. for (int index = 0; index < AC_QUANTITY; index++)
  5131. {
  5132. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5133. {
  5134. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  5135. }
  5136. }
  5137. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  5138. }
  5139. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  5140. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  5141. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  5142. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  5143. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  5144. }
  5145. //***********************************************(5)VOLTAGE L1******************************************************/
  5146. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5147. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5148. (dataType == ReadingContext_Trigger))
  5149. {
  5150. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5151. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5152. {
  5153. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5154. {
  5155. tempIndex = ((gun_index==2) ? 1: 0);
  5156. }
  5157. else
  5158. {
  5159. tempIndex = gun_index;
  5160. }
  5161. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5162. {
  5163. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5164. {
  5165. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  5166. }
  5167. }
  5168. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5169. }
  5170. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5171. {
  5172. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5173. {
  5174. tempIndex = ((gun_index==2) ? 1: 0);
  5175. }
  5176. else
  5177. {
  5178. tempIndex = gun_index;
  5179. }
  5180. for (int index = 0; index < CCS_QUANTITY; index++)
  5181. {
  5182. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5183. {
  5184. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  5185. }
  5186. }
  5187. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5188. }
  5189. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5190. {
  5191. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5192. {
  5193. tempIndex = ((gun_index==2) ? 1: 0);
  5194. }
  5195. else
  5196. {
  5197. tempIndex = gun_index;
  5198. }
  5199. for (int index = 0; index < GB_QUANTITY; index++)
  5200. {
  5201. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5202. {
  5203. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  5204. }
  5205. }
  5206. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5207. }
  5208. else if(gunType[gun_index] == GUN_TYPE_DO)
  5209. {
  5210. tempIndex = gun_index;
  5211. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5212. {
  5213. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5214. {
  5215. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  5216. }
  5217. }
  5218. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5219. }
  5220. else
  5221. {
  5222. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5223. {
  5224. tempIndex = 2;
  5225. }
  5226. else
  5227. {
  5228. tempIndex = gun_index;
  5229. }
  5230. for (int index = 0; index < AC_QUANTITY; index++)
  5231. {
  5232. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5233. {
  5234. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  5235. }
  5236. }
  5237. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  5238. }
  5239. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  5240. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  5241. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  5242. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  5243. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5244. }
  5245. //***********************************************(6)SOC******************************************************/
  5246. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "SOC") != NULL)) ||
  5247. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "SOC") != NULL)) ||
  5248. (dataType == ReadingContext_Trigger))
  5249. {
  5250. 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))
  5251. {
  5252. //idx_sample=5;
  5253. //sampledValue = NULL;
  5254. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5255. {
  5256. tempIndex = ((gun_index==2) ? 1: 0);
  5257. }
  5258. else
  5259. {
  5260. tempIndex = gun_index;
  5261. }
  5262. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5263. {
  5264. //tempIndex = ((gun_index==2) ? 1: 0);
  5265. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5266. {
  5267. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5268. {
  5269. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  5270. }
  5271. }
  5272. }
  5273. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5274. {
  5275. //tempIndex = ((gun_index==2) ? 1: 0);
  5276. for (int index = 0; index < CCS_QUANTITY; index++)
  5277. {
  5278. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5279. {
  5280. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  5281. }
  5282. }
  5283. }
  5284. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5285. {
  5286. //tempIndex = ((gun_index==2) ? 1: 0);
  5287. for (int index = 0; index < GB_QUANTITY; index++)
  5288. {
  5289. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5290. {
  5291. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  5292. }
  5293. }
  5294. }
  5295. else if(gunType[gun_index] == GUN_TYPE_DO)
  5296. {
  5297. //tempIndex = ((gun_index==2) ? 1: 0);
  5298. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5299. {
  5300. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5301. {
  5302. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  5303. }
  5304. }
  5305. }
  5306. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  5307. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  5308. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  5309. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  5310. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  5311. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  5312. }
  5313. }
  5314. //********************************(7)Current.Import L2************************************************/
  5315. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5316. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5317. (dataType == ReadingContext_Trigger))
  5318. {
  5319. // Only for AC 3 phase
  5320. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5321. {
  5322. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5323. {
  5324. tempIndex = 2;
  5325. }
  5326. else
  5327. {
  5328. tempIndex = gun_index;
  5329. }
  5330. for (int index = 0; index < AC_QUANTITY; index++)
  5331. {
  5332. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5333. {
  5334. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  5335. }
  5336. }
  5337. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  5338. }
  5339. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  5340. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  5341. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  5342. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  5343. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5344. }
  5345. //********************************(8)Current.Import L3************************************************/
  5346. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5347. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5348. (dataType == ReadingContext_Trigger))
  5349. {
  5350. // Only for AC 3 phase
  5351. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5352. {
  5353. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5354. {
  5355. tempIndex = 2;
  5356. }
  5357. else
  5358. {
  5359. tempIndex = gun_index;
  5360. }
  5361. for (int index = 0; index < AC_QUANTITY; index++)
  5362. {
  5363. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5364. {
  5365. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  5366. }
  5367. }
  5368. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  5369. }
  5370. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  5371. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  5372. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  5373. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  5374. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5375. }
  5376. //***********************************************(9)VOLTAGE L2******************************************************/
  5377. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5378. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5379. (dataType == ReadingContext_Trigger))
  5380. {
  5381. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5382. {
  5383. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5384. {
  5385. tempIndex = 2;
  5386. }
  5387. else
  5388. {
  5389. tempIndex = gun_index;
  5390. }
  5391. for (int index = 0; index < AC_QUANTITY; index++)
  5392. {
  5393. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5394. {
  5395. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  5396. }
  5397. }
  5398. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  5399. }
  5400. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  5401. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  5402. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  5403. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  5404. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5405. }
  5406. //***********************************************(10)VOLTAGE L3******************************************************/
  5407. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5408. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5409. (dataType == ReadingContext_Trigger))
  5410. {
  5411. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5412. {
  5413. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5414. {
  5415. tempIndex = 2;
  5416. }
  5417. else
  5418. {
  5419. tempIndex = gun_index;
  5420. }
  5421. for (int index = 0; index < AC_QUANTITY; index++)
  5422. {
  5423. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5424. {
  5425. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  5426. }
  5427. }
  5428. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  5429. }
  5430. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  5431. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  5432. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  5433. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  5434. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5435. }
  5436. // Message create ====================================================================================================
  5437. if(TRUE)
  5438. {
  5439. json_object *MeterValueReq = json_object_new_object();
  5440. json_object *MeterValues = json_object_new_array();
  5441. json_object *sampledValues = json_object_new_array();
  5442. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  5443. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  5444. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  5445. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  5446. {
  5447. json_object *MeterValue = json_object_new_object();
  5448. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  5449. {
  5450. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  5451. {
  5452. json_object *sampledValue = json_object_new_object();
  5453. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  5454. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  5455. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  5456. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  5457. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  5458. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  5459. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  5460. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  5461. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  5462. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  5463. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  5464. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  5465. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  5466. json_object_array_add(sampledValues, sampledValue);
  5467. }
  5468. }
  5469. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  5470. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  5471. json_object_array_add(MeterValues, MeterValue);
  5472. }
  5473. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  5474. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  5475. ,gun_index + 1
  5476. ,MESSAGE_TYPE_CALL
  5477. ,guid
  5478. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  5479. json_object_put(MeterValueReq);
  5480. }
  5481. // Put request guid to hash map
  5482. sprintf(tempdata, "MeterValues,%d", (gun_index));
  5483. 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*/)
  5484. {
  5485. result = PASS;
  5486. //DEBUG_INFO("MeterValues mapitem pass\n");
  5487. }
  5488. if((dataType != ReadingContext_Trigger) &&
  5489. (dataType != ReadingContext_Sample_Clock) &&
  5490. (ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1))
  5491. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  5492. else
  5493. {
  5494. if(FirstHeartBeat)
  5495. LWS_Send(queuedata +2);
  5496. }
  5497. return result;
  5498. }
  5499. int sendLogStatusNotificationRequest(char *status)
  5500. {
  5501. mtrace();
  5502. int result = PASS;
  5503. char message[4096]={0};
  5504. char guid[37]={0};
  5505. char tempdata[128]={0};
  5506. json_object *LogStatusNotification = json_object_new_object();
  5507. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  5508. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  5509. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  5510. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  5511. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  5512. random_uuid(guid);
  5513. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  5514. json_object_put(LogStatusNotification);
  5515. LWS_Send(message);
  5516. sprintf(tempdata, "LogStatusNotification,%d", 0);
  5517. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5518. {
  5519. result = PASS;
  5520. }
  5521. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  5522. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  5523. return result;
  5524. }
  5525. int sendSecurityEventNotificationRequest()
  5526. {
  5527. mtrace();
  5528. int result = PASS;
  5529. char message[4096]={0};
  5530. char guid[37]={0};
  5531. char tempdata[128]={0};
  5532. json_object *SecurityEventNotification = json_object_new_object();
  5533. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  5534. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  5535. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  5536. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  5537. random_uuid(guid);
  5538. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  5539. json_object_put(SecurityEventNotification);
  5540. LWS_Send(message);
  5541. sprintf(tempdata, "SecurityEventNotification,0");
  5542. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5543. {
  5544. result = PASS;
  5545. }
  5546. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  5547. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  5548. return result;
  5549. }
  5550. int sendSignCertificateRequest()
  5551. {
  5552. mtrace();
  5553. int result = PASS;
  5554. char message[4096]={0};
  5555. char guid[37]={0};
  5556. char tempdata[128]={0};
  5557. json_object *SignCertificate = json_object_new_object();
  5558. DEBUG_INFO("sendSignCertificateRequest...\n");
  5559. // Read csr file content
  5560. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  5561. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  5562. char *line = NULL;
  5563. size_t len = 0;
  5564. while(getline(&line, &len, fp) != -1)
  5565. {
  5566. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  5567. {
  5568. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  5569. }
  5570. }
  5571. fclose(fp);
  5572. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  5573. random_uuid(guid);
  5574. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  5575. json_object_put(SignCertificate);
  5576. LWS_Send(message);
  5577. sprintf(tempdata, "SignCertificate,0");
  5578. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5579. {
  5580. result = PASS;
  5581. }
  5582. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  5583. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  5584. return result;
  5585. }
  5586. int sendSignedFirmwareStatusNotificationRequest(char *status)
  5587. {
  5588. mtrace();
  5589. int result = PASS;
  5590. char message[110]={0};
  5591. char guid[37]={0};
  5592. char tempdata[65]={0};
  5593. json_object *FirmwareStatusNotification = json_object_new_object();
  5594. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  5595. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  5596. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  5597. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  5598. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  5599. random_uuid(guid);
  5600. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  5601. json_object_put(FirmwareStatusNotification);
  5602. LWS_Send(message);
  5603. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5604. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5605. {
  5606. result = PASS;
  5607. }
  5608. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  5609. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  5610. return result;
  5611. }
  5612. //==========================================
  5613. // send confirm routine
  5614. //==========================================
  5615. int sendCancelReservationConfirmation(char *uuid,char *payload)
  5616. {
  5617. mtrace();
  5618. int result = FAIL;
  5619. char message[100]={0};
  5620. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  5621. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5622. LWS_Send(message);
  5623. result = TRUE;
  5624. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  5625. return result;
  5626. }
  5627. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  5628. {
  5629. mtrace();
  5630. int result = FAIL;
  5631. char message[100]={0};
  5632. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  5633. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5634. LWS_Send(message);
  5635. result = TRUE;
  5636. return result;
  5637. }
  5638. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  5639. {
  5640. mtrace();
  5641. int result = FAIL;
  5642. char message[100]={0};
  5643. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  5644. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5645. LWS_Send(message);
  5646. result = TRUE;
  5647. return result;
  5648. }
  5649. int sendClearCacheConfirmation(char *uuid,char *payload)
  5650. {
  5651. mtrace();
  5652. int result = FAIL;
  5653. char message[500]={0};
  5654. DEBUG_INFO("sendClearCacheConfirmation...\n");
  5655. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5656. LWS_Send(message);
  5657. return result;
  5658. }
  5659. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  5660. {
  5661. mtrace();
  5662. int result = FAIL;
  5663. char message[500]={0};
  5664. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  5665. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5666. LWS_Send(message);
  5667. return result;
  5668. }
  5669. int sendDataTransferConfirmation(char *uuid,char *payload)
  5670. {
  5671. mtrace();
  5672. char statusStr[20]={0};
  5673. char dataStr[10]={0};
  5674. char sstr[20]={0};
  5675. int c = 0;
  5676. char *loc;
  5677. int result = FAIL;
  5678. DEBUG_INFO("sendDataTransferConfirmation...\n");
  5679. /**********************status**************************/
  5680. loc = strstr(payload, "status");
  5681. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5682. c = 0;
  5683. while (loc[3+strlen("status")+c] != '\"')
  5684. {
  5685. sstr[c] = loc[3+strlen("status")+c];
  5686. c++;
  5687. }
  5688. sstr[c] = '\0';
  5689. strcpy(statusStr, sstr);
  5690. /**********************data**************************/
  5691. loc = strstr(payload, "data");
  5692. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5693. c = 0;
  5694. while (loc[3+strlen("data")+c] != '\"')
  5695. {
  5696. sstr[c] = loc[3+strlen("data")+c];
  5697. c++;
  5698. }
  5699. sstr[c] = '\0';
  5700. strcpy(dataStr, sstr);
  5701. return result;
  5702. }
  5703. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  5704. {
  5705. mtrace();
  5706. int result = FAIL;
  5707. char message[1000]={0};
  5708. int CompositeScheduleIndex = 0;
  5709. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  5710. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  5711. if(nPeriod == 0)
  5712. {
  5713. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  5714. {
  5715. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  5716. ,MESSAGE_TYPE_CALLRESULT
  5717. ,uuid
  5718. ,payload
  5719. ,connectorIdInt);
  5720. }
  5721. else
  5722. {
  5723. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  5724. ,MESSAGE_TYPE_CALLRESULT
  5725. ,uuid
  5726. ,payload
  5727. ,connectorIdInt
  5728. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5729. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5730. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5731. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  5732. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  5733. }
  5734. }
  5735. else
  5736. {
  5737. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  5738. ,MESSAGE_TYPE_CALLRESULT
  5739. ,uuid
  5740. ,payload
  5741. ,connectorIdInt
  5742. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5743. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5744. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5745. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  5746. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  5747. {
  5748. if (idx_sample == 0)
  5749. {
  5750. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5751. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5752. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5753. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5754. }
  5755. else
  5756. {
  5757. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5758. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5759. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5760. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5761. }
  5762. }
  5763. sprintf(message + strlen(message), "]}}]");
  5764. }
  5765. LWS_Send(message);
  5766. result = TRUE;
  5767. return result;
  5768. }
  5769. int sendGetConfigurationConfirmation(char *uuid)
  5770. {
  5771. mtrace();
  5772. int result = FAIL;
  5773. int MaxKeySupported = 0;
  5774. int sentConfigurationNumber= 0;
  5775. int sentunConfigurationNumber= 0;
  5776. char message[4000]={0};
  5777. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5778. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5779. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5780. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5781. ,MESSAGE_TYPE_CALLRESULT
  5782. ,uuid );
  5783. //configuration key
  5784. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5785. {
  5786. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5787. {
  5788. if (sentConfigurationNumber == 0)
  5789. {
  5790. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5791. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5792. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5793. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5794. }
  5795. else
  5796. {
  5797. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5798. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5799. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5800. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5801. }
  5802. sentConfigurationNumber = sentConfigurationNumber + 1;
  5803. }
  5804. }
  5805. sprintf(message + strlen(message), "]");
  5806. if(UnknownKeynum != 0)
  5807. {
  5808. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5809. //unkown key
  5810. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5811. {
  5812. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5813. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5814. if(sentunConfigurationNumber == 0)
  5815. {
  5816. sprintf(message + strlen(message), "\"%s\""
  5817. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5818. }
  5819. else
  5820. {
  5821. sprintf(message + strlen(message), ",\"%s\""
  5822. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5823. }
  5824. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5825. }
  5826. sprintf(message + strlen(message), "]");
  5827. }
  5828. sprintf(message + strlen(message), "}]");
  5829. LWS_Send(message);
  5830. return result;
  5831. }
  5832. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5833. {
  5834. mtrace();
  5835. int result = FAIL;
  5836. char message[400]={0};
  5837. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5838. if(strcmp(payload,"")==0)
  5839. {
  5840. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5841. }
  5842. else
  5843. {
  5844. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5845. }
  5846. LWS_Send(message);
  5847. result = TRUE;
  5848. return result;
  5849. }
  5850. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5851. {
  5852. mtrace();
  5853. int result = FAIL;
  5854. char message[80]={0};
  5855. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5856. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  5857. LWS_Send(message);
  5858. result = TRUE;
  5859. return result;
  5860. }
  5861. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5862. {
  5863. mtrace();
  5864. int result = FAIL;
  5865. char message[80]={0};
  5866. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5867. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5868. LWS_Send(message);
  5869. result = TRUE;
  5870. return result;
  5871. }
  5872. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5873. {
  5874. mtrace();
  5875. int result = FAIL;
  5876. char message[80]={0};
  5877. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5878. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5879. LWS_Send(message);
  5880. result = TRUE;
  5881. return result;
  5882. }
  5883. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5884. {
  5885. mtrace();
  5886. int result = FAIL;
  5887. char message[80]={0};
  5888. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5889. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5890. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5891. LWS_Send(message);
  5892. result = TRUE;
  5893. return result;
  5894. }
  5895. int sendResetConfirmation(char *uuid,char *payload)
  5896. {
  5897. mtrace();
  5898. int result = FAIL;
  5899. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  5900. char message[80]={0};
  5901. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  5902. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5903. LWS_Send(message);
  5904. result = TRUE;
  5905. return result;
  5906. }
  5907. int sendSendLocalListConfirmation(char *uuid,char *payload)
  5908. {
  5909. mtrace();
  5910. int result = FAIL;
  5911. char message[500]={0};
  5912. // [ 3, "1571284266109", { "status": "Accepted" } ]
  5913. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5914. LWS_Send(message);
  5915. result = TRUE;
  5916. return result;
  5917. }
  5918. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  5919. {
  5920. mtrace();
  5921. int result = FAIL;
  5922. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  5923. char message[80]={0};
  5924. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  5925. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5926. LWS_Send(message);
  5927. result = TRUE;
  5928. return result;
  5929. }
  5930. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  5931. {
  5932. mtrace();
  5933. int result = FAIL;
  5934. char message[80]={0};
  5935. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  5936. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5937. LWS_Send(message);
  5938. result = TRUE;
  5939. return result;
  5940. }
  5941. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  5942. {
  5943. mtrace();
  5944. int result = FAIL;
  5945. char message[80]={0};
  5946. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5947. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  5948. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5949. LWS_Send(message);
  5950. result = TRUE;
  5951. return result;
  5952. }
  5953. int sendUpdateFirmwareConfirmation(char *uuid)
  5954. {
  5955. mtrace();
  5956. int result = FAIL;
  5957. char message[60]={0};
  5958. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5959. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  5960. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5961. LWS_Send(message);
  5962. result = TRUE;
  5963. return result;
  5964. }
  5965. int sendCertificateSignedConfirmation(char *uuid)
  5966. {
  5967. mtrace();
  5968. int result = PASS;
  5969. char message[4096]={0};
  5970. json_object *CertificateSigned = json_object_new_object();
  5971. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  5972. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  5973. sprintf(message,"[%d,\"%s\",%s]"
  5974. ,MESSAGE_TYPE_CALLRESULT
  5975. ,uuid
  5976. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  5977. json_object_put(CertificateSigned);
  5978. LWS_Send(message);
  5979. return result;
  5980. }
  5981. int sendDeleteCertificateConfirmation(char *uuid)
  5982. {
  5983. mtrace();
  5984. int result = PASS;
  5985. char message[4096]={0};
  5986. json_object *DeleteCertificate = json_object_new_object();
  5987. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  5988. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  5989. sprintf(message,"[%d,\"%s\",%s]"
  5990. ,MESSAGE_TYPE_CALLRESULT
  5991. ,uuid
  5992. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  5993. json_object_put(DeleteCertificate);
  5994. LWS_Send(message);
  5995. return result;
  5996. }
  5997. int sendExtendedTriggerMessageConfirmation(char *uuid)
  5998. {
  5999. mtrace();
  6000. int result = PASS;
  6001. char message[4096]={0};
  6002. json_object *ExtendedTriggerMessage = json_object_new_object();
  6003. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  6004. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  6005. sprintf(message,"[%d,\"%s\",%s]"
  6006. ,MESSAGE_TYPE_CALLRESULT
  6007. ,uuid
  6008. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  6009. json_object_put(ExtendedTriggerMessage);
  6010. LWS_Send(message);
  6011. return result;
  6012. }
  6013. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  6014. {
  6015. mtrace();
  6016. int result = PASS;
  6017. char message[4096]={0};
  6018. json_object *GetInstalledCertificateIds = json_object_new_object();
  6019. json_object *certificateHashDataDatas = json_object_new_array();
  6020. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  6021. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  6022. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  6023. {
  6024. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  6025. {
  6026. json_object *certificateHashData = json_object_new_object();
  6027. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  6028. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  6029. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  6030. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  6031. json_object_array_add(certificateHashDataDatas, certificateHashData);
  6032. }
  6033. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  6034. }
  6035. else
  6036. {
  6037. json_object_put(certificateHashDataDatas);
  6038. }
  6039. sprintf(message,"[%d,\"%s\",%s]"
  6040. ,MESSAGE_TYPE_CALLRESULT
  6041. ,uuid
  6042. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  6043. json_object_put(GetInstalledCertificateIds);
  6044. LWS_Send(message);
  6045. return result;
  6046. }
  6047. int sendGetLogConfirmation(char *uuid)
  6048. {
  6049. mtrace();
  6050. int result = PASS;
  6051. char message[4096]={0};
  6052. json_object *GetLog = json_object_new_object();
  6053. DEBUG_INFO("sendGetLogConfirmation...\n");
  6054. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  6055. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  6056. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  6057. sprintf(message,"[%d,\"%s\",%s]"
  6058. ,MESSAGE_TYPE_CALLRESULT
  6059. ,uuid
  6060. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  6061. json_object_put(GetLog);
  6062. LWS_Send(message);
  6063. return result;
  6064. }
  6065. int sendInstallCertificateConfirmation(char *uuid)
  6066. {
  6067. mtrace();
  6068. int result = PASS;
  6069. char message[4096]={0};
  6070. json_object *InstallCertificate = json_object_new_object();
  6071. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  6072. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  6073. sprintf(message,"[%d,\"%s\",%s]"
  6074. ,MESSAGE_TYPE_CALLRESULT
  6075. ,uuid
  6076. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  6077. json_object_put(InstallCertificate);
  6078. LWS_Send(message);
  6079. return result;
  6080. }
  6081. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  6082. {
  6083. mtrace();
  6084. int result = PASS;
  6085. char message[4096]={0};
  6086. json_object *SignedUpdateFirmware = json_object_new_object();
  6087. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  6088. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  6089. sprintf(message,"[%d,\"%s\",%s]"
  6090. ,MESSAGE_TYPE_CALLRESULT
  6091. ,uuid
  6092. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  6093. json_object_put(SignedUpdateFirmware);
  6094. LWS_Send(message);
  6095. return result;
  6096. }
  6097. int sendUnknownConfirmation(char *uuid)
  6098. {
  6099. mtrace();
  6100. int result = PASS;
  6101. char message[256]={0};
  6102. DEBUG_INFO("sendUnknownConfirmation...\n");
  6103. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  6104. LWS_Send(message);
  6105. return result;
  6106. }
  6107. //==========================================
  6108. // Handle server request routine Start
  6109. //==========================================
  6110. int handleCancelReservationRequest(char *uuid, char *payload)
  6111. {
  6112. mtrace();
  6113. int result = FAIL;
  6114. int gunNO = 0;
  6115. int reservationIdInt = -1;
  6116. char comfirmstr[20];
  6117. DEBUG_INFO("handleCancelReservationRequest...\n");
  6118. json_object *CancelReservation;
  6119. CancelReservation = json_tokener_parse(payload);
  6120. if(!is_error(CancelReservation))
  6121. {
  6122. // Required data
  6123. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  6124. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  6125. }
  6126. json_object_put(CancelReservation);
  6127. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  6128. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6129. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  6130. if(reservationIdInt != -1)
  6131. {
  6132. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6133. //check Transaction active
  6134. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6135. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6136. {
  6137. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  6138. {
  6139. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6140. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6141. if(gunType[2] == GUN_TYPE_CHAdeMO)
  6142. {
  6143. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  6144. }
  6145. else
  6146. {
  6147. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  6148. }
  6149. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6150. goto end;
  6151. }
  6152. }
  6153. for (int index = 0; index < CCS_QUANTITY; index++)
  6154. {
  6155. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  6156. {
  6157. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6158. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6159. if(gunType[2] == GUN_TYPE_CCS)
  6160. {
  6161. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  6162. }
  6163. else
  6164. {
  6165. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  6166. }
  6167. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6168. goto end;
  6169. }
  6170. }
  6171. for (int index = 0; index < GB_QUANTITY; index++)
  6172. {
  6173. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  6174. {
  6175. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6176. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6177. if(gunType[2] == GUN_TYPE_GBT)
  6178. {
  6179. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  6180. }
  6181. else
  6182. {
  6183. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  6184. }
  6185. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6186. goto end;
  6187. }
  6188. }
  6189. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6190. {
  6191. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  6192. {
  6193. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6194. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6195. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  6196. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6197. goto end;
  6198. }
  6199. }
  6200. for (int index = 0; index < AC_QUANTITY; index++)
  6201. {
  6202. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  6203. {
  6204. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6205. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6206. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6207. {
  6208. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  6209. }
  6210. else
  6211. {
  6212. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  6213. }
  6214. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6215. goto end;
  6216. }
  6217. }
  6218. }
  6219. //The reservationId does NOT match the reservationId
  6220. sendCancelReservationConfirmation(uuid, comfirmstr);
  6221. end:
  6222. // Fill in ocpp packet uuid
  6223. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  6224. return result;
  6225. }
  6226. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  6227. {
  6228. mtrace();
  6229. int result = FAIL;
  6230. int gunIndex = 0;
  6231. char typeStr[16]={0};
  6232. char comfirmstr[20];
  6233. int specificId = FALSE;
  6234. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  6235. json_object *ChangeAvailability;
  6236. ChangeAvailability = json_tokener_parse(payload);
  6237. if(!is_error(ChangeAvailability))
  6238. {
  6239. // Required data
  6240. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  6241. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  6242. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  6243. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  6244. }
  6245. json_object_put(ChangeAvailability);
  6246. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6247. {
  6248. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  6249. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  6250. }
  6251. else if(gunIndex == 0)
  6252. {
  6253. for(int i=0; i < gunTotalNumber; i++)
  6254. {
  6255. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  6256. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  6257. }
  6258. }
  6259. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6260. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6261. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  6262. {
  6263. specificId = TRUE;
  6264. }
  6265. if(specificId == FALSE)
  6266. goto end;
  6267. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  6268. {
  6269. //----------------------gunIndex is 0 ------------------------------------------------//
  6270. if(gunIndex == 0)
  6271. {
  6272. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6273. {
  6274. for(int i=0; i < gunTotalNumber; i++)
  6275. {
  6276. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6277. {
  6278. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  6279. {
  6280. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6281. {
  6282. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6283. goto end;
  6284. }
  6285. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6286. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6287. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6288. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6289. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6290. {
  6291. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6292. goto end;
  6293. }
  6294. }
  6295. }//END FOR CHAdeMO_QUANTITY
  6296. for (int index = 0; index < CCS_QUANTITY; index++)
  6297. {
  6298. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  6299. {
  6300. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  6301. {
  6302. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6303. goto end;
  6304. }
  6305. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6306. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6307. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6308. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6309. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6310. {
  6311. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6312. goto end;
  6313. }
  6314. }
  6315. }//END FOR CCS_QUANTITY
  6316. for (int index = 0; index < GB_QUANTITY; index++)
  6317. {
  6318. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  6319. {
  6320. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6321. {
  6322. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6323. goto end;
  6324. }
  6325. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6326. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6327. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6328. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6329. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6330. {
  6331. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6332. goto end;
  6333. }
  6334. }
  6335. }// END FOR GB_QUANTITY
  6336. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6337. {
  6338. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  6339. {
  6340. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6341. {
  6342. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6343. goto end;
  6344. }
  6345. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6346. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6347. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6348. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6349. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6350. {
  6351. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6352. goto end;
  6353. }
  6354. }
  6355. }// END FOR GENERAL_GUN_QUANTITY
  6356. for (int index = 0; index < AC_QUANTITY; index++)
  6357. {
  6358. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  6359. {
  6360. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6361. {
  6362. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6363. goto end;
  6364. }
  6365. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6366. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6367. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6368. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6369. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6370. {
  6371. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6372. goto end;
  6373. }
  6374. }
  6375. }//END FOR AC_QUANTITY
  6376. }// END FOR gunTotalNumber
  6377. }
  6378. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6379. {
  6380. for(int i=0; i < gunTotalNumber; i++)
  6381. {
  6382. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6383. {
  6384. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6385. goto end;
  6386. }
  6387. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6388. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  6389. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  6390. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  6391. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6392. {
  6393. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6394. goto end;
  6395. }
  6396. }
  6397. }
  6398. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6399. goto end;
  6400. }
  6401. //----------------------gunIndex is not 0 ------------------------------------------------//
  6402. //check Transaction active
  6403. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6404. {
  6405. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  6406. {
  6407. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  6408. {
  6409. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6410. goto end;
  6411. }
  6412. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6413. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6414. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6415. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6416. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6417. {
  6418. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6419. goto end;
  6420. }
  6421. else
  6422. {
  6423. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  6424. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6425. goto end;
  6426. }
  6427. }
  6428. }//END FOR CHAdeMO_QUANTITY
  6429. for (int index = 0; index < CCS_QUANTITY; index++)
  6430. {
  6431. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  6432. {
  6433. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  6434. {
  6435. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6436. goto end;
  6437. }
  6438. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6439. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6440. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6441. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6442. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6443. {
  6444. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6445. goto end;
  6446. }
  6447. else
  6448. {
  6449. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  6450. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6451. goto end;
  6452. }
  6453. }
  6454. }//END FOR CCS_QUANTITY
  6455. for (int index = 0; index < GB_QUANTITY; index++)
  6456. {
  6457. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  6458. {
  6459. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6460. {
  6461. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6462. goto end;
  6463. }
  6464. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6465. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6466. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6467. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6468. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6469. {
  6470. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6471. goto end;
  6472. }
  6473. else
  6474. {
  6475. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  6476. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6477. goto end;
  6478. }
  6479. }
  6480. }// END FOR GB_QUANTITY
  6481. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6482. {
  6483. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  6484. {
  6485. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6486. {
  6487. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6488. goto end;
  6489. }
  6490. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6491. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6492. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6493. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6494. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6495. {
  6496. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6497. goto end;
  6498. }
  6499. else
  6500. {
  6501. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  6502. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6503. goto end;
  6504. }
  6505. }
  6506. }// END FOR GENERAL_GUN_QUANTITY
  6507. for (int index = 0; index < AC_QUANTITY; index++)
  6508. {
  6509. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  6510. {
  6511. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6512. {
  6513. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6514. goto end;
  6515. }
  6516. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6517. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6518. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6519. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6520. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6521. {
  6522. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6523. goto end;
  6524. }
  6525. else
  6526. {
  6527. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  6528. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6529. goto end;
  6530. }
  6531. }
  6532. }//END FOR AC_QUANTITY
  6533. }//END FOR AvailabilityTypeStr[Inoperative]
  6534. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  6535. {
  6536. //----------------------gunIndex is 0 ------------------------------------------------//
  6537. if(gunIndex == 0)
  6538. {
  6539. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6540. {
  6541. for(int i=0; i < gunTotalNumber; i++)
  6542. {
  6543. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6544. {
  6545. 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
  6546. {
  6547. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6548. goto end;
  6549. }
  6550. }//END FOR CHAdeMO_QUANTITY
  6551. for (int index = 0; index < CCS_QUANTITY; index++)
  6552. {
  6553. 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
  6554. {
  6555. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6556. goto end;
  6557. }
  6558. }//END FOR CCS_QUANTITY
  6559. for (int index = 0; index < GB_QUANTITY; index++)
  6560. {
  6561. 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
  6562. {
  6563. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6564. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6565. goto end;
  6566. }
  6567. }// END FOR GB_QUANTITY
  6568. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6569. {
  6570. 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
  6571. {
  6572. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6573. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6574. goto end;
  6575. }
  6576. }// END FOR GENERAL_GUN_QUANTITY
  6577. for (int index = 0; index < AC_QUANTITY; index++)
  6578. {
  6579. 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
  6580. {
  6581. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6582. goto end;
  6583. }
  6584. }//END FOR CHAdeMO_QUANTITY
  6585. }// END FOR gunTotalNumber
  6586. }
  6587. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6588. {
  6589. for(int i=0; i < gunTotalNumber; i++)
  6590. {
  6591. for (int index = 0; index < AC_QUANTITY; index++)
  6592. {
  6593. 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
  6594. {
  6595. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6596. goto end;
  6597. }
  6598. }//END FOR CHAdeMO_QUANTITY
  6599. } // END FOR gunTotalNumber
  6600. }
  6601. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6602. goto end;
  6603. }
  6604. //----------------------gunIndex is not 0 ------------------------------------------------//
  6605. //check Transaction active
  6606. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6607. {
  6608. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6609. {
  6610. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6611. goto end;
  6612. }
  6613. }//END FOR CHAdeMO_QUANTITY
  6614. for (int index = 0; index < CCS_QUANTITY; index++)
  6615. {
  6616. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6617. {
  6618. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6619. goto end;
  6620. }
  6621. }//END FOR CCS_QUANTITY
  6622. for (int index = 0; index < GB_QUANTITY; index++)
  6623. {
  6624. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6625. {
  6626. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6627. goto end;
  6628. }
  6629. }// END FOR GB_QUANTITY
  6630. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6631. {
  6632. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6633. {
  6634. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6635. goto end;
  6636. }
  6637. }// END FOR GENERAL_GUN_QUANTITY
  6638. for (int index = 0; index < AC_QUANTITY; index++)
  6639. {
  6640. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6641. {
  6642. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6643. goto end;
  6644. }
  6645. }//END FOR AC_QUANTITY
  6646. }//END FOR AvailabilityTypeStr[Operative]
  6647. end:
  6648. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6649. {
  6650. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  6651. }
  6652. else
  6653. {
  6654. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  6655. }
  6656. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6657. {
  6658. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6659. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6660. }
  6661. else if(gunIndex == 0)
  6662. {
  6663. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6664. {
  6665. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  6666. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  6667. }
  6668. }
  6669. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  6670. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6671. return result;
  6672. }
  6673. int handleChangeConfigurationRequest(char *uuid, char *payload)
  6674. {
  6675. mtrace();
  6676. int result = FAIL;
  6677. char keystr[40]={0};
  6678. char valuestr[256]={0};
  6679. char comfirmstr[20]={0};
  6680. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  6681. json_object *ChangeConfiguration;
  6682. ChangeConfiguration = json_tokener_parse(payload);
  6683. if(!is_error(ChangeConfiguration))
  6684. {
  6685. // Required data
  6686. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  6687. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  6688. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  6689. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  6690. }
  6691. json_object_put(ChangeConfiguration);
  6692. if((uuid==NULL) || (payload ==NULL) )
  6693. {
  6694. DEBUG_ERROR("Payload is null\n");
  6695. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6696. }
  6697. else
  6698. {
  6699. int status = setKeyValue(keystr, valuestr);
  6700. switch(status)
  6701. {
  6702. case ConfigurationStatus_Accepted:
  6703. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  6704. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  6705. StoreConfigurationTable();
  6706. break;
  6707. case RebootRequired:
  6708. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  6709. StoreConfigurationTable();
  6710. break;
  6711. case NotSupported:
  6712. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  6713. break;
  6714. case ConfigurationStatus_Rejected:
  6715. default:
  6716. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6717. break;
  6718. }
  6719. }
  6720. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  6721. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  6722. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6723. {
  6724. ChageWebSocketPingInterval(atoi(valuestr));
  6725. }
  6726. if((strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6727. {
  6728. SetOcppConnStatus(FALSE);
  6729. }
  6730. return result;
  6731. }
  6732. int handleClearCacheRequest(char *uuid, char *payload)
  6733. {
  6734. mtrace();
  6735. int result = FAIL;
  6736. char comfirmstr[20];
  6737. char rmFileCmd[100]={0};
  6738. struct stat stats;
  6739. DEBUG_INFO("handleClearCacheRequest...\n");
  6740. stat("/Storage/OCPP", &stats);
  6741. // Check for directory existence
  6742. if (S_ISDIR(stats.st_mode) == 1)
  6743. {}
  6744. else
  6745. {
  6746. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  6747. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  6748. system(rmFileCmd);
  6749. }
  6750. if(OCPP_cleanLocalCache())
  6751. {
  6752. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  6753. }
  6754. else
  6755. {
  6756. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  6757. }
  6758. sendClearCacheConfirmation(uuid, comfirmstr);
  6759. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6760. return result;
  6761. }
  6762. int handleClearChargingProfileRequest(char *uuid, char *payload)
  6763. {
  6764. mtrace();
  6765. int result = FAIL;
  6766. int resultRename;
  6767. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  6768. char chargingProfilePurposeStr[26]={0};
  6769. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  6770. char tempchargingProfilePurposeStr[26]={0};
  6771. char str[100]={0};
  6772. char fname[200]={0};
  6773. char comfirmstr[20]={0};
  6774. char word[1600]={0};
  6775. int clearflag = FALSE;
  6776. int chargingProfileIdIsNULL = FALSE;
  6777. int connectorIsNULL = FALSE;
  6778. int chargingProfilePurposeIsNULL = FALSE;
  6779. int stackLevelIsNULL = FALSE;
  6780. //int GotoEnd = FALSE;
  6781. FILE *fptr1, *fptr2;
  6782. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  6783. int n_chargingProfile=0;
  6784. int isEmptyFile = FALSE;
  6785. char sLineWord[1600]={0};
  6786. char chargingProfiles[10][100]={0};
  6787. int ChargeProfileCount = 0;
  6788. int ch;
  6789. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  6790. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  6791. json_object *ClearChargingProfile;
  6792. ClearChargingProfile = json_tokener_parse(payload);
  6793. if(!is_error(ClearChargingProfile))
  6794. {
  6795. // Optional data
  6796. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  6797. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  6798. else
  6799. chargingProfileIdIsNULL = TRUE;
  6800. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  6801. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  6802. else
  6803. connectorIsNULL = TRUE;
  6804. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  6805. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  6806. else
  6807. chargingProfilePurposeIsNULL = TRUE;
  6808. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  6809. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  6810. else
  6811. stackLevelIsNULL = TRUE;
  6812. }
  6813. json_object_put(ClearChargingProfile);
  6814. if(connectorIsNULL == FALSE)
  6815. {
  6816. switch(connectorIdInt)
  6817. {
  6818. case 0:
  6819. if(chargingProfilePurposeIsNULL == TRUE)
  6820. {
  6821. int l = 0;
  6822. strcpy(fname, ChargePointMaxProfile_JSON);
  6823. if((access(fname,F_OK))!=-1)
  6824. {
  6825. strcpy(chargingProfiles[l], fname);
  6826. l = l + 1;
  6827. }
  6828. strcpy(fname, TxDefaultProfile_0_JSON);
  6829. if((access(fname,F_OK))!=-1)
  6830. {
  6831. strcpy(chargingProfiles[l], fname);
  6832. l = l + 1;
  6833. }
  6834. ChargeProfileCount = l;
  6835. }
  6836. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  6837. {
  6838. strcpy(fname, ChargePointMaxProfile_JSON);
  6839. if((access(fname,F_OK))!=-1)
  6840. {
  6841. strcpy(chargingProfiles[0], fname);
  6842. ChargeProfileCount = 1;
  6843. }
  6844. }
  6845. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6846. {
  6847. strcpy(fname, TxDefaultProfile_0_JSON);
  6848. if((access(fname,F_OK))!=-1)
  6849. {
  6850. strcpy(chargingProfiles[0], fname);
  6851. ChargeProfileCount = 1;
  6852. }
  6853. }
  6854. break;
  6855. default:
  6856. if(chargingProfilePurposeIsNULL == TRUE)
  6857. {
  6858. int m = 0;
  6859. memset(fname, 0, ARRAY_SIZE(fname));
  6860. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6861. if((access(fname,F_OK))!=-1)
  6862. {
  6863. strcpy(chargingProfiles[m], fname);
  6864. m = m + 1;
  6865. }
  6866. memset(fname, 0, ARRAY_SIZE(fname));
  6867. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6868. if((access(fname,F_OK))!=-1)
  6869. {
  6870. strcpy(chargingProfiles[m], fname);
  6871. m = m + 1;
  6872. }
  6873. ChargeProfileCount = m;
  6874. }
  6875. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6876. {
  6877. //strcpy(fname, TxDefaultProfile_1_JSON);
  6878. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6879. if((access(fname,F_OK))!=-1)
  6880. {
  6881. strcpy(chargingProfiles[0], fname);
  6882. ChargeProfileCount = 1;
  6883. }
  6884. }
  6885. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  6886. {
  6887. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6888. if((access(fname,F_OK))!=-1)
  6889. {
  6890. strcpy(chargingProfiles[0], fname);
  6891. ChargeProfileCount = 1;
  6892. }
  6893. //strcpy(fname, TxProfile_1_JSON);
  6894. }
  6895. //strcpy(fname, ChargePointMaxProfile_JSON );
  6896. break;
  6897. }
  6898. }
  6899. else // Check all Charging Profiles
  6900. {
  6901. int i = 0;
  6902. char fnametemp[200]={0};
  6903. ChargeProfileCount = 0;
  6904. //Check ChargePointMaxProfile.json exit
  6905. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  6906. {
  6907. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  6908. i = i + 1;
  6909. }
  6910. //Check TxDefaultProfile_0.json exit
  6911. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  6912. {
  6913. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  6914. i = i + 1;
  6915. }
  6916. //Check TxDefaultProfile_%d.json
  6917. for(int j=1; j <= gunTotalNumber; j++)
  6918. {
  6919. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6920. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  6921. if((access(fnametemp,F_OK))!=-1)
  6922. {
  6923. strcpy(chargingProfiles[i], fnametemp);
  6924. i = i + 1;
  6925. }
  6926. }
  6927. //Check TxProfile_%d.json
  6928. for(int j=1; j <= gunTotalNumber; j++)
  6929. {
  6930. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6931. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  6932. if((access(fnametemp,F_OK))!=-1)
  6933. {
  6934. strcpy(chargingProfiles[i], fnametemp);
  6935. i = i + 1;
  6936. }
  6937. }
  6938. ChargeProfileCount = i;
  6939. }// End connectorIsNULL is TRUE
  6940. if(ChargeProfileCount == 0)
  6941. {
  6942. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6943. goto end;
  6944. }
  6945. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  6946. {
  6947. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6948. goto end;
  6949. }
  6950. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  6951. {
  6952. memset(str, 0, ARRAY_SIZE(str));
  6953. // clear temp file
  6954. sprintf(str,"rm -f %s",temp);
  6955. system(str);
  6956. for(int k=0; k < ChargeProfileCount; k++)
  6957. {
  6958. memset(str, 0, ARRAY_SIZE(str));
  6959. //clear file in C
  6960. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6961. system(str);
  6962. }
  6963. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6964. goto end;
  6965. }
  6966. else if(connectorIsNULL == TRUE)
  6967. {
  6968. for(int k=0; k < ChargeProfileCount; k++)
  6969. {
  6970. fptr1 = fopen(chargingProfiles[k], "r");
  6971. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  6972. //Check Charging Profile Count
  6973. while(fscanf(fptr1, "%s", word) != EOF)
  6974. {
  6975. //DEBUG_INFO("word=%s\n",word);
  6976. if(strstr(word, "chargingProfileId")!= NULL)
  6977. {
  6978. //DEBUG_INFO("test chargingProfileId \n");
  6979. n_chargingProfile = n_chargingProfile + 1;
  6980. //DEBUG_INFO("chargingProfileId Found\n");
  6981. }
  6982. }
  6983. rewind(fptr1);
  6984. //search Charging Profile Element
  6985. //int i= 0;
  6986. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6987. {
  6988. json_object *tmpProfilee;
  6989. tmpProfilee = json_tokener_parse(sLineWord);
  6990. if(!is_error(tmpProfilee))
  6991. {
  6992. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  6993. {
  6994. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  6995. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  6996. }
  6997. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  6998. {
  6999. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7000. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7001. }
  7002. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7003. {
  7004. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7005. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7006. }
  7007. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7008. {
  7009. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7010. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7011. }
  7012. }
  7013. json_object_put(tmpProfilee);
  7014. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7015. {
  7016. //------- not write to fptr2-------//
  7017. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7018. //clearflag = TRUE;
  7019. }
  7020. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7021. {
  7022. //------- not write to fptr2-------//
  7023. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7024. }
  7025. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7026. {
  7027. //------- not write to fptr2-------//
  7028. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7029. }
  7030. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  7031. {
  7032. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7033. }
  7034. else
  7035. {
  7036. fprintf(fptr2, sLineWord);//writing data into file
  7037. }
  7038. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7039. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7040. if(clearflag == TRUE)
  7041. {
  7042. fclose(fptr1);
  7043. fclose(fptr2);
  7044. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7045. system(str);
  7046. // clear temp file
  7047. sprintf(str,"rm -f %s",temp);
  7048. system(str);
  7049. }
  7050. else
  7051. {
  7052. fclose(fptr1);
  7053. fclose(fptr2);
  7054. memset(str, 0, ARRAY_SIZE(str));
  7055. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7056. system(str);
  7057. resultRename = rename(temp, chargingProfiles[k]);
  7058. if(resultRename == 0)
  7059. {
  7060. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  7061. }
  7062. else
  7063. {
  7064. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  7065. }
  7066. if(comfirmstr[0]== 0)
  7067. {
  7068. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7069. }
  7070. //Check chargingProfile is empty file
  7071. /*------ Read the file ----------------*/
  7072. fptr1=fopen(chargingProfiles[k],"r");
  7073. ch=fgetc(fptr1);
  7074. rewind(fptr1);
  7075. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7076. if(ch!=EOF)
  7077. {
  7078. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7079. {
  7080. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7081. if(sLineWord[0]=='\0')
  7082. {
  7083. isEmptyFile = TRUE;
  7084. break;
  7085. }
  7086. else
  7087. {
  7088. isEmptyFile = FALSE;
  7089. break;
  7090. }
  7091. }
  7092. }
  7093. else
  7094. isEmptyFile = TRUE;
  7095. fclose(fptr1);
  7096. if(isEmptyFile == TRUE)
  7097. {
  7098. memset(str, 0, ARRAY_SIZE(str));
  7099. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7100. system(str);
  7101. }
  7102. }
  7103. }// End of while(int k=0; k < ChargePointCount; k++)
  7104. }
  7105. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  7106. {
  7107. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  7108. for(int k=0; k < ChargeProfileCount; k++)
  7109. {
  7110. fptr1 = fopen(chargingProfiles[k], "r");
  7111. fptr2 = fopen(temp, "w+");
  7112. //Check Charging Profile Count
  7113. while(fscanf(fptr1, "%s", word) != EOF)
  7114. {
  7115. //DEBUG_INFO("word=%s\n",word);
  7116. if(strstr(word, "chargingProfileId")!= NULL)
  7117. {
  7118. n_chargingProfile = n_chargingProfile + 1;
  7119. }
  7120. }
  7121. rewind(fptr1);
  7122. //search Charging Profile Element
  7123. //int i= 0;
  7124. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7125. {
  7126. json_object *tmpProfilee;
  7127. tmpProfilee = json_tokener_parse(sLineWord);
  7128. if(!is_error(tmpProfilee))
  7129. {
  7130. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7131. {
  7132. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7133. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7134. }
  7135. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7136. {
  7137. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7138. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7139. }
  7140. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7141. {
  7142. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7143. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7144. }
  7145. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7146. {
  7147. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7148. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7149. }
  7150. }
  7151. json_object_put(tmpProfilee);
  7152. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7153. {
  7154. //------- not write to fptr2-------//
  7155. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7156. //clearflag = TRUE;
  7157. }
  7158. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7159. {
  7160. //------- not write to fptr2-------//
  7161. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7162. }
  7163. else if(stackLevelIsNULL == TRUE)
  7164. {
  7165. //Clear Whole File
  7166. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7167. clearflag = TRUE;
  7168. break;
  7169. }
  7170. else
  7171. {
  7172. fprintf(fptr2, sLineWord);//writing data into file
  7173. }
  7174. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7175. }
  7176. if(clearflag == TRUE)
  7177. {
  7178. fclose(fptr1);
  7179. fclose(fptr2);
  7180. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7181. system(str);
  7182. // clear temp file
  7183. sprintf(str,"rm -f %s",temp);
  7184. system(str);
  7185. }
  7186. else
  7187. {
  7188. fclose(fptr1);
  7189. fclose(fptr2);
  7190. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7191. system(str);
  7192. resultRename = rename(temp, chargingProfiles[k]);
  7193. if(resultRename == 0)
  7194. {
  7195. DEBUG_INFO("File ChargingProfile renamed successfully");
  7196. }
  7197. else
  7198. {
  7199. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  7200. }
  7201. if(comfirmstr[0]== 0)
  7202. {
  7203. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7204. }
  7205. //Check chargingProfile is empty file
  7206. /*------ Read the file ----------------*/
  7207. fptr1=fopen(chargingProfiles[k],"r");
  7208. ch=fgetc(fptr1);
  7209. rewind(fptr1);
  7210. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7211. if(ch!=EOF)
  7212. {
  7213. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7214. {
  7215. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7216. if(sLineWord[0]=='\0')
  7217. {
  7218. isEmptyFile = TRUE;
  7219. break;
  7220. }
  7221. else
  7222. {
  7223. isEmptyFile = FALSE;
  7224. break;
  7225. }
  7226. }
  7227. }
  7228. else
  7229. isEmptyFile = TRUE;
  7230. fclose(fptr1);
  7231. if(isEmptyFile == TRUE)
  7232. {
  7233. memset(str, 0, ARRAY_SIZE(str));
  7234. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7235. system(str);
  7236. }
  7237. /*------- End of reading ---------------*/
  7238. }
  7239. } // while(int k=0; k < ChargeProfileCount; k++)
  7240. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  7241. end:
  7242. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  7243. {
  7244. if(connectorIdInt == 0)
  7245. {
  7246. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  7247. {
  7248. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  7249. }
  7250. }
  7251. else
  7252. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  7253. }
  7254. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  7255. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7256. return result;
  7257. }
  7258. void createFirmwareVersionByDataTransfer(void)
  7259. {
  7260. json_object *FirmwareDataTransfer = json_object_new_object();
  7261. // AC & DC model
  7262. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  7263. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  7264. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  7265. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  7266. // DC model
  7267. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O')
  7268. {
  7269. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  7270. {
  7271. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7272. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7273. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  7274. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  7275. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7276. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7277. }
  7278. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  7279. ((gunType[1] != GUN_TYPE_UNKNOWN) || (gunType[2] != GUN_TYPE_UNKNOWN) || (gunType[3] != GUN_TYPE_UNKNOWN)))
  7280. {
  7281. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  7282. }
  7283. }
  7284. else
  7285. {
  7286. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7287. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7288. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7289. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7290. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  7291. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  7292. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  7293. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  7294. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  7295. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  7296. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  7297. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  7298. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  7299. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  7300. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  7301. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  7302. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  7303. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  7304. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  7305. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  7306. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  7307. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  7308. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  7309. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  7310. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  7311. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  7312. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  7313. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  7314. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  7315. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  7316. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  7317. }
  7318. // 4G model
  7319. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  7320. {
  7321. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  7322. }
  7323. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  7324. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  7325. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  7326. json_object_put(FirmwareDataTransfer);
  7327. }
  7328. int handleDataTransferRequest(char *uuid, char *payload)
  7329. {
  7330. mtrace();
  7331. json_object *response = json_object_new_object();
  7332. int result = FAIL;
  7333. char tempvendorId[255]={0};
  7334. char tempmessageId[50]={0};
  7335. char tempdata[512]={0};
  7336. char message[2048]={0};
  7337. DEBUG_INFO("handleDataTransferRequest...\n");
  7338. if((uuid != NULL) && (payload != NULL))
  7339. {
  7340. json_object *DataTransfer;
  7341. DataTransfer = json_tokener_parse(payload);
  7342. if(!is_error(DataTransfer))
  7343. {
  7344. // Required data
  7345. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  7346. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  7347. // Optional data
  7348. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  7349. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  7350. if(json_object_object_get(DataTransfer, "data") != NULL)
  7351. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  7352. result = PASS;
  7353. }
  7354. json_object_put(DataTransfer);
  7355. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  7356. {
  7357. // Send all moudle firmware version on EVSE
  7358. createFirmwareVersionByDataTransfer();
  7359. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7360. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  7361. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7362. json_object_put(response);
  7363. }
  7364. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  7365. {
  7366. system("/usr/bin/run_tmate_restart.sh &");
  7367. }
  7368. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  7369. {
  7370. json_object *data;
  7371. data = json_tokener_parse(tempdata);
  7372. if(!is_error(data))
  7373. {
  7374. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  7375. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  7376. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  7377. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  7378. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  7379. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  7380. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  7381. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  7382. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  7383. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  7384. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7385. }
  7386. else
  7387. {
  7388. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7389. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7390. }
  7391. json_object_put(data);
  7392. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7393. json_object_put(response);
  7394. }
  7395. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  7396. {
  7397. json_object *data;
  7398. data = json_tokener_parse(tempdata);
  7399. if(!is_error(data))
  7400. {
  7401. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  7402. if(json_object_object_get(data, "idToken") != NULL)
  7403. {
  7404. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  7405. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  7406. }
  7407. if(json_object_object_get(data, "price") != NULL)
  7408. {
  7409. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  7410. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  7411. }
  7412. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7413. }
  7414. else
  7415. {
  7416. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7417. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7418. }
  7419. json_object_put(data);
  7420. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7421. json_object_put(response);
  7422. }
  7423. else if(strstr(tempmessageId, "RunningCost") != NULL)
  7424. {
  7425. json_object *data;
  7426. data = json_tokener_parse(tempdata);
  7427. if(!is_error(data))
  7428. {
  7429. if(json_object_object_get(data, "txId") != NULL)
  7430. {
  7431. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7432. for(int idx = 0;idx<gunTotalNumber;idx++)
  7433. {
  7434. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7435. {
  7436. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  7437. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7438. if(json_object_object_get(data, "description") != NULL)
  7439. {
  7440. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7441. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7442. }
  7443. }
  7444. }
  7445. }
  7446. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7447. }
  7448. else
  7449. {
  7450. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7451. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7452. }
  7453. json_object_put(data);
  7454. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7455. json_object_put(response);
  7456. }
  7457. else if(strstr(tempmessageId, "FinalCost") != NULL)
  7458. {
  7459. json_object *data;
  7460. data = json_tokener_parse(tempdata);
  7461. if(!is_error(data))
  7462. {
  7463. if(json_object_object_get(data, "txId") != NULL)
  7464. {
  7465. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7466. for(int idx = 0;idx<gunTotalNumber;idx++)
  7467. {
  7468. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7469. {
  7470. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  7471. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7472. if(json_object_object_get(data, "description") != NULL)
  7473. {
  7474. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7475. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7476. }
  7477. }
  7478. }
  7479. }
  7480. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7481. }
  7482. else
  7483. {
  7484. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7485. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7486. }
  7487. json_object_put(data);
  7488. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7489. json_object_put(response);
  7490. }
  7491. else
  7492. {
  7493. // Can not find valid message id
  7494. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  7495. }
  7496. }
  7497. else
  7498. {
  7499. // Payload is null
  7500. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  7501. }
  7502. LWS_Send(message);
  7503. return result;
  7504. }
  7505. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  7506. {
  7507. mtrace();
  7508. int result = FAIL;
  7509. int connectorIdInt, durationInt;
  7510. char chargingRateUnitStr[4]={0};
  7511. char comfirmstr[20];
  7512. int confirmPeriods = 0;
  7513. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  7514. json_object *GetCompositeSchedule;
  7515. GetCompositeSchedule = json_tokener_parse(payload);
  7516. if(!is_error(GetCompositeSchedule))
  7517. {
  7518. // Required data
  7519. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  7520. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  7521. else
  7522. connectorIdInt = -1;
  7523. if(json_object_object_get(GetCompositeSchedule, "duration"))
  7524. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  7525. else
  7526. durationInt = 86400;
  7527. // Optional data
  7528. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  7529. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  7530. }
  7531. json_object_put(GetCompositeSchedule);
  7532. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  7533. if((connectorIdInt == 0) ||
  7534. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  7535. {
  7536. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  7537. struct StructChargingProfile tmpProfile[1];
  7538. if(strstr(chargingRateUnitStr, "W") != NULL)
  7539. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  7540. else
  7541. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  7542. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7543. {
  7544. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7545. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7546. }
  7547. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  7548. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  7549. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  7550. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7551. {
  7552. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7553. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7554. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  7555. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  7556. {
  7557. confirmPeriods = idx;
  7558. break;
  7559. }
  7560. }
  7561. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  7562. }
  7563. else
  7564. {
  7565. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  7566. }
  7567. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  7568. return result;
  7569. }
  7570. int handleGetConfigurationRequest(char *uuid, char *payload)
  7571. {
  7572. mtrace();
  7573. int result = FAIL;
  7574. int MaxKeySupported = 0;
  7575. int n_keys = 0;
  7576. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  7577. DEBUG_INFO("handleGetConfigurationRequest...\n");
  7578. json_object *GetConfiguration;
  7579. GetConfiguration = json_tokener_parse(payload);
  7580. if(!is_error(GetConfiguration))
  7581. {
  7582. // Optional data
  7583. if(json_object_object_get(GetConfiguration, "key") != NULL)
  7584. {
  7585. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  7586. {
  7587. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  7588. n_keys = idx + 1;
  7589. }
  7590. }
  7591. }
  7592. json_object_put(GetConfiguration);
  7593. UnknownKeynum = 0;
  7594. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  7595. MaxKeySupported = GetConfigurationMaxKeysNUM;
  7596. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  7597. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  7598. if(n_keys != 0)
  7599. {
  7600. for(int i=0;i<n_keys;i++)
  7601. {
  7602. getKeyValue(requestKey[i]);
  7603. }
  7604. }
  7605. else
  7606. {
  7607. DEBUG_INFO("There is no key in Message, get all configuration\n");
  7608. getKeyValue("");
  7609. }
  7610. processUnkownKey();
  7611. sendGetConfigurationConfirmation(uuid);
  7612. return result;
  7613. }
  7614. static char fnamePlusPath[100]={0};
  7615. static char fnamePWithNoPath[60]={0};
  7616. void checkUploadLog(void)
  7617. {
  7618. FILE *fp;
  7619. /* Open the command for reading. */
  7620. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  7621. if (fp == NULL) {
  7622. printf("Failed to run command\n" );
  7623. exit(1);
  7624. }
  7625. int ftppathlen = 0;
  7626. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  7627. int i = 0;
  7628. /* Read the output a line at a time - output it. */
  7629. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  7630. if(i==0)
  7631. {
  7632. ftppathlen = strlen(fnamePlusPath);
  7633. printf("%s\n", fnamePlusPath);
  7634. fnamePlusPath[ftppathlen]='\0';
  7635. break;
  7636. }
  7637. i= i+1;
  7638. }
  7639. /* close */
  7640. pclose(fp);
  7641. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  7642. {
  7643. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  7644. {
  7645. fnamePlusPath[k]='\0';
  7646. }
  7647. }
  7648. i=1;
  7649. //char fname[60]={0};
  7650. while(i < ftppathlen)
  7651. {
  7652. int len=ftppathlen-i;
  7653. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  7654. {
  7655. printf("compare '/' all right\n");
  7656. break;
  7657. }
  7658. i=i+1;
  7659. }
  7660. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  7661. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  7662. fnamePWithNoPath[i+1] = '\0';
  7663. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  7664. {
  7665. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  7666. {
  7667. fnamePWithNoPath[j]='\0';
  7668. }
  7669. }
  7670. FILE* fp1 = fopen(fnamePlusPath, "r");
  7671. if (fp1)
  7672. {
  7673. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  7674. // file exists
  7675. fclose(fp1);
  7676. }
  7677. else
  7678. {
  7679. // file doesn't exist
  7680. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  7681. }
  7682. }
  7683. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  7684. {
  7685. mtrace();
  7686. int result = FAIL;
  7687. time_t CurrentTime;
  7688. struct tm *tm;
  7689. pthread_t th_Status;
  7690. CurrentTime = time(NULL);
  7691. tm = localtime(&CurrentTime);
  7692. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  7693. 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);
  7694. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  7695. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  7696. return result;
  7697. }
  7698. void* GetDiagnosticsProcess(void* data)
  7699. {
  7700. pthread_detach(pthread_self());
  7701. mtrace();
  7702. int retriesInt=0, retryIntervalInt=0;
  7703. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  7704. 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};
  7705. int port=0;
  7706. int isSuccess = FALSE;
  7707. char ftpbuf[200]={0};
  7708. char cmdBuf[2048];
  7709. struct tm *tmNow;
  7710. time_t CurrentTime;
  7711. struct tm tmStart;
  7712. struct tm tmStop;
  7713. CurrentTime = time(NULL);
  7714. tmNow=localtime(&CurrentTime);
  7715. uint16_t targetYear, targetMonth;
  7716. json_object *GetDiagnostics;
  7717. DEBUG_INFO("GetDiagnosticsProcess...\n");
  7718. GetDiagnostics = json_tokener_parse(data);
  7719. if(!is_error(GetDiagnostics))
  7720. {
  7721. // Required data
  7722. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  7723. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  7724. // Optional data
  7725. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  7726. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  7727. else
  7728. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  7729. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  7730. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  7731. else
  7732. retryIntervalInt = 30;
  7733. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  7734. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  7735. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  7736. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  7737. }
  7738. json_object_put(GetDiagnostics);
  7739. // Pack log to compress file
  7740. 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) &&
  7741. (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))
  7742. {
  7743. // Pack system log
  7744. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  7745. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  7746. targetYear = tmStart.tm_year;
  7747. targetMonth = tmStart.tm_mon;
  7748. do
  7749. {
  7750. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7751. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7752. if(targetMonth+1>=13)
  7753. {
  7754. targetYear += 1;
  7755. targetMonth = 1;
  7756. }
  7757. else
  7758. {
  7759. targetMonth += 1;
  7760. }
  7761. }while((targetYear < (tmNow->tm_year+1900)) ||
  7762. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  7763. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  7764. system(cmdBuf);
  7765. // Pack charging & event log
  7766. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  7767. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  7768. targetYear = tmStart.tm_year;
  7769. targetMonth = tmStart.tm_mon;
  7770. do
  7771. {
  7772. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7773. if(targetMonth+1>=13)
  7774. {
  7775. targetYear += 1;
  7776. targetMonth = 1;
  7777. }
  7778. else
  7779. {
  7780. targetMonth += 1;
  7781. }
  7782. }while((targetYear < (tmNow->tm_year+1900)) ||
  7783. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  7784. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  7785. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  7786. system(cmdBuf);
  7787. // Combine log file
  7788. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  7789. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  7790. }
  7791. else
  7792. {
  7793. system("exec /root/logPackTools 'log' 6");
  7794. }
  7795. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  7796. system(cmdBuf);
  7797. checkUploadLog();
  7798. //****************location*******************/
  7799. if(strcmp(locationstr,"")==0)
  7800. {
  7801. DEBUG_INFO("location is <Empty>!\n");
  7802. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7803. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7804. goto end;
  7805. }
  7806. memset(protocol, 0, ARRAY_SIZE(protocol));
  7807. memset(user, 0, ARRAY_SIZE(user) );
  7808. memset(password, 0, ARRAY_SIZE(password));
  7809. memset(host, 0, ARRAY_SIZE(host));
  7810. memset(path, 0, ARRAY_SIZE(path));
  7811. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  7812. memset(host1, 0, ARRAY_SIZE(host1));
  7813. memset(path1, 0, ARRAY_SIZE(path1));
  7814. /*location: ftp://user:password@host:port/path*/
  7815. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  7816. if((access(fnamePlusPath,F_OK))!=-1)
  7817. {
  7818. DEBUG_INFO("fnamePlusPath exist.\n");
  7819. }
  7820. else
  7821. {
  7822. DEBUG_INFO("fnamePlusPath not exist!\n");
  7823. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7824. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7825. goto end;
  7826. }
  7827. if(strchr(locationstr,'@')==NULL)
  7828. {
  7829. sscanf(locationstr,
  7830. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  7831. protocol, host, &port, path);
  7832. strcpy(user,"anonymous");
  7833. strcpy(password,"");
  7834. }
  7835. else
  7836. {
  7837. //DEBUG_INFO("pch=%s\n", pch);
  7838. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  7839. protocol, user, password, host, &port, path);
  7840. }
  7841. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  7842. {
  7843. DEBUG_INFO("protocol is not ftp/http ! \n");
  7844. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7845. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7846. goto end;
  7847. }
  7848. if(strncmp(locationstr,"http", 4) == 0)
  7849. {
  7850. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  7851. sprintf(ftppath,"/%s", path);
  7852. do
  7853. {
  7854. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7855. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7856. sleep(3);
  7857. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  7858. if(!isSuccess)
  7859. {
  7860. DEBUG_INFO("Diagnostics fail.\n");
  7861. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7862. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7863. sleep(retryIntervalInt);
  7864. }
  7865. else
  7866. {
  7867. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7868. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7869. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7870. }
  7871. retriesInt--;
  7872. }while((isSuccess == 0)&&(retriesInt >= 0));
  7873. }
  7874. else
  7875. {
  7876. sscanf(host,"%[^/]%s",host1, path1);
  7877. if(strlen(path) > 0)
  7878. sprintf(ftppath,"/%s", path);
  7879. else
  7880. sprintf(ftppath,"/%s", path1);
  7881. int ftppathlen=strlen(ftppath);
  7882. int i=1;
  7883. char filenametemp[50];
  7884. while(i < ftppathlen)
  7885. {
  7886. int len=ftppathlen-i;
  7887. if(ftppath[len]== 47) // '/' ascll code: 47
  7888. {
  7889. DEBUG_INFO("find '/' all right\n");
  7890. break;
  7891. }
  7892. i=i+1;
  7893. }
  7894. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  7895. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  7896. filenametemp[i+1] = 0;
  7897. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  7898. if(port == 0)
  7899. port = 21;
  7900. do
  7901. {
  7902. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7903. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7904. sleep(3);
  7905. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  7906. if(!isSuccess)
  7907. {
  7908. DEBUG_INFO("Diagnostics fail.\n");
  7909. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7910. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7911. sleep(retryIntervalInt);
  7912. }
  7913. else
  7914. {
  7915. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7916. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7917. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7918. }
  7919. retriesInt--;
  7920. }while((!isSuccess)&&(retriesInt >= 0));
  7921. }
  7922. end:
  7923. system("rm -f /mnt/*");
  7924. sleep(5);
  7925. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  7926. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7927. pthread_exit(NULL);
  7928. }
  7929. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  7930. {
  7931. mtrace();
  7932. int result = FAIL;
  7933. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  7934. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  7935. {
  7936. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  7937. localversion = -1;
  7938. }
  7939. else
  7940. {
  7941. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  7942. OCPP_getListVerion();
  7943. }
  7944. //from db.OCPP_getListVerion
  7945. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  7946. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  7947. sendGetLocalListVersionConfirmation(uuid,"");
  7948. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  7949. return result;
  7950. }
  7951. int handleRemoteStartRequest(char *uuid, char *payload)
  7952. {
  7953. mtrace();
  7954. int result = FAIL;
  7955. int connectorIdInt=0;
  7956. int tempIndex = 0;
  7957. int connectorIdIsNULL, chargingProfileIsNULL;
  7958. char comfirmstr[20]={0};
  7959. char cmdBuf[512];
  7960. json_object *RemoteStartTransaction;
  7961. FILE *fp;
  7962. DEBUG_INFO("handleRemoteStartRequest ...\n");
  7963. if(server_pending == TRUE)
  7964. {
  7965. return 0;
  7966. }
  7967. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  7968. RemoteStartTransaction = json_tokener_parse(payload);
  7969. if(!is_error(RemoteStartTransaction))
  7970. {
  7971. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  7972. {
  7973. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  7974. if(connectorIdInt <= gunTotalNumber)
  7975. {
  7976. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  7977. // Required data
  7978. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  7979. // Optional data
  7980. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  7981. {
  7982. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  7983. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  7984. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  7985. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  7986. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  7987. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  7988. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  7989. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  7990. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  7991. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  7992. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  7993. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  7994. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  7995. {
  7996. 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")));
  7997. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  7998. 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"));
  7999. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  8000. 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"));
  8001. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  8002. 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")));
  8003. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  8004. {
  8005. 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++)
  8006. {
  8007. 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"));
  8008. 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"));
  8009. 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)
  8010. 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"));
  8011. }
  8012. }
  8013. }
  8014. }
  8015. else
  8016. chargingProfileIsNULL = TRUE;
  8017. }
  8018. }
  8019. else
  8020. connectorIdIsNULL = TRUE;
  8021. }
  8022. else
  8023. connectorIdIsNULL = TRUE;
  8024. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  8025. {
  8026. DEBUG_WARN("Connector id is NULL\n.");
  8027. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8028. goto end;
  8029. }
  8030. /*
  8031. enum _SYSTEM_STATUS
  8032. {
  8033. S_BOOTING = 0,
  8034. S_IDLE, = 1
  8035. S_AUTHORIZING, = 2
  8036. S_REASSIGN_CHECK, = 3
  8037. S_REASSIGN, = 4
  8038. S_PRECHARGE, = 5
  8039. S_PREPARING_FOR_EV, = 6
  8040. S_PREPARING_FOR_EVSE, = 7
  8041. S_CHARGING, = 8
  8042. S_TERMINATING, = 9
  8043. S_COMPLETE, = 10
  8044. S_ALARM, = 11
  8045. S_FAULT = 12
  8046. }
  8047. */
  8048. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  8049. {
  8050. //check Transaction active
  8051. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8052. {
  8053. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8054. {
  8055. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8056. }
  8057. else
  8058. {
  8059. tempIndex = connectorIdInt -1;
  8060. }
  8061. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8062. {
  8063. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  8064. {
  8065. 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))
  8066. {
  8067. //Reserved
  8068. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8069. }
  8070. 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))
  8071. {
  8072. //Reserved
  8073. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8074. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8075. goto end;
  8076. }
  8077. else
  8078. {
  8079. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8080. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  8081. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  8082. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  8083. {
  8084. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  8085. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8086. goto end;
  8087. }
  8088. }//END FOR ELSE
  8089. }
  8090. }// END FOR CHAdeMO_QUANTITY
  8091. }
  8092. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8093. {
  8094. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8095. {
  8096. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8097. }
  8098. else
  8099. {
  8100. tempIndex = connectorIdInt -1;
  8101. }
  8102. for (int index = 0; index < CCS_QUANTITY; index++)
  8103. {
  8104. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8105. {
  8106. 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))
  8107. {
  8108. //Reserved
  8109. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8110. }
  8111. 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))
  8112. {
  8113. //Reserved
  8114. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8115. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8116. goto end;
  8117. }
  8118. else
  8119. {
  8120. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8121. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8122. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8123. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8124. {
  8125. DEBUG_WARN("CCS connector not allow start\n.");
  8126. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8127. goto end;
  8128. }
  8129. }// END FOR ELSE
  8130. }
  8131. }// END FOR CCS_QUANTITY
  8132. }
  8133. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8134. {
  8135. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8136. {
  8137. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8138. }
  8139. else
  8140. {
  8141. tempIndex = connectorIdInt -1;
  8142. }
  8143. for (int index = 0; index < GB_QUANTITY; index++)
  8144. {
  8145. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  8146. {
  8147. 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))
  8148. {
  8149. //Reserved
  8150. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8151. }
  8152. 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))
  8153. {
  8154. //Reserved
  8155. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8156. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8157. goto end;
  8158. }
  8159. else
  8160. {
  8161. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8162. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8163. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8164. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8165. {
  8166. DEBUG_WARN("GB connector not allow start\n.");
  8167. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8168. goto end;
  8169. }
  8170. }// END FOR ELSE
  8171. }
  8172. } // END FOR GB_QUANTITY
  8173. }
  8174. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8175. {
  8176. tempIndex = connectorIdInt -1;
  8177. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8178. {
  8179. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  8180. {
  8181. 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))
  8182. {
  8183. //Reserved
  8184. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8185. }
  8186. 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))
  8187. {
  8188. //Reserved
  8189. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8190. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8191. goto end;
  8192. }
  8193. else
  8194. {
  8195. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8196. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8197. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8198. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8199. {
  8200. DEBUG_WARN("GB connector not allow start\n.");
  8201. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8202. goto end;
  8203. }
  8204. }// END FOR ELSE
  8205. }
  8206. } // END FOR GB_QUANTITY
  8207. }
  8208. else
  8209. {
  8210. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8211. {
  8212. tempIndex = 2;
  8213. }
  8214. else
  8215. {
  8216. tempIndex = connectorIdInt -1;
  8217. }
  8218. for (int index = 0; index < AC_QUANTITY; index++)
  8219. {
  8220. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  8221. {
  8222. 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))
  8223. {
  8224. //Reserved
  8225. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8226. }
  8227. 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))
  8228. {
  8229. //Reserved
  8230. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8231. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8232. goto end;
  8233. }
  8234. else
  8235. {
  8236. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8237. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8238. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8239. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8240. {
  8241. DEBUG_WARN("AC connector not allow start\n.");
  8242. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8243. goto end;
  8244. }
  8245. }//END FOR ELSE
  8246. }
  8247. }// END FOR AC_QUANTITY
  8248. }
  8249. if(chargingProfileIsNULL == FALSE)
  8250. {
  8251. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8252. {
  8253. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  8254. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8255. //memset idTag
  8256. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  8257. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8258. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  8259. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8260. // Save profile to file
  8261. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8262. system(cmdBuf);
  8263. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8264. fp = fopen(cmdBuf, "w");
  8265. 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));
  8266. fclose(fp);
  8267. }
  8268. else
  8269. {
  8270. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  8271. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8272. }
  8273. }
  8274. else
  8275. {
  8276. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  8277. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8278. //memset idTag
  8279. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  8280. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8281. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  8282. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8283. }
  8284. }
  8285. else
  8286. {
  8287. DEBUG_WARN("Connector id over\n.");
  8288. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8289. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8290. }
  8291. end:
  8292. json_object_put(RemoteStartTransaction);
  8293. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  8294. {
  8295. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  8296. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8297. }
  8298. //OCPP send RemoteStartConfirmation by first.
  8299. sendRemoteStartConfirmation(uuid, comfirmstr);
  8300. return result;
  8301. }
  8302. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  8303. {
  8304. mtrace();
  8305. int result = FAIL;
  8306. int match = FALSE;
  8307. int GunNO = 0;
  8308. int tempIndex = 0;
  8309. int transactionIdInt=0;
  8310. int transactionIdIsNULL= TRUE;
  8311. char comfirmstr[20];
  8312. json_object *RemoteStopTransaction;
  8313. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  8314. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  8315. if(server_pending == TRUE)
  8316. {
  8317. return 0;
  8318. }
  8319. RemoteStopTransaction = json_tokener_parse(payload);
  8320. if(!is_error(RemoteStopTransaction))
  8321. {
  8322. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  8323. {
  8324. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  8325. transactionIdIsNULL = FALSE;
  8326. }
  8327. }
  8328. json_object_put(RemoteStopTransaction);
  8329. if(transactionIdIsNULL == FALSE)
  8330. {
  8331. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  8332. {
  8333. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  8334. {
  8335. //check Transaction active
  8336. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  8337. {
  8338. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8339. {
  8340. tempIndex = ((gun_index==2) ? 1: 0);
  8341. }
  8342. else
  8343. {
  8344. tempIndex = gun_index;
  8345. }
  8346. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8347. {
  8348. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8349. {
  8350. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8351. {
  8352. match = TRUE;
  8353. GunNO = gun_index;
  8354. }
  8355. }
  8356. }// END FOR CHAdeMO_QUANTITY
  8357. }
  8358. else if(gunType[gun_index] == GUN_TYPE_CCS)
  8359. {
  8360. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8361. {
  8362. tempIndex = ((gun_index==2) ? 1: 0);
  8363. }
  8364. else
  8365. {
  8366. tempIndex = gun_index;
  8367. }
  8368. for (int index = 0; index < CCS_QUANTITY; index++)
  8369. {
  8370. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8371. {
  8372. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8373. {
  8374. match = TRUE;
  8375. GunNO = gun_index;
  8376. }
  8377. }
  8378. }// END FOR CCS_QUANTITY
  8379. }
  8380. else if(gunType[gun_index] == GUN_TYPE_GBT)
  8381. {
  8382. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8383. {
  8384. tempIndex = ((gun_index==2) ? 1: 0);
  8385. }
  8386. else
  8387. {
  8388. tempIndex = gun_index;
  8389. }
  8390. for (int index = 0; index < GB_QUANTITY; index++)
  8391. {
  8392. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8393. {
  8394. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8395. {
  8396. match = TRUE;
  8397. GunNO = gun_index;
  8398. }
  8399. }
  8400. }// END FOR GB_QUANTITY
  8401. }
  8402. else if(gunType[gun_index] == GUN_TYPE_DO)
  8403. {
  8404. tempIndex = gun_index;
  8405. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8406. {
  8407. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8408. {
  8409. 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
  8410. {
  8411. match = TRUE;
  8412. GunNO = gun_index;
  8413. }
  8414. }
  8415. }// END FOR GB_QUANTITY
  8416. }
  8417. else
  8418. {
  8419. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8420. {
  8421. tempIndex = 2;
  8422. }
  8423. else
  8424. {
  8425. tempIndex = gun_index;
  8426. }
  8427. for (int index = 0; index < AC_QUANTITY; index++)
  8428. {
  8429. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8430. {
  8431. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8432. {
  8433. match = TRUE;
  8434. GunNO = gun_index;
  8435. }
  8436. }
  8437. }// END FOR CHAdeMO_QUANTITY
  8438. } // END FOR AC ELSE
  8439. }// CHECK IF ResponseTransactionId == transactionIdInt
  8440. }//END FOR
  8441. if( match == TRUE)
  8442. {
  8443. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  8444. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8445. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  8446. }
  8447. else
  8448. {
  8449. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8450. }
  8451. }
  8452. else
  8453. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8454. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  8455. return result;
  8456. }
  8457. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  8458. {
  8459. mtrace();
  8460. int result = FAIL;
  8461. int connectorIdInt=0, reservationIdInt=0;
  8462. int tempIndex = 0;
  8463. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  8464. char comfirmstr[20]={0};
  8465. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  8466. int c = 0;
  8467. char *loc;
  8468. //char *ptr;
  8469. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  8470. strcpy(sstrtemp, stringtrimspace(payload));
  8471. //***(1)connectorId ****/
  8472. c=0;
  8473. loc = strstr(sstrtemp, "connectorId");
  8474. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8475. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  8476. {
  8477. sstr[c] = loc[strlen("connectorId")+2+c];
  8478. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8479. c++;
  8480. }
  8481. sstr[c] = '\0';
  8482. connectorIdInt = atoi(sstr);
  8483. //***(2)expiryDate ****/
  8484. loc = strstr(sstrtemp, "expiryDate");
  8485. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8486. c = 0;
  8487. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  8488. {
  8489. sstr[c] = loc[3+strlen("expiryDate")+c];
  8490. c++;
  8491. }
  8492. sstr[c] = '\0';
  8493. strcpy(expiryDatestr, sstr);
  8494. //***(3)idTag ****/
  8495. loc = strstr(sstrtemp, "idTag");
  8496. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8497. c = 0;
  8498. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  8499. {
  8500. sstr[c] = loc[3+strlen("idTag")+c];
  8501. c++;
  8502. }
  8503. sstr[c] = '\0';
  8504. strcpy(idTagstr, sstr);
  8505. //***(4)parentIdTag ****/
  8506. loc = strstr(sstrtemp, "parentIdTag");
  8507. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8508. c = 0;
  8509. if(loc == NULL)
  8510. {
  8511. strcpy(parentIdTagstr, "");
  8512. }
  8513. else
  8514. {
  8515. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8516. {
  8517. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8518. c++;
  8519. }
  8520. sstr[c] = '\0';
  8521. strcpy(parentIdTagstr, sstr);
  8522. }
  8523. //***(5)reservationId ****/
  8524. c=0;
  8525. loc = strstr(sstrtemp, "reservationId");
  8526. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8527. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  8528. {
  8529. sstr[c] = loc[strlen("reservationId")+2+c];
  8530. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8531. c++;
  8532. }
  8533. sstr[c] = '\0';
  8534. reservationIdInt = atoi(sstr);
  8535. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8536. /*
  8537. enum SYSTEM_STATUS
  8538. {
  8539. SYS_MODE_BOOTING = 0,
  8540. SYS_MODE_IDLE = 1,
  8541. SYS_MODE_AUTHORIZING = 2,
  8542. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  8543. SYS_MODE_REASSIGN = 4,
  8544. SYS_MODE_PREPARING = 5,
  8545. SYS_MODE_PREPARE_FOR_EV = 6,
  8546. SYS_MODE_PREPARE_FOR_EVSE = 7,
  8547. SYS_MODE_CHARGING = 8,
  8548. SYS_MODE_TERMINATING = 9,
  8549. SYS_MODE_COMPLETE = 10,
  8550. SYS_MODE_ALARM = 11,
  8551. SYS_MODE_FAULT = 12,
  8552. SYS_MODE_RESERVATION = 13,
  8553. SYS_MODE_BOOKING = 14,
  8554. SYS_MODE_MAINTAIN = 15,
  8555. SYS_MODE_DEBUG = 16,
  8556. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  8557. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  8558. SYS_MODE_UPDATE = 19
  8559. };
  8560. */
  8561. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  8562. {
  8563. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8564. goto end;
  8565. }
  8566. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  8567. {
  8568. //check Transaction active
  8569. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8570. {
  8571. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8572. {
  8573. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8574. }
  8575. else
  8576. {
  8577. tempIndex = connectorIdInt -1;
  8578. }
  8579. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8580. {
  8581. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8582. {
  8583. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8584. {
  8585. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8586. {
  8587. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8588. {
  8589. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8590. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8591. }
  8592. 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'))
  8593. {
  8594. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8595. }
  8596. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8597. {
  8598. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8599. }
  8600. else
  8601. {
  8602. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8603. }
  8604. }
  8605. 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
  8606. {
  8607. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8608. }
  8609. }
  8610. else
  8611. {
  8612. //replace reservation
  8613. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8614. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8615. }
  8616. }
  8617. } // END FOR CHAdeMO_QUANTITY
  8618. }
  8619. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8620. {
  8621. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8622. {
  8623. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8624. }
  8625. else
  8626. {
  8627. tempIndex = connectorIdInt -1;
  8628. }
  8629. for (int index = 0; index < CCS_QUANTITY; index++)
  8630. {
  8631. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8632. {
  8633. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8634. {
  8635. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8636. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8637. {
  8638. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8639. {
  8640. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8641. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8642. }
  8643. 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'))
  8644. {
  8645. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8646. }
  8647. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  8648. {
  8649. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8650. }
  8651. else
  8652. {
  8653. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8654. }
  8655. }
  8656. 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
  8657. {
  8658. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8659. }
  8660. }
  8661. else
  8662. {
  8663. //replace reservation
  8664. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8665. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8666. }
  8667. }
  8668. } // END FOR CCS_QUANTITY
  8669. }
  8670. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8671. {
  8672. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8673. {
  8674. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8675. }
  8676. else
  8677. {
  8678. tempIndex = connectorIdInt -1;
  8679. }
  8680. for (int index = 0; index < GB_QUANTITY; index++)
  8681. {
  8682. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8683. {
  8684. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8685. {
  8686. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8687. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8688. {
  8689. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8690. {
  8691. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8692. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8693. }
  8694. 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'))
  8695. {
  8696. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8697. }
  8698. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8699. {
  8700. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8701. }
  8702. else
  8703. {
  8704. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8705. }
  8706. }
  8707. 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
  8708. {
  8709. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8710. }
  8711. }
  8712. else
  8713. {
  8714. //replace reservation
  8715. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8716. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8717. }
  8718. }
  8719. }// END FOR GB_QUANTITY
  8720. }
  8721. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8722. {
  8723. tempIndex = connectorIdInt -1;
  8724. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8725. {
  8726. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8727. {
  8728. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  8729. {
  8730. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8731. 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
  8732. {
  8733. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8734. {
  8735. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8736. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8737. }
  8738. 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'))
  8739. {
  8740. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8741. }
  8742. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8743. {
  8744. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8745. }
  8746. else
  8747. {
  8748. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8749. }
  8750. }
  8751. 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
  8752. {
  8753. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8754. }
  8755. }
  8756. else
  8757. {
  8758. //replace reservation
  8759. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8760. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8761. }
  8762. }
  8763. }// END FOR GB_QUANTITY
  8764. }
  8765. else
  8766. {
  8767. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8768. {
  8769. tempIndex = 2;
  8770. }
  8771. else
  8772. {
  8773. tempIndex = (connectorIdInt -1);
  8774. }
  8775. for (int index = 0; index < AC_QUANTITY; index++)
  8776. {
  8777. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8778. {
  8779. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8780. {
  8781. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8782. {
  8783. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8784. {
  8785. 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))
  8786. {
  8787. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8788. }
  8789. else
  8790. {
  8791. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8792. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8793. }
  8794. }
  8795. 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'))
  8796. {
  8797. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8798. }
  8799. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8800. {
  8801. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8802. }
  8803. else
  8804. {
  8805. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8806. }
  8807. }
  8808. 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
  8809. {
  8810. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8811. }
  8812. }
  8813. else
  8814. {
  8815. //replace reservation
  8816. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8817. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8818. }
  8819. }
  8820. } // END FOR AC_QUANTITY
  8821. }
  8822. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8823. }
  8824. else if(connectorIdInt == 0)
  8825. {
  8826. //check Transaction active
  8827. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8828. {
  8829. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8830. {
  8831. 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'))
  8832. {
  8833. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8834. goto end;
  8835. }
  8836. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8837. {
  8838. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8839. goto end;
  8840. }
  8841. 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
  8842. {
  8843. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8844. goto end;
  8845. }
  8846. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8847. {
  8848. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8849. goto end;
  8850. }
  8851. }
  8852. }// END FOR CHAdeMO_QUANTITY
  8853. for (int index = 0; index < CCS_QUANTITY; index++)
  8854. {
  8855. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8856. {
  8857. 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'))
  8858. {
  8859. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8860. goto end;
  8861. }
  8862. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  8863. {
  8864. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8865. goto end;
  8866. }
  8867. 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
  8868. {
  8869. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8870. goto end;
  8871. }
  8872. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8873. {
  8874. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8875. goto end;
  8876. }
  8877. }
  8878. } // END FOR CCS_QUANTITY
  8879. for (int index = 0; index < GB_QUANTITY; index++)
  8880. {
  8881. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8882. {
  8883. 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'))
  8884. {
  8885. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8886. goto end;
  8887. }
  8888. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8889. {
  8890. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8891. goto end;
  8892. }
  8893. 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
  8894. {
  8895. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8896. goto end;
  8897. }
  8898. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8899. {
  8900. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8901. goto end;
  8902. }
  8903. }
  8904. } // END FOR GB_QUANTITY
  8905. for (int index = 0; index < AC_QUANTITY; index++)
  8906. {
  8907. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8908. {
  8909. 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'))
  8910. {
  8911. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8912. goto end;
  8913. }
  8914. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8915. {
  8916. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8917. goto end;
  8918. }
  8919. 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
  8920. {
  8921. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8922. goto end;
  8923. }
  8924. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8925. {
  8926. 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))
  8927. {
  8928. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8929. goto end;
  8930. }
  8931. }
  8932. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8933. {
  8934. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8935. goto end;
  8936. }
  8937. }
  8938. }// END FOR AC_QUANTITY
  8939. //The connectorId is 0
  8940. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  8941. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8942. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  8943. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  8944. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  8945. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  8946. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  8947. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  8948. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  8949. result = TRUE;
  8950. return result;
  8951. }
  8952. else
  8953. {
  8954. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8955. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8956. }
  8957. if(strcmp(comfirmstr,"Accepted") == 0)
  8958. {
  8959. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  8960. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  8961. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  8962. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  8963. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  8964. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  8965. result = TRUE;
  8966. return result;
  8967. }
  8968. end:
  8969. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  8970. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  8971. return result;
  8972. }
  8973. int handleResetRequest(char *uuid, char *payload)
  8974. {
  8975. mtrace();
  8976. int result = FAIL;
  8977. char sstr[10]={0},sstrtemp[30]={ 0 };
  8978. char typestr[10]={0};
  8979. char comfirmstr[20]={0};
  8980. int c = 0;
  8981. char *loc;
  8982. DEBUG_INFO("handleResetRequest...\n");
  8983. strcpy(sstrtemp, stringtrimspace(payload));
  8984. loc = strstr(sstrtemp, "type");
  8985. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8986. c = 0;
  8987. while (loc[3+strlen("type")+c] != '\"')
  8988. {
  8989. sstr[c] = loc[3+strlen("type")+c];
  8990. c++;
  8991. }
  8992. sstr[c] = '\0';
  8993. strcpy(typestr,sstr);
  8994. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  8995. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  8996. {
  8997. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  8998. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  8999. result = TRUE;
  9000. return result;
  9001. }
  9002. else
  9003. {
  9004. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  9005. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  9006. goto errorend;
  9007. }
  9008. errorend:
  9009. sendResetConfirmation(uuid, comfirmstr);
  9010. return result;
  9011. }
  9012. int handleSendLocalListRequest(char *uuid, char *payload)
  9013. {
  9014. mtrace();
  9015. int result = FAIL;
  9016. int listVersionInt;
  9017. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  9018. char listsearch[]="listVersion";
  9019. char updateTypesearch[]="updateType";
  9020. char localAuthorizationListsearch[]="localAuthorizationList";
  9021. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  9022. char CardList[500][160]={0};
  9023. char updateTypestr[15]={0};
  9024. char idTagstr[20]={0};
  9025. char parentIdTag[20]={0};
  9026. char expiryDate[30]={0};
  9027. char idTagstatus[16]={0};
  9028. int c = 0;
  9029. int i = 0;
  9030. char *delim1 = "}";
  9031. char * pch;
  9032. char *loc;
  9033. //char *ptr;
  9034. char comfirmstr[20];
  9035. //int n_localAuthorizations = 0;
  9036. int checkState_Faulted = FALSE;
  9037. DEBUG_INFO("handleSendLocalListRequest...\n");
  9038. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  9039. {
  9040. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9041. goto end;
  9042. }
  9043. //check Charge Point state
  9044. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9045. {
  9046. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9047. {
  9048. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9049. }
  9050. }
  9051. for (int index = 0; index < CCS_QUANTITY; index++)
  9052. {
  9053. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9054. {
  9055. checkState_Faulted = TRUE; //OCPP Status
  9056. }
  9057. }
  9058. for (int index = 0; index < GB_QUANTITY; index++)
  9059. {
  9060. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9061. {
  9062. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9063. }
  9064. }
  9065. //check Charge Point state
  9066. for (int index = 0; index < AC_QUANTITY; index++)
  9067. {
  9068. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9069. {
  9070. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9071. }
  9072. }
  9073. if(checkState_Faulted == TRUE)
  9074. {
  9075. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9076. goto end;
  9077. }
  9078. //Filter payload space
  9079. strcpy(sstrtemp, stringtrimspace(payload));
  9080. //listVersion
  9081. c = 0;
  9082. loc = strstr(sstrtemp, listsearch);
  9083. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  9084. {
  9085. sstr[c] = loc[strlen("listVersion")+2+c];
  9086. c++;
  9087. }
  9088. sstr[c] = '\0';
  9089. listVersionInt = atoi(sstr);
  9090. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  9091. //updateType
  9092. loc = strstr(sstrtemp, updateTypesearch);
  9093. c = 0;
  9094. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  9095. {
  9096. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  9097. c++;
  9098. }
  9099. sstr[c] = '\0';
  9100. strcpy(updateTypestr, sstr);
  9101. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  9102. //localAuthorizationList
  9103. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9104. loc = strstr(sstrtemp, localAuthorizationListsearch);
  9105. if(loc != NULL) // localAuthorizationList is not NULL
  9106. {
  9107. //Check UpdateType
  9108. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9109. {
  9110. //Local list full update
  9111. printf("Local list full update.\n");
  9112. OCPP_getListVerion();
  9113. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  9114. {
  9115. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9116. goto end;
  9117. }
  9118. OCPP_cleanLocalList();
  9119. }
  9120. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9121. {
  9122. //Local list different update
  9123. printf("Local list different update.\n");
  9124. OCPP_getListVerion();
  9125. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  9126. {
  9127. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  9128. goto end;
  9129. }
  9130. }
  9131. else
  9132. {
  9133. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9134. goto end;
  9135. }
  9136. c = 0;
  9137. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  9138. {
  9139. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  9140. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9141. c++;
  9142. }
  9143. sstr[c] = '\0';
  9144. //DEBUG_INFO("sstr=%s\n", sstr);
  9145. //parsing strings to words
  9146. i = 0;
  9147. pch = strtok(sstr,delim1);
  9148. while (pch != NULL)
  9149. {
  9150. strcpy(CardList[i], pch);
  9151. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  9152. pch = strtok (NULL, delim1);
  9153. i = i + 1;
  9154. }
  9155. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  9156. //local Authorizations List Numbers
  9157. //n_localAuthorizations = i;
  9158. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  9159. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  9160. c= 0;
  9161. while(c < i) // i is CardList Number
  9162. {
  9163. //Search "IdToken"
  9164. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9165. loc = strstr(CardList[c], "idTag");
  9166. int j = 0;
  9167. while (loc[3+strlen("idTag")+j] != '\"')
  9168. {
  9169. sstr[j] = loc[3+strlen("idTag")+j];
  9170. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9171. j++;
  9172. }
  9173. sstr[j] = '\0';
  9174. strcpy(idTagstr, sstr);
  9175. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  9176. //Search "expiryDate"
  9177. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9178. loc = strstr(CardList[c], "expiryDate");
  9179. j = 0;
  9180. if(loc != NULL)
  9181. {
  9182. while (loc[3+strlen("expiryDate")+j] != '\"')
  9183. {
  9184. sstr[j] = loc[3+strlen("expiryDate")+j];
  9185. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9186. j++;
  9187. }
  9188. sstr[j] = '\0';
  9189. strcpy(expiryDate, sstr);
  9190. }
  9191. else
  9192. {
  9193. strcpy(expiryDate, "");
  9194. }
  9195. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  9196. //Search "parentIdTag"
  9197. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9198. loc = strstr(CardList[c], "parentIdTag");
  9199. j = 0;
  9200. if(loc != NULL)
  9201. {
  9202. while (loc[3+strlen("parentIdTag")+j] != '\"')
  9203. {
  9204. sstr[j] = loc[3+strlen("parentIdTag")+j];
  9205. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9206. j++;
  9207. }
  9208. sstr[j] = '\0';
  9209. strcpy(parentIdTag, sstr);
  9210. }
  9211. else
  9212. {
  9213. strcpy(parentIdTag, "");
  9214. }
  9215. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  9216. //Search "status"
  9217. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9218. loc = strstr(CardList[c], "status");
  9219. j = 0;
  9220. while (loc[3+strlen("status")+j] != '\"')
  9221. {
  9222. sstr[j] = loc[3+strlen("status")+j];
  9223. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9224. j++;
  9225. }
  9226. sstr[j] = '\0';
  9227. strcpy(idTagstatus, sstr);
  9228. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  9229. OCPP_getIdTagFromLocalList(idTagstr);
  9230. //OCPP_getIdTagFromLocalList("test"); For Test
  9231. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  9232. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  9233. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9234. {
  9235. //Local list full update
  9236. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9237. // update list
  9238. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9239. //DEBUG_INFO("Local list full update. 1\n");
  9240. //OCPP_get_TableAuthlocalAllData();
  9241. //DEBUG_INFO("Local list full update. 2\n");
  9242. }
  9243. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9244. {
  9245. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9246. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  9247. }
  9248. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  9249. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  9250. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  9251. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  9252. c++;
  9253. }
  9254. }
  9255. else
  9256. {
  9257. //Check UpdateType
  9258. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9259. {
  9260. //Local list full update
  9261. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  9262. OCPP_cleanLocalList();
  9263. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9264. goto end;
  9265. }
  9266. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9267. {
  9268. //Local list different update
  9269. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  9270. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9271. goto end;
  9272. }
  9273. }
  9274. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9275. end:
  9276. sendSendLocalListConfirmation(uuid, comfirmstr);
  9277. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  9278. return result;
  9279. }
  9280. #define MAX 200
  9281. int handleSetChargingProfileRequest(char *uuid, char *payload)
  9282. {
  9283. mtrace();
  9284. int result = FAIL;
  9285. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  9286. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  9287. char chargingProfilePurposeStr[30]={0};
  9288. char chargingProfileKindStr[16]={0};
  9289. char recurrencyKindStr[10]={0};
  9290. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  9291. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  9292. int chargingSchedulePeriodCount = 0;
  9293. char comfirmstr[20]={0};
  9294. int meet= FALSE;
  9295. FILE *fptr1;
  9296. char filename[MAX]={0};
  9297. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  9298. char rmFileCmd[50]={0};
  9299. char tempchargingProfilePurposeStr[30]={0};
  9300. char word[1600]={0};
  9301. int n_chargingProfile = 0;
  9302. json_object *SetChargingProfile;
  9303. DEBUG_INFO("handleSetChargingProfileRequest\n");
  9304. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  9305. SetChargingProfile = json_tokener_parse(payload);
  9306. if(!is_error(SetChargingProfile))
  9307. {
  9308. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  9309. {
  9310. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  9311. if(connectorIdInt == 0)
  9312. {
  9313. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  9314. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  9315. }
  9316. else
  9317. {
  9318. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  9319. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  9320. }
  9321. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  9322. }
  9323. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  9324. {
  9325. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9326. {
  9327. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9328. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9329. {
  9330. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9331. }
  9332. else
  9333. {
  9334. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9335. }
  9336. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  9337. }
  9338. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9339. {
  9340. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  9341. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9342. {
  9343. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  9344. }
  9345. else
  9346. {
  9347. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  9348. }
  9349. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  9350. }
  9351. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9352. {
  9353. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9354. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9355. {
  9356. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9357. }
  9358. else
  9359. {
  9360. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9361. }
  9362. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  9363. }
  9364. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  9365. {
  9366. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  9367. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9368. {
  9369. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9370. }
  9371. else
  9372. {
  9373. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9374. }
  9375. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  9376. }
  9377. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  9378. {
  9379. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  9380. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9381. {
  9382. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  9383. }
  9384. else
  9385. {
  9386. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  9387. }
  9388. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  9389. }
  9390. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  9391. {
  9392. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  9393. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9394. {
  9395. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9396. }
  9397. else
  9398. {
  9399. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9400. }
  9401. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  9402. }
  9403. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  9404. {
  9405. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  9406. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9407. {
  9408. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  9409. }
  9410. else
  9411. {
  9412. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  9413. }
  9414. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  9415. }
  9416. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  9417. {
  9418. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  9419. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9420. {
  9421. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  9422. }
  9423. else
  9424. {
  9425. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  9426. }
  9427. //DEBUG_INFO("validToStr: %s\n", validToStr);
  9428. }
  9429. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  9430. {
  9431. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  9432. {
  9433. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  9434. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9435. {
  9436. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9437. }
  9438. else
  9439. {
  9440. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9441. }
  9442. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  9443. }
  9444. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  9445. {
  9446. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  9447. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9448. {
  9449. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9450. }
  9451. else
  9452. {
  9453. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9454. }
  9455. //DEBUG_INFO("durationInt: %d\n", durationInt);
  9456. }
  9457. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  9458. {
  9459. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  9460. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9461. {
  9462. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9463. }
  9464. else
  9465. {
  9466. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9467. }
  9468. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  9469. }
  9470. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  9471. {
  9472. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  9473. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9474. {
  9475. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9476. }
  9477. else
  9478. {
  9479. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9480. }
  9481. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  9482. }
  9483. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9484. {
  9485. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  9486. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  9487. if(chargingSchedulePeriodCount <= 10)
  9488. {
  9489. 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++)
  9490. {
  9491. 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)
  9492. {
  9493. 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"));
  9494. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9495. {
  9496. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9497. }
  9498. else
  9499. {
  9500. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9501. }
  9502. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  9503. }
  9504. 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)
  9505. {
  9506. 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"));
  9507. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9508. {
  9509. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9510. }
  9511. else
  9512. {
  9513. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9514. }
  9515. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  9516. }
  9517. 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)
  9518. {
  9519. 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"));
  9520. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9521. {
  9522. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9523. }
  9524. else
  9525. {
  9526. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9527. }
  9528. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  9529. }
  9530. }
  9531. }
  9532. }
  9533. }
  9534. }
  9535. }
  9536. json_object_put(SetChargingProfile);
  9537. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  9538. {
  9539. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9540. goto end;
  9541. }
  9542. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  9543. {
  9544. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  9545. if(connectorIdInt != 0)
  9546. {
  9547. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9548. goto end;
  9549. }
  9550. strcpy(filename, ChargePointMaxProfile_JSON );
  9551. fptr1 = fopen(filename, "r");
  9552. if (!fptr1)
  9553. {
  9554. //file not exist
  9555. DEBUG_INFO("Unable to open the input file!!\n");
  9556. fptr1 = fopen(filename, "w+");
  9557. }
  9558. else
  9559. {
  9560. //Check Charging Profile Count
  9561. while(fscanf(fptr1, "%s", word) != EOF)
  9562. {
  9563. //DEBUG_INFO("word=%s\n",word);
  9564. if(strstr(word, "chargingProfileId")!= NULL)
  9565. {
  9566. //DEBUG_INFO("test chargingProfileId \n");
  9567. n_chargingProfile = n_chargingProfile + 1;
  9568. //DEBUG_INFO("chargingProfileId Found\n");
  9569. }
  9570. }
  9571. }
  9572. fclose(fptr1);
  9573. }
  9574. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  9575. {
  9576. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  9577. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9578. {
  9579. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9580. goto end;
  9581. }
  9582. memset(filename, 0, ARRAY_SIZE(filename));
  9583. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9584. fptr1 = fopen(filename, "r");
  9585. if (!fptr1)
  9586. {
  9587. //file not exist
  9588. //DEBUG_INFO("Unable to open the input file!!\n");
  9589. fptr1 = fopen(filename, "w+");
  9590. }
  9591. else
  9592. {
  9593. //Check Charging Profile Count
  9594. while(fscanf(fptr1, "%s", word) != EOF)
  9595. {
  9596. //DEBUG_INFO("word=%s\n",word);
  9597. if(strstr(word, "chargingProfileId")!= NULL)
  9598. {
  9599. //DEBUG_INFO("test chargingProfileId \n");
  9600. n_chargingProfile = n_chargingProfile + 1;
  9601. //DEBUG_INFO("chargingProfileId Found\n");
  9602. }
  9603. }
  9604. }
  9605. fclose(fptr1);
  9606. }
  9607. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9608. {
  9609. //printf("set chargingProfile 1-4\n");
  9610. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  9611. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  9612. if(connectorIdInt == 0)
  9613. {
  9614. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9615. goto end;
  9616. }
  9617. int tempIndex = 0;
  9618. //check Transaction active
  9619. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9620. {
  9621. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9622. {
  9623. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9624. }
  9625. else
  9626. {
  9627. tempIndex = connectorIdInt -1;
  9628. }
  9629. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9630. {
  9631. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9632. {
  9633. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9634. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9635. {
  9636. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9637. {
  9638. meet = TRUE;
  9639. break;
  9640. }
  9641. }
  9642. }
  9643. }
  9644. }
  9645. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9646. {
  9647. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9648. {
  9649. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9650. }
  9651. else
  9652. {
  9653. tempIndex = connectorIdInt -1;
  9654. }
  9655. for (int index = 0; index < CCS_QUANTITY; index++)
  9656. {
  9657. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9658. {
  9659. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9660. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9661. {
  9662. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9663. {
  9664. meet = TRUE;
  9665. break;
  9666. }
  9667. }
  9668. }
  9669. }
  9670. }
  9671. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9672. {
  9673. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9674. {
  9675. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9676. }
  9677. else
  9678. {
  9679. tempIndex = connectorIdInt -1;
  9680. }
  9681. for (int index = 0; index < GB_QUANTITY; index++)
  9682. {
  9683. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9684. {
  9685. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9686. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9687. {
  9688. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9689. {
  9690. meet = TRUE;
  9691. break;
  9692. }
  9693. }
  9694. }
  9695. }
  9696. }
  9697. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9698. {
  9699. tempIndex = connectorIdInt -1;
  9700. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9701. {
  9702. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9703. {
  9704. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  9705. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9706. {
  9707. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9708. {
  9709. meet = TRUE;
  9710. break;
  9711. }
  9712. }
  9713. }
  9714. }
  9715. }
  9716. else
  9717. {
  9718. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9719. {
  9720. tempIndex = 2;
  9721. }
  9722. else
  9723. {
  9724. tempIndex = (connectorIdInt -1);
  9725. }
  9726. for (int index = 0; index < AC_QUANTITY; index++)
  9727. {
  9728. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9729. {
  9730. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9731. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9732. {
  9733. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9734. {
  9735. meet = TRUE;
  9736. break;
  9737. }
  9738. }
  9739. }
  9740. }
  9741. }
  9742. //check Transaction active
  9743. if(meet == FALSE)
  9744. {
  9745. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9746. goto end;
  9747. }
  9748. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9749. {
  9750. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9751. goto end;
  9752. }
  9753. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9754. fptr1 = fopen(filename, "r");
  9755. if (!fptr1)
  9756. {
  9757. //file not exist
  9758. DEBUG_INFO("Unable to open the input file!!\n");
  9759. fptr1 = fopen(filename, "w+");
  9760. }
  9761. else
  9762. {
  9763. //Check Charging Profile Count
  9764. while(fscanf(fptr1, "%s", word) != EOF)
  9765. {
  9766. //DEBUG_INFO("word=%s\n",word);
  9767. if(strstr(word, "chargingProfileId")!= NULL)
  9768. {
  9769. //DEBUG_INFO("test chargingProfileId \n");
  9770. n_chargingProfile = n_chargingProfile + 1;
  9771. //DEBUG_INFO("chargingProfileId Found\n");
  9772. }
  9773. }
  9774. }
  9775. fclose(fptr1);
  9776. }
  9777. // Check ChargeProfileMaxStackLevel
  9778. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  9779. {
  9780. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9781. goto end;
  9782. }
  9783. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9784. {
  9785. int i = 0;
  9786. char fnametemp[200]={0};
  9787. n_chargingProfile = 0;
  9788. //Check ChargePointMaxProfile.json exit
  9789. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9790. {
  9791. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  9792. //Check Charging Profile Count
  9793. while(fscanf(fptr1, "%s", word) != EOF)
  9794. {
  9795. //DEBUG_INFO("word=%s\n",word);
  9796. if(strstr(word, "chargingProfileId")!= NULL)
  9797. {
  9798. //DEBUG_INFO("test chargingProfileId \n");
  9799. n_chargingProfile = n_chargingProfile + 1;
  9800. i = i + 1;
  9801. //DEBUG_INFO("chargingProfileId Found\n");
  9802. }
  9803. memset(word, 0, ARRAY_SIZE(word));
  9804. }
  9805. fclose(fptr1);
  9806. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  9807. }
  9808. //Check TxDefaultProfile_0.json exit
  9809. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9810. {
  9811. i = 0;
  9812. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  9813. //Check Charging Profile Count
  9814. while(fscanf(fptr1, "%s", word) != EOF)
  9815. {
  9816. //DEBUG_INFO("word=%s\n",word);
  9817. if(strstr(word, "chargingProfileId")!= NULL)
  9818. {
  9819. //DEBUG_INFO("test chargingProfileId \n");
  9820. n_chargingProfile = n_chargingProfile + 1;
  9821. i = i + 1;
  9822. //DEBUG_INFO("chargingProfileId Found\n");
  9823. }
  9824. memset(word, 0, ARRAY_SIZE(word));
  9825. }
  9826. fclose(fptr1);
  9827. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  9828. }
  9829. //Check TxDefaultProfile_%d.json
  9830. for(int j=1; j <= gunTotalNumber; j++)
  9831. {
  9832. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9833. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9834. if((access(fnametemp,F_OK))!=-1)
  9835. {
  9836. i = 0;
  9837. fptr1 = fopen(fnametemp, "r");
  9838. //Check Charging Profile Count
  9839. while(fscanf(fptr1, "%s", word) != EOF)
  9840. {
  9841. //DEBUG_INFO("word=%s\n",word);
  9842. if(strstr(word, "chargingProfileId")!= NULL)
  9843. {
  9844. //DEBUG_INFO("test chargingProfileId \n");
  9845. n_chargingProfile = n_chargingProfile + 1;
  9846. i = i + 1;
  9847. //DEBUG_INFO("chargingProfileId Found\n");
  9848. }
  9849. memset(word, 0, ARRAY_SIZE(word));
  9850. }
  9851. fclose(fptr1);
  9852. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9853. }
  9854. }
  9855. //Check TxProfile_%d.json
  9856. for(int j=1; j <= gunTotalNumber; j++)
  9857. {
  9858. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9859. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9860. if((access(fnametemp,F_OK))!=-1)
  9861. {
  9862. i = 0;
  9863. fptr1 = fopen(fnametemp, "r");
  9864. //Check Charging Profile Count
  9865. while(fscanf(fptr1, "%s", word) != EOF)
  9866. {
  9867. //DEBUG_INFO("word=%s\n",word);
  9868. if(strstr(word, "chargingProfileId")!= NULL)
  9869. {
  9870. //DEBUG_INFO("test chargingProfileId \n");
  9871. n_chargingProfile = n_chargingProfile + 1;
  9872. i = i + 1;
  9873. //DEBUG_INFO("chargingProfileId Found\n");
  9874. }
  9875. memset(word, 0, ARRAY_SIZE(word));
  9876. }
  9877. fclose(fptr1);
  9878. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9879. }
  9880. }
  9881. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  9882. {
  9883. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9884. goto end;
  9885. }
  9886. }
  9887. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9888. //**********************************Write to File********************************************************/
  9889. FILE *infile;
  9890. FILE *outfile;
  9891. infile = fopen (filename, "r");
  9892. outfile = fopen (tempfile, "w");
  9893. int d =0;
  9894. d = fgetc(infile);
  9895. rewind(infile);
  9896. if(d == EOF)
  9897. {
  9898. // Profile is empty
  9899. fprintf(outfile,"%s\n",payload);
  9900. fclose(infile);
  9901. fclose(outfile);
  9902. sprintf(rmFileCmd,"rm -f %s",filename);
  9903. system(rmFileCmd);
  9904. rename(tempfile, filename);
  9905. }
  9906. else
  9907. {
  9908. // Profile is not empty
  9909. char buf[2048]={0};
  9910. int ChargingProfileAdded = FALSE;
  9911. while (fgets(buf, sizeof(buf), infile) != NULL)
  9912. {
  9913. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9914. json_object *tmpChargingProfile;
  9915. tmpChargingProfile = json_tokener_parse(buf);
  9916. if(!is_error(SetChargingProfile))
  9917. {
  9918. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  9919. {
  9920. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  9921. }
  9922. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  9923. {
  9924. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9925. {
  9926. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9927. }
  9928. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9929. {
  9930. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  9931. }
  9932. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9933. {
  9934. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9935. }
  9936. }
  9937. }
  9938. json_object_put(tmpChargingProfile);
  9939. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  9940. {
  9941. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9942. {
  9943. //DEBUG_INFO("update set chargingProfile to file -0\n");
  9944. if(ChargingProfileAdded == FALSE)
  9945. {
  9946. fprintf(outfile,"%s\n",payload);
  9947. ChargingProfileAdded = TRUE;
  9948. }
  9949. }
  9950. else
  9951. {
  9952. if(tempstackLevelInt < stackLevelInt)
  9953. {
  9954. if(ChargingProfileAdded == FALSE)
  9955. {
  9956. fprintf(outfile,"%s\n",buf);
  9957. fprintf(outfile,"%s\n",payload);
  9958. ChargingProfileAdded = TRUE;
  9959. }
  9960. else
  9961. {
  9962. fprintf(outfile,"%s\n",buf);
  9963. }
  9964. }
  9965. else
  9966. {
  9967. if(ChargingProfileAdded == FALSE)
  9968. {
  9969. fprintf(outfile,"%s\n",buf);
  9970. fprintf(outfile,"%s\n",payload);
  9971. ChargingProfileAdded = TRUE;
  9972. }
  9973. else
  9974. {
  9975. fprintf(outfile,"%s\n",buf);
  9976. }
  9977. }
  9978. }
  9979. }
  9980. else
  9981. {
  9982. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9983. {
  9984. if(ChargingProfileAdded == FALSE)
  9985. {
  9986. fprintf(outfile,"%s\n",buf);
  9987. fprintf(outfile,"%s\n",payload);
  9988. ChargingProfileAdded = TRUE;
  9989. }
  9990. else
  9991. {
  9992. fprintf(outfile,"%s\n",buf);
  9993. }
  9994. }
  9995. else if(tempstackLevelInt < stackLevelInt)
  9996. {
  9997. if(ChargingProfileAdded == FALSE)
  9998. {
  9999. fprintf(outfile,"%s\n",buf);
  10000. fprintf(outfile,"%s\n",payload);
  10001. ChargingProfileAdded = TRUE;
  10002. }
  10003. else
  10004. {
  10005. fprintf(outfile,"%s\n",buf);
  10006. }
  10007. }
  10008. else
  10009. {
  10010. if(ChargingProfileAdded == FALSE)
  10011. {
  10012. fprintf(outfile,"%s\n",buf);
  10013. fprintf(outfile,"%s\n",payload);
  10014. ChargingProfileAdded = TRUE;
  10015. }
  10016. else
  10017. {
  10018. fprintf(outfile,"%s\n",buf);
  10019. }
  10020. }
  10021. }
  10022. } // end of while loop
  10023. fclose(infile);
  10024. fclose(outfile);
  10025. sprintf(rmFileCmd,"rm -f %s",filename);
  10026. system(rmFileCmd);
  10027. rename(tempfile, filename);
  10028. }
  10029. sleep(1);
  10030. result = TRUE;
  10031. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  10032. end:
  10033. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  10034. {
  10035. if(connectorIdInt == 0)
  10036. {
  10037. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  10038. {
  10039. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  10040. }
  10041. }
  10042. else
  10043. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  10044. }
  10045. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  10046. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10047. return result;
  10048. }
  10049. int handleTriggerMessageRequest(char *uuid, char *payload)
  10050. {
  10051. mtrace();
  10052. int result = FAIL;
  10053. int connectorIdIsNULL = FALSE;
  10054. int connectorIdInt =0;
  10055. char sstr[40]={0},sstrtemp[100]={ 0 };
  10056. char requestedMessagestr[40]={0};
  10057. char comfirmstr[20]={0};
  10058. int c = 0;
  10059. char *loc;
  10060. DEBUG_INFO("handleTriggerMessageRequest\n");
  10061. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  10062. strcpy(sstrtemp, stringtrimspace(payload));
  10063. c = 0;
  10064. loc = strstr(sstrtemp, "requestedMessage");
  10065. while (loc[3+strlen("requestedMessage")+c] != '\"')
  10066. {
  10067. sstr[c] = loc[3+strlen("requestedMessage")+c];
  10068. c++;
  10069. }
  10070. sstr[c] = '\0';
  10071. strcpy(requestedMessagestr, sstr);
  10072. c = 0;
  10073. loc = strstr(sstrtemp, "connectorId");
  10074. if(loc == NULL)
  10075. {
  10076. connectorIdIsNULL = TRUE;
  10077. }
  10078. else
  10079. {
  10080. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10081. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  10082. {
  10083. sstr[c] = loc[strlen("connectorId")+2+c];
  10084. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10085. c++;
  10086. }
  10087. sstr[c] = '\0';
  10088. connectorIdInt = atoi(sstr);
  10089. }
  10090. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  10091. {
  10092. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  10093. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  10094. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10095. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  10096. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  10097. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  10098. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  10099. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  10100. {
  10101. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10102. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10103. return TRUE;
  10104. }
  10105. else
  10106. {
  10107. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10108. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10109. }
  10110. }
  10111. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  10112. {
  10113. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  10114. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10115. return TRUE;
  10116. }
  10117. //==========================
  10118. // Trigger message
  10119. //==========================
  10120. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10121. {
  10122. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  10123. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  10124. {
  10125. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10126. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  10127. }
  10128. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10129. }
  10130. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  10131. {
  10132. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  10133. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10134. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10135. }
  10136. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  10137. {
  10138. //sendBootNotificationRequest();
  10139. server_sign = FALSE;
  10140. }
  10141. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  10142. {
  10143. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  10144. }
  10145. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  10146. {
  10147. if(connectorIdIsNULL == FALSE)
  10148. {
  10149. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  10150. {
  10151. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  10152. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  10153. }
  10154. }
  10155. else
  10156. {
  10157. for(int idx=0;idx< gunTotalNumber;idx++)
  10158. {
  10159. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10160. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10161. }
  10162. }
  10163. }
  10164. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  10165. {
  10166. if(connectorIdIsNULL == FALSE)
  10167. {
  10168. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  10169. {
  10170. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  10171. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  10172. }
  10173. }
  10174. else
  10175. {
  10176. for(int idx=0;idx< gunTotalNumber;idx++)
  10177. {
  10178. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  10179. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  10180. }
  10181. }
  10182. }
  10183. return result;
  10184. }
  10185. int handleUnlockConnectorRequest(char *uuid, char *payload)
  10186. {
  10187. mtrace();
  10188. int result = FAIL;
  10189. int connectorIdInt =0;
  10190. char comfirmstr[20]={0};
  10191. int tempIndex = 0;
  10192. json_object *UnlockConnector;
  10193. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  10194. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  10195. UnlockConnector = json_tokener_parse(payload);
  10196. if(!is_error(UnlockConnector))
  10197. {
  10198. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  10199. {
  10200. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  10201. }
  10202. }
  10203. json_object_put(UnlockConnector);
  10204. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  10205. if(gunTotalNumber == 0)
  10206. {
  10207. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10208. goto end;
  10209. }
  10210. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  10211. {
  10212. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10213. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10214. goto end;
  10215. }
  10216. else
  10217. {
  10218. //check Transaction active
  10219. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  10220. {
  10221. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10222. {
  10223. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10224. }
  10225. else
  10226. {
  10227. tempIndex = connectorIdInt -1;
  10228. }
  10229. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10230. {
  10231. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10232. {
  10233. //stop Transaction
  10234. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10235. }
  10236. }
  10237. }
  10238. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  10239. {
  10240. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10241. {
  10242. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10243. }
  10244. else
  10245. {
  10246. tempIndex = connectorIdInt -1;
  10247. }
  10248. for (int index = 0; index < CCS_QUANTITY; index++)
  10249. {
  10250. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10251. {
  10252. //stop Transaction
  10253. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10254. }
  10255. }
  10256. }
  10257. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  10258. {
  10259. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10260. {
  10261. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10262. }
  10263. else
  10264. {
  10265. tempIndex = connectorIdInt -1;
  10266. }
  10267. for (int index = 0; index < GB_QUANTITY; index++)
  10268. {
  10269. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  10270. {
  10271. //stop Transaction
  10272. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10273. }
  10274. }
  10275. }
  10276. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  10277. {
  10278. tempIndex = connectorIdInt -1;
  10279. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10280. {
  10281. 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)))
  10282. {
  10283. //stop Transaction
  10284. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10285. }
  10286. }
  10287. }
  10288. else
  10289. {
  10290. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10291. {
  10292. tempIndex = 2;
  10293. }
  10294. else
  10295. {
  10296. tempIndex = connectorIdInt-1;
  10297. }
  10298. for (int index = 0; index < AC_QUANTITY; index++)
  10299. {
  10300. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10301. {
  10302. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10303. }
  10304. }
  10305. }
  10306. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  10307. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  10308. result = TRUE;
  10309. return result;
  10310. }
  10311. end:
  10312. //json_object_put(obj); --- remove temporally
  10313. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  10314. return result;
  10315. }
  10316. static char UpdateFirmwarepayloadData[300]={0};
  10317. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  10318. {
  10319. mtrace();
  10320. int result = FAIL;
  10321. pthread_t t;
  10322. sendUpdateFirmwareConfirmation(uuid);
  10323. memset(UpdateFirmwarepayloadData, 0, 300);
  10324. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  10325. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  10326. ////pthread_join(t, NULL); //
  10327. //pthread_detach(t);
  10328. //sendUpdateFirmwareConfirmation(uuid);
  10329. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  10330. return result;
  10331. }
  10332. void *UpdateFirmwareProcess(void *data)
  10333. {
  10334. pthread_detach(pthread_self());
  10335. mtrace();
  10336. int retriesInt =0, retryIntervalInt=0;
  10337. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  10338. int port=0;
  10339. char locationstr[512]={0}, retrieveDatestr[36]={0};
  10340. int isSuccess = 0;
  10341. char ftpbuf[512];
  10342. char temp[100];
  10343. char * pch;
  10344. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  10345. json_object *UpdateFirmware;
  10346. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  10347. if(!is_error(UpdateFirmware))
  10348. {
  10349. // Required data
  10350. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  10351. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  10352. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  10353. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  10354. // Optional data
  10355. if(json_object_object_get(UpdateFirmware, "retries"))
  10356. {
  10357. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  10358. }
  10359. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  10360. {
  10361. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  10362. }
  10363. }
  10364. json_object_put(UpdateFirmware);
  10365. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10366. memset(path, 0, ARRAY_SIZE(path));
  10367. // Wait retrieveData
  10368. if(strlen(retrieveDatestr) > 10)
  10369. {
  10370. do
  10371. {
  10372. sleep(1);
  10373. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  10374. }
  10375. // Ready to download
  10376. system("rm -f /mnt/*");
  10377. if(strncmp(locationstr,"http", 4) == 0)
  10378. {
  10379. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10380. sprintf(ftppath,"/%s", path);
  10381. DEBUG_INFO("locationstr: %s\n", locationstr);
  10382. DEBUG_INFO("protocol: %s\n",protocol);
  10383. DEBUG_INFO("host: %s\n",host);
  10384. DEBUG_INFO("path: %s\n",path);
  10385. DEBUG_INFO("ftppath: %s\n",ftppath);
  10386. int ftppathlen=strlen(ftppath);
  10387. int i=1;
  10388. char filenametemp[50];
  10389. while(i < ftppathlen)
  10390. {
  10391. int len=ftppathlen-i;
  10392. if(ftppath[len]== 47) // '/' ascll code: 47
  10393. {
  10394. DEBUG_INFO("compare '/' all right\n");
  10395. break;
  10396. }
  10397. i=i+1;
  10398. }
  10399. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10400. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10401. filenametemp[i+1] = 0;
  10402. do
  10403. {
  10404. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  10405. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10406. sleep(1);
  10407. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  10408. if(!isSuccess)
  10409. {
  10410. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10411. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10412. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  10413. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10414. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10415. }
  10416. else
  10417. {
  10418. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10419. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10420. }
  10421. retriesInt--;
  10422. }while((isSuccess == 0)&&(retriesInt >= 0));
  10423. }
  10424. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  10425. {
  10426. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  10427. memset(temp, 0, ARRAY_SIZE(temp));
  10428. //DEBUG_INFO("locationstr=%s\n",locationstr);
  10429. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  10430. int ftppathlen=strlen(ftpbuf);
  10431. int i=1;
  10432. char filenametemp[50];
  10433. while(i < ftppathlen)
  10434. {
  10435. int len=ftppathlen-i;
  10436. if(ftpbuf[len]== 47) // '/' ascll code: 47
  10437. {
  10438. DEBUG_INFO(" compare '/' all right\n");
  10439. break;
  10440. }
  10441. i=i+1;
  10442. }
  10443. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10444. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  10445. filenametemp[i+1] = 0;
  10446. strncpy(temp, ftpbuf, ftppathlen-i+1);
  10447. pch=strchr(temp,'@');
  10448. if(pch==NULL)
  10449. {
  10450. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10451. protocol, host, &port, path);
  10452. strcpy(user,"anonymous");
  10453. strcpy(password,"");
  10454. }
  10455. else
  10456. {
  10457. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10458. protocol, user, password, host, &port, path);
  10459. }
  10460. sscanf(host,"%[^/]%s",host1, path1);
  10461. sprintf(ftppath,"%s", path1);
  10462. //DEBUG_INFO("protocol =%s\n",protocol);
  10463. //DEBUG_INFO("user =%s\n",user);
  10464. //DEBUG_INFO("password =%s\n",password);
  10465. //DEBUG_INFO("host1 =%s\n",host1);
  10466. //DEBUG_INFO("port =%d\n",port);
  10467. //DEBUG_INFO("path1 =%s\n",path1);
  10468. //DEBUG_INFO("ftppath=%s\n",ftppath);
  10469. //ftpFile(host, user, password, port, ftppath, fname);
  10470. //download firmware pthred
  10471. if(port == 0)
  10472. {
  10473. port = 21;
  10474. }
  10475. do
  10476. {
  10477. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  10478. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10479. sleep(1);
  10480. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  10481. if(!isSuccess)
  10482. {
  10483. //BulldogUtil.sleepMs(interval*1000);
  10484. DEBUG_INFO("Update firmware request and download file fail.\n");
  10485. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10486. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10487. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  10488. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10489. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10490. }
  10491. else
  10492. {
  10493. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10494. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10495. }
  10496. retriesInt--;
  10497. }while((!isSuccess)&&(retriesInt >= 0));
  10498. }
  10499. else
  10500. {
  10501. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10502. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10503. sleep(1);
  10504. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10505. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10506. }
  10507. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  10508. pthread_exit(NULL);
  10509. }
  10510. int handleCertificateSignedRequest(char *uuid, char *payload)
  10511. {
  10512. mtrace();
  10513. int result = PASS;
  10514. json_object *CertificateSigned;
  10515. DEBUG_INFO("handleCertificateSignedRequest...\n");
  10516. CertificateSigned = json_tokener_parse(payload);
  10517. if(!is_error(CertificateSigned))
  10518. {
  10519. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  10520. }
  10521. json_object_put(CertificateSigned);
  10522. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  10523. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  10524. fclose(fp);
  10525. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10526. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  10527. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  10528. sendCertificateSignedConfirmation(uuid);
  10529. return result;
  10530. }
  10531. int handleDeleteCertificateRequest(char *uuid, char *payload)
  10532. {
  10533. mtrace();
  10534. int result = PASS;
  10535. json_object *DeleteCertificate;
  10536. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  10537. DeleteCertificate = json_tokener_parse(payload);
  10538. if(!is_error(DeleteCertificate))
  10539. {
  10540. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  10541. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  10542. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  10543. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  10544. }
  10545. json_object_put(DeleteCertificate);
  10546. /*
  10547. * TODO: Delete certificateSigned process
  10548. */
  10549. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  10550. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  10551. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  10552. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  10553. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  10554. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  10555. sendDeleteCertificateConfirmation(uuid);
  10556. return result;
  10557. }
  10558. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  10559. {
  10560. mtrace();
  10561. int result = PASS;
  10562. json_object *ExtendedTriggerMessage;
  10563. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  10564. ExtendedTriggerMessage = json_tokener_parse(payload);
  10565. if(!is_error(ExtendedTriggerMessage))
  10566. {
  10567. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  10568. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  10569. {
  10570. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  10571. }
  10572. else
  10573. {
  10574. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  10575. }
  10576. }
  10577. json_object_put(ExtendedTriggerMessage);
  10578. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  10579. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  10580. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  10581. {
  10582. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  10583. }
  10584. else
  10585. {
  10586. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  10587. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  10588. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10589. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  10590. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  10591. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  10592. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  10593. {
  10594. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10595. }
  10596. else
  10597. {
  10598. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10599. }
  10600. }
  10601. sendExtendedTriggerMessageConfirmation(uuid);
  10602. //==========================
  10603. // Trigger message
  10604. //==========================
  10605. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  10606. {
  10607. //sendBootNotificationRequest();
  10608. server_sign = FALSE;
  10609. }
  10610. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  10611. {
  10612. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  10613. }
  10614. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10615. {
  10616. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  10617. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  10618. {
  10619. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10620. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  10621. }
  10622. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10623. }
  10624. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  10625. {
  10626. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  10627. }
  10628. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  10629. {
  10630. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  10631. {
  10632. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  10633. }
  10634. else
  10635. {
  10636. for(int idx=0;idx< gunTotalNumber;idx++)
  10637. {
  10638. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10639. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10640. }
  10641. }
  10642. }
  10643. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  10644. {
  10645. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  10646. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  10647. {
  10648. system("openssl req -newkey rsa:2048 -out /Storage/OCPP/certCP.csr -nodes -keyout /Storage/OCPP/certCP.key -subj \"/C=TW/ST=Taiwan/L=Taoyuan/O=Phihong Technology/OU=IT/CN=phihong.com\" &");
  10649. }
  10650. }
  10651. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  10652. {
  10653. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  10654. {
  10655. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  10656. }
  10657. else
  10658. {
  10659. for(int idx=0;idx< gunTotalNumber;idx++)
  10660. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  10661. }
  10662. }
  10663. return result;
  10664. }
  10665. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  10666. {
  10667. mtrace();
  10668. int result = PASS;
  10669. json_object *GetInstalledCertificateIds;
  10670. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  10671. GetInstalledCertificateIds = json_tokener_parse(payload);
  10672. if(!is_error(GetInstalledCertificateIds))
  10673. {
  10674. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  10675. }
  10676. json_object_put(GetInstalledCertificateIds);
  10677. /*
  10678. * TODO: Return installed certificate process
  10679. */
  10680. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  10681. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  10682. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  10683. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  10684. sendGetInstalledCertificateIdsConfirmation(uuid);
  10685. return result;
  10686. }
  10687. int handleGetLogRequest(char *uuid, char *payload)
  10688. {
  10689. mtrace();
  10690. int result = PASS;
  10691. json_object *GetLog;
  10692. DEBUG_INFO("handleGetLogRequest...\n");
  10693. GetLog = json_tokener_parse(payload);
  10694. if(!is_error(GetLog))
  10695. {
  10696. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  10697. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  10698. if(json_object_object_get(GetLog, "retries") != NULL)
  10699. {
  10700. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  10701. }
  10702. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  10703. {
  10704. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  10705. }
  10706. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  10707. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  10708. {
  10709. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  10710. }
  10711. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  10712. {
  10713. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  10714. }
  10715. }
  10716. json_object_put(GetLog);
  10717. /*
  10718. * TODO: Upload log process
  10719. */
  10720. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  10721. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  10722. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  10723. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  10724. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  10725. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  10726. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  10727. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  10728. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  10729. sendGetLogConfirmation(uuid);
  10730. return result;
  10731. }
  10732. int handleInstallCertificateRequest(char *uuid, char *payload)
  10733. {
  10734. mtrace();
  10735. int result = PASS;
  10736. json_object *InstallCertificate;
  10737. DEBUG_INFO("handleInstallCertificateRequest...\n");
  10738. InstallCertificate = json_tokener_parse(payload);
  10739. if(!is_error(InstallCertificate))
  10740. {
  10741. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  10742. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  10743. /*
  10744. * TODO: Install certificate process
  10745. */
  10746. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  10747. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  10748. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  10749. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  10750. sendInstallCertificateConfirmation(uuid);
  10751. }
  10752. json_object_put(InstallCertificate);
  10753. return result;
  10754. }
  10755. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  10756. {
  10757. mtrace();
  10758. int result = PASS;
  10759. json_object *SignedUpdateFirmware;
  10760. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  10761. SignedUpdateFirmware = json_tokener_parse(payload);
  10762. if(!is_error(SignedUpdateFirmware))
  10763. {
  10764. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  10765. {
  10766. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  10767. }
  10768. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  10769. {
  10770. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  10771. }
  10772. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  10773. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  10774. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  10775. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  10776. {
  10777. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  10778. }
  10779. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  10780. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  10781. }
  10782. json_object_put(SignedUpdateFirmware);
  10783. /*
  10784. * TODO: Upgrade firmware process
  10785. */
  10786. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  10787. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  10788. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  10789. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  10790. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  10791. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  10792. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  10793. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  10794. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  10795. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  10796. sendInstallCertificateConfirmation(uuid);
  10797. return result;
  10798. }
  10799. int handleUnknownRequest(char *uuid, char *payload)
  10800. {
  10801. mtrace();
  10802. int result = PASS;
  10803. DEBUG_INFO("handleUnknownRequest...\n");
  10804. sendUnknownConfirmation(uuid);
  10805. result = PASS;
  10806. return result;
  10807. }
  10808. //==========================================
  10809. // Handle server response routine
  10810. //==========================================
  10811. void handleAuthorizeResponse(char *payload, int gun_index)
  10812. {
  10813. mtrace();
  10814. char expiryDatestr[30]={0};
  10815. char parentIdTagstr[20]={0};
  10816. char statusstr[20]={0};
  10817. int expiryDateISNULL=FALSE;
  10818. int parentIdTagISNULL=FALSE;
  10819. DEBUG_INFO("handleAuthorizeResponse...\n");
  10820. json_object *Authorize;
  10821. Authorize = json_tokener_parse(payload);
  10822. if(!is_error(Authorize))
  10823. {
  10824. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  10825. {
  10826. // Required data
  10827. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  10828. // Optional data
  10829. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  10830. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  10831. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  10832. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  10833. }
  10834. }
  10835. json_object_put(Authorize);
  10836. if(expiryDateISNULL == FALSE)
  10837. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  10838. if(parentIdTagISNULL == FALSE)
  10839. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  10840. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  10841. //Update idTag information to authorization cache if supproted
  10842. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  10843. {
  10844. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  10845. }
  10846. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  10847. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  10848. authorizeRetryTimes = 0;
  10849. }
  10850. void handleBootNotificationResponse(char *payload, int gun_index)
  10851. {
  10852. mtrace();
  10853. char statusStr[12]={0};
  10854. char currentTimeStr[30]={0};
  10855. int intervalInt = 0;
  10856. DEBUG_INFO("handleBootNotificationResponse...\n");
  10857. json_object *BootNotification;
  10858. BootNotification = json_tokener_parse(payload);
  10859. if(!is_error(BootNotification))
  10860. {
  10861. // Required data
  10862. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  10863. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  10864. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  10865. }
  10866. json_object_put(BootNotification);
  10867. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10868. BootNotificationInterval = intervalInt;
  10869. HeartBeatWaitTime = intervalInt;
  10870. //write back to ShmOCPP16Data->BootNotification
  10871. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  10872. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10873. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  10874. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  10875. {
  10876. server_sign = TRUE;
  10877. server_pending =FALSE;
  10878. }
  10879. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  10880. {
  10881. server_pending = TRUE;
  10882. }
  10883. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  10884. srand(time(NULL));
  10885. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  10886. SetOcppConnStatus(TRUE);
  10887. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  10888. }
  10889. void handleDataTransferResponse(char *payload, int gun_index)
  10890. {
  10891. char sstr[160]={0};//sstr[200]={ 0 };
  10892. int c = 0;
  10893. char *loc;
  10894. DEBUG_INFO("handleDataTransferResponse ...\n");
  10895. loc = strstr(payload, "status");
  10896. printf("loc=%s\n",loc);
  10897. c = 0;
  10898. while (loc[3+strlen("status")+c] != '\"')
  10899. {
  10900. sstr[c] = loc[3+strlen("status")+c];
  10901. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10902. c++;
  10903. }
  10904. sstr[c] = '\0';
  10905. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  10906. }
  10907. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  10908. {
  10909. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  10910. //struct json_object *obj;
  10911. // obj = json_tokener_parse(payload);
  10912. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  10913. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  10914. //No fields are defined.
  10915. }
  10916. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  10917. {
  10918. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  10919. //struct json_object *obj;
  10920. // obj = json_tokener_parse(payload);
  10921. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  10922. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  10923. //No fields are defined.
  10924. }
  10925. void handleHeartbeatResponse(char *payload, int gun_index)
  10926. {
  10927. mtrace();
  10928. DEBUG_INFO("handleHeartbeatResponse...\n");
  10929. json_object *Heartbeat;
  10930. Heartbeat = json_tokener_parse(payload);
  10931. if(!is_error(Heartbeat))
  10932. {
  10933. // Required data
  10934. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  10935. }
  10936. json_object_put(Heartbeat);
  10937. if(FirstHeartBeat == 0)
  10938. {
  10939. FirstHeartBeat = 1;
  10940. DEBUG_INFO("FirstHeartBeat \n");
  10941. }
  10942. HeartBeatWithNOResponse = 0;
  10943. clientTime.Heartbeat=time((time_t*)NULL);
  10944. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  10945. }
  10946. void handleMeterValuesResponse(char *payload, int gun_index)
  10947. {
  10948. mtrace();
  10949. DEBUG_INFO("handleMeterValuesResponse...\n");
  10950. }
  10951. void handleStartTransactionResponse(char *payload, int gun_index)
  10952. {
  10953. mtrace();
  10954. //int transactionIdInt = 0;
  10955. FILE *outfile;
  10956. char data[100]={0};
  10957. DEBUG_INFO("handleStartTransactionResponse...\n");
  10958. json_object *StartTransaction;
  10959. StartTransaction = json_tokener_parse(payload);
  10960. if(!is_error(StartTransaction))
  10961. {
  10962. // Required data
  10963. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  10964. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  10965. // Optional data
  10966. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  10967. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  10968. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10969. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  10970. }
  10971. json_object_put(StartTransaction);
  10972. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  10973. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  10974. //-----------Start : write to the Queue TransactionId file -----------------//
  10975. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  10976. {}
  10977. else
  10978. {
  10979. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  10980. if(log == NULL)
  10981. {
  10982. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  10983. return ;
  10984. }
  10985. else
  10986. {
  10987. fclose(log);
  10988. }
  10989. }
  10990. // open file for writing
  10991. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  10992. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  10993. {
  10994. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  10995. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  10996. fputs(data, outfile);
  10997. fclose (outfile);
  10998. }
  10999. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11000. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11001. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  11002. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  11003. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11004. }
  11005. void handleStatusNotificationResponse(char *payload, int gun_index)
  11006. {
  11007. mtrace();
  11008. DEBUG_INFO("handleStatusNotificationResponse...\n");
  11009. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  11010. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  11011. }
  11012. void handleStopTransactionnResponse(char *payload, int gun_index)
  11013. {
  11014. mtrace();
  11015. DEBUG_INFO("handleStopTransactionnResponse...\n");
  11016. json_object *StopTransaction;
  11017. StopTransaction = json_tokener_parse(payload);
  11018. if(!is_error(StopTransaction))
  11019. {
  11020. // Optional data
  11021. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  11022. {
  11023. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  11024. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  11025. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  11026. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11027. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  11028. }
  11029. }
  11030. json_object_put(StopTransaction);
  11031. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  11032. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  11033. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11034. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11035. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  11036. }
  11037. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  11038. {
  11039. mtrace();
  11040. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  11041. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  11042. }
  11043. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  11044. {
  11045. mtrace();
  11046. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  11047. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  11048. }
  11049. void handleSignCertificateResponse(char *payload, int gun_index)
  11050. {
  11051. mtrace();
  11052. DEBUG_INFO("handleSignCertificateResponse...\n");
  11053. json_object *SignCertificate;
  11054. SignCertificate = json_tokener_parse(payload);
  11055. if(!is_error(SignCertificate))
  11056. {
  11057. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  11058. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  11059. }
  11060. json_object_put(SignCertificate);
  11061. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  11062. }
  11063. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11064. {
  11065. mtrace();
  11066. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  11067. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  11068. }
  11069. //==========================================
  11070. // Handle Error routine
  11071. //==========================================
  11072. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  11073. {
  11074. mtrace();
  11075. #ifdef SystemLogMessage
  11076. DEBUG_INFO("errorCode: %s\n", errorCode);
  11077. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  11078. DEBUG_INFO("errorDetails: %s\n", payload);
  11079. #endif
  11080. }
  11081. //===============================================
  11082. // Common routine
  11083. //===============================================
  11084. int initialConfigurationTable(void)
  11085. {
  11086. //clock_t start_t, end_t, total_t;
  11087. FILE *fp;
  11088. FILE *outfile;
  11089. char str[512]={0};
  11090. char sstr[256]={0};
  11091. int c = 0;
  11092. char *loc;
  11093. int confVersion = 1;
  11094. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  11095. //start_t = clock();
  11096. //printf("Starting of the program, start_t = %ld\n", start_t);
  11097. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  11098. // Check configuration file size is correct
  11099. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  11100. {
  11101. struct stat st;
  11102. stat("/Storage/OCPP/OCPPConfiguration", &st);
  11103. if(st.st_size < 3100)
  11104. {
  11105. system("rm -f /Storage/OCPP/OCPPConfiguration");
  11106. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  11107. }
  11108. }
  11109. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  11110. {
  11111. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  11112. if(outfile == NULL)
  11113. {
  11114. DEBUG_INFO("Error opening file\n");
  11115. return FALSE;
  11116. }
  11117. /*Core Profile*/
  11118. //AllowOfflineTxForUnknownId
  11119. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11120. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11121. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  11122. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11123. //AuthorizationCacheEnabled
  11124. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11127. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11128. //AuthorizeRemoteTxRequests
  11129. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11130. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11131. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  11132. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11133. //BlinkRepeat
  11134. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11135. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11136. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11137. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11138. //ClockAlignedDataInterval
  11139. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11140. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11141. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11142. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11143. //ConnectionTimeOut
  11144. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11145. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11146. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11147. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11148. //GetConfigurationMaxKeys
  11149. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11150. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11151. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  11152. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11153. // HeartbeatInterval
  11154. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11155. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11156. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  11157. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11158. // LightIntensity
  11159. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11160. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11162. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11163. // LocalAuthorizeOffline
  11164. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  11165. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11166. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11167. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11168. // LocalPreAuthorize
  11169. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  11170. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11171. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11172. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11173. // MaxEnergyOnInvalidId
  11174. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11175. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  11176. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  11177. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  11178. // MeterValuesAlignedData
  11179. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  11180. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  11181. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11182. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11183. else
  11184. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11185. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  11186. // MeterValuesAlignedDataMaxLength
  11187. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  11188. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  11189. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11190. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  11191. else
  11192. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "9" );
  11193. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  11194. // MeterValuesSampledData
  11195. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  11196. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  11197. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11198. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11199. else
  11200. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11201. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  11202. // MeterValuesSampledDataMaxLength
  11203. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  11204. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  11205. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11206. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  11207. else
  11208. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "9" );
  11209. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  11210. // MeterValueSampleInterval
  11211. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  11212. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  11213. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  11214. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  11215. // MinimumStatusDuration
  11216. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  11217. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  11218. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  11219. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  11220. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  11221. // NumberOfConnectors
  11222. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  11223. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  11224. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11225. {
  11226. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  11227. }
  11228. else
  11229. {
  11230. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  11231. }
  11232. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  11233. // ResetRetries
  11234. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  11235. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  11236. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  11237. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  11238. // ConnectorPhaseRotation
  11239. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  11240. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  11241. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  11242. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  11243. // ConnectorPhaseRotationMaxLength
  11244. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  11245. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  11246. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  11247. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  11248. // StopTransactionOnEVSideDisconnect
  11249. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  11250. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  11251. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  11252. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  11253. // StopTransactionOnInvalidId
  11254. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  11255. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  11256. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  11257. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  11258. // StopTxnAlignedData
  11259. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  11260. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  11261. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  11262. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  11263. // StopTxnAlignedDataMaxLength
  11264. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  11265. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  11266. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11267. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11268. // StopTxnSampledData
  11269. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11270. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11271. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11272. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11273. else
  11274. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11275. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11276. // StopTxnSampledDataMaxLength
  11277. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11278. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11279. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11280. {
  11281. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  11282. }
  11283. else
  11284. {
  11285. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  11286. }
  11287. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11288. // SupportedFeatureProfiles
  11289. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11290. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11291. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11292. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  11293. // SupportedFeatureProfilesMaxLength
  11294. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  11295. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  11296. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  11297. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  11298. // TransactionMessageAttempts
  11299. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11301. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11302. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11303. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11304. // TransactionMessageRetryInterval
  11305. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11306. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11307. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11308. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11309. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11310. // UnlockConnectorOnEVSideDisconnect
  11311. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11312. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11313. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11314. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11315. // WebSocketPingInterval
  11316. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11317. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11318. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11319. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11320. // QueueOffLineStartTransactionMessage
  11321. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  11322. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  11323. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  11324. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  11325. // AuthorizationKey
  11326. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  11327. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  11328. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "" );
  11329. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  11330. // SecurityProfile
  11331. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  11332. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  11333. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "0" );
  11334. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  11335. // DefaultPrice
  11336. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  11337. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  11338. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  11339. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  11340. // CustomDisplayCostAndPrice
  11341. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  11342. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  11343. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  11344. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  11345. // CustomIdleFeeAfterStop
  11346. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  11347. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  11348. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  11349. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  11350. // Configuration Version
  11351. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  11352. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  11353. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  11354. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  11355. //* Local Auth List Management Profile*/
  11356. #if 0
  11357. //For OCTT Test Case
  11358. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11359. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  11360. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11361. #endif
  11362. #if 1
  11363. //LocalAuthListEnabled
  11364. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11365. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  11366. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11367. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11368. #endif
  11369. //LocalAuthListMaxLength
  11370. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  11371. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  11372. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  11373. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  11374. //SendLocalListMaxLength
  11375. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  11376. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11377. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  11378. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11379. //ReserveConnectorZeroSupported
  11380. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11381. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11382. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11383. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11384. //* Smart Charging Profile */
  11385. //ChargeProfileMaxStackLevel
  11386. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11387. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11388. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11389. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11390. // ChargingScheduleAllowedChargingRateUnit
  11391. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11392. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11393. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  11394. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11395. // ChargingScheduleMaxPeriods
  11396. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11397. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11398. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11399. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11400. // ConnectorSwitch3to1PhaseSupported
  11401. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11402. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11403. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  11404. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11405. // MaxChargingProfilesInstalled
  11406. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11407. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11408. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  11409. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11410. fclose(outfile);
  11411. }
  11412. else
  11413. {
  11414. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  11415. char keystr[60]={0};
  11416. char readonlystr[10]={0};
  11417. char valuestr[256]={0};
  11418. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  11419. if(fp == NULL) {
  11420. DEBUG_INFO("Error opening file");
  11421. return FALSE;
  11422. }
  11423. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  11424. {
  11425. //DEBUG_INFO("Get Configuration \n");
  11426. if(strlen(str) > 0)
  11427. {
  11428. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  11429. //*************************key*********************************/
  11430. if(strstr(str, "key") != NULL)
  11431. {
  11432. loc = strstr(str, "key");
  11433. c = 0;
  11434. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11435. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  11436. {
  11437. sstr[c] = loc[strlen("key")+3+c];
  11438. c++;
  11439. }
  11440. sstr[c] = '\0';
  11441. strcpy(keystr,sstr);
  11442. }
  11443. //*************************readonly*********************************/
  11444. if(strstr(str, "readonly") != NULL)
  11445. {
  11446. loc = strstr(str, "readonly");
  11447. c = 0;
  11448. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11449. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  11450. {
  11451. sstr[c] = loc[strlen("readonly")+2+c];
  11452. c++;
  11453. }
  11454. sstr[c] = '\0';
  11455. strcpy(readonlystr,sstr);
  11456. }
  11457. //*************************value*********************************/
  11458. if(strstr(str, "value") != NULL)
  11459. {
  11460. loc = strstr(str, "value");
  11461. c = 0;
  11462. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11463. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  11464. {
  11465. sstr[c] = loc[strlen("value")+3+c];
  11466. c++;
  11467. }
  11468. sstr[c] = '\0';
  11469. strcpy(valuestr,sstr);
  11470. }
  11471. // DEBUG_INFO("keystr=%s\n",keystr);
  11472. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  11473. // DEBUG_INFO("valuestr=%s\n",valuestr);
  11474. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  11475. {
  11476. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11477. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11478. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  11479. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  11480. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  11481. }
  11482. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  11483. {
  11484. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11485. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11486. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  11487. }
  11488. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  11489. {
  11490. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11491. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  11492. }
  11493. if(strcmp(keystr, "BlinkRepeat") == 0)
  11494. {
  11495. //Charger.BlinkRepeat = Integer.parseInt(value);
  11496. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11497. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  11498. }
  11499. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  11500. {
  11501. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11502. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  11503. }
  11504. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  11505. {
  11506. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11507. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  11508. }
  11509. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  11510. {
  11511. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11512. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  11513. }
  11514. if(strcmp(keystr, "HeartbeatInterval") == 0)
  11515. {
  11516. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11517. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  11518. HeartBeatWaitTime = atoi(valuestr);
  11519. }
  11520. if(strcmp(keystr, "LightIntensity") == 0)
  11521. {
  11522. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11523. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  11524. }
  11525. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  11526. {
  11527. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11528. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  11529. }
  11530. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  11531. {
  11532. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11533. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  11534. }
  11535. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  11536. {
  11537. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11538. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  11539. }
  11540. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  11541. {
  11542. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11543. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  11544. }
  11545. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  11546. {
  11547. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11548. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  11549. }
  11550. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  11551. {
  11552. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11553. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  11554. }
  11555. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  11556. {
  11557. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11558. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  11559. }
  11560. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  11561. {
  11562. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11563. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  11564. }
  11565. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  11566. {
  11567. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11568. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  11569. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  11570. }
  11571. if(strcmp(keystr, "NumberOfConnectors") == 0)
  11572. {
  11573. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11574. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  11575. }
  11576. if(strcmp(keystr, "ResetRetries") == 0)
  11577. {
  11578. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11579. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  11580. }
  11581. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  11582. {
  11583. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11584. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  11585. }
  11586. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  11587. {
  11588. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11589. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  11590. }
  11591. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  11592. {
  11593. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11594. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  11595. }
  11596. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  11597. {
  11598. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11599. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  11600. }
  11601. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  11602. {
  11603. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11604. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  11605. }
  11606. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  11607. {
  11608. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11609. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11610. }
  11611. if(strcmp(keystr, "StopTxnSampledData") == 0)
  11612. {
  11613. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11614. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  11615. }
  11616. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  11617. {
  11618. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11619. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11620. }
  11621. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  11622. {
  11623. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11624. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  11625. }
  11626. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  11627. {
  11628. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11629. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  11630. }
  11631. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  11632. {
  11633. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11634. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  11635. TransactionMessageAttemptsValue = atoi(valuestr);
  11636. }
  11637. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  11638. {
  11639. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11640. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  11641. TransactionMessageRetryIntervalValue = atoi(valuestr);
  11642. }
  11643. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  11644. {
  11645. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11646. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  11647. }
  11648. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  11649. {
  11650. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11651. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  11652. }
  11653. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  11654. {
  11655. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11656. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  11657. }
  11658. if(strcmp(keystr, "AuthorizationKey") == 0)
  11659. {
  11660. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11661. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  11662. }
  11663. if(strcmp(keystr, "SecurityProfile") == 0)
  11664. {
  11665. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11666. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  11667. }
  11668. if(strcmp(keystr, "DefaultPrice") == 0)
  11669. {
  11670. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11671. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  11672. }
  11673. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  11674. {
  11675. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11676. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  11677. }
  11678. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  11679. {
  11680. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11681. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  11682. }
  11683. if(strcmp(keystr, "ConfigurationVersion") == 0)
  11684. {
  11685. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11686. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  11687. }
  11688. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  11689. {
  11690. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11691. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  11692. }
  11693. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  11694. {
  11695. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11696. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  11697. }
  11698. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  11699. {
  11700. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11701. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  11702. }
  11703. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  11704. {
  11705. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11706. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  11707. }
  11708. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  11709. {
  11710. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11711. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  11712. }
  11713. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  11714. {
  11715. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11716. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  11717. }
  11718. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  11719. {
  11720. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11721. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  11722. }
  11723. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  11724. {
  11725. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11726. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  11727. }
  11728. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  11729. {
  11730. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11731. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  11732. }
  11733. }
  11734. }
  11735. fclose(fp);
  11736. }
  11737. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  11738. {
  11739. return PASS;
  11740. }
  11741. else
  11742. {
  11743. return FAIL;
  11744. }
  11745. }
  11746. void StoreConfigurationTable(void)
  11747. {
  11748. FILE *outfile;
  11749. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  11750. if(outfile == NULL)
  11751. {
  11752. DEBUG_INFO("Error opening file");
  11753. return ;
  11754. }
  11755. /*Core Profile*/
  11756. //AllowOfflineTxForUnknownId
  11757. /*
  11758. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11759. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  11760. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11761. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  11762. */
  11763. //DEBUG_INFO("data=%s\n",data);
  11764. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11765. //AuthorizationCacheEnabled
  11766. /*
  11767. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11768. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11769. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11770. */
  11771. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11772. //AuthorizeRemoteTxRequests
  11773. /*
  11774. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11775. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11776. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  11777. */
  11778. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11779. //BlinkRepeat
  11780. /*
  11781. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11782. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11783. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11784. */
  11785. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11786. //ClockAlignedDataInterval
  11787. /*
  11788. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11789. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11790. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11791. */
  11792. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11793. //ConnectionTimeOut
  11794. /*
  11795. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11796. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11797. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11798. */
  11799. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11800. //GetConfigurationMaxKeys
  11801. /*
  11802. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11804. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  11805. */
  11806. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11807. // HeartbeatInterval
  11808. /*
  11809. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11810. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11811. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  11812. */
  11813. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11814. // LightIntensity
  11815. /*
  11816. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11818. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11819. */
  11820. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11821. // LocalAuthorizeOffline
  11822. /*
  11823. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  11824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11825. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11826. */
  11827. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11828. // LocalPreAuthorize
  11829. /*
  11830. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  11831. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11832. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11833. */
  11834. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11835. // MaxEnergyOnInvalidId
  11836. /*
  11837. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11838. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  11839. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  11840. */
  11841. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  11842. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  11843. // MeterValuesAlignedData
  11844. /*
  11845. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  11846. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  11847. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  11848. */
  11849. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  11850. // MeterValuesAlignedDataMaxLength
  11851. /*
  11852. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  11853. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  11854. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  11855. */
  11856. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  11857. // MeterValuesSampledData
  11858. /*
  11859. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  11860. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  11861. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  11862. */
  11863. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  11864. // MeterValuesSampledDataMaxLength
  11865. /*
  11866. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  11867. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  11868. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  11869. */
  11870. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  11871. // MeterValueSampleInterval
  11872. /*
  11873. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  11874. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  11875. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  11876. */
  11877. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  11878. // MinimumStatusDuration
  11879. /*
  11880. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  11881. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  11882. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  11883. */
  11884. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  11885. // NumberOfConnectors
  11886. /*
  11887. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  11888. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  11889. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11890. {
  11891. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  11892. }
  11893. else
  11894. {
  11895. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  11896. }
  11897. */
  11898. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  11899. // ResetRetries
  11900. /*
  11901. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  11902. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  11903. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  11904. */
  11905. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  11906. // ConnectorPhaseRotation
  11907. /*
  11908. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  11909. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  11910. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  11911. */
  11912. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  11913. // ConnectorPhaseRotationMaxLength
  11914. /*
  11915. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  11916. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  11917. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  11918. */
  11919. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  11920. // StopTransactionOnEVSideDisconnect
  11921. /*
  11922. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  11923. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  11924. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  11925. */
  11926. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  11927. // StopTransactionOnInvalidId
  11928. /*
  11929. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  11930. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  11931. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  11932. */
  11933. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  11934. // StopTxnAlignedData
  11935. /*
  11936. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  11937. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  11938. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  11939. */
  11940. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  11941. // StopTxnAlignedDataMaxLength
  11942. /*
  11943. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  11944. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  11945. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11946. */
  11947. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11948. // StopTxnSampledData
  11949. /*
  11950. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11951. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11952. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  11953. */
  11954. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11955. // StopTxnSampledDataMaxLength
  11956. /*
  11957. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11958. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11959. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  11960. */
  11961. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11962. // SupportedFeatureProfiles
  11963. /*
  11964. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11965. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11966. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11967. */
  11968. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  11969. // SupportedFeatureProfilesMaxLength
  11970. /*
  11971. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  11972. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  11973. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  11974. */
  11975. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  11976. // TransactionMessageAttempts
  11977. /*
  11978. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11979. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11980. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11981. */
  11982. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11983. // TransactionMessageRetryInterval
  11984. /*
  11985. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11986. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11987. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11988. */
  11989. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11990. // UnlockConnectorOnEVSideDisconnect
  11991. /*
  11992. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11993. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11994. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11995. */
  11996. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11997. // WebSocketPingInterval
  11998. /*
  11999. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12000. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12001. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12002. */
  12003. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12004. // QueueOffLineStartTransactionMessage
  12005. /*
  12006. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  12007. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  12008. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  12009. */
  12010. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  12011. // AuthorizationKey
  12012. /*
  12013. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12014. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12015. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  12016. */
  12017. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12018. // SecurityProfile
  12019. /*
  12020. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12021. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12022. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  12023. */
  12024. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12025. // DefaultPrice
  12026. /*
  12027. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12028. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12029. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12030. */
  12031. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12032. // CustomDisplayCostAndPrice
  12033. /*
  12034. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12035. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12036. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12037. */
  12038. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12039. // CustomIdleFeeAfterStop
  12040. /*
  12041. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12042. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12043. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12044. */
  12045. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12046. // ConfigurationVersion
  12047. /*
  12048. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  12049. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12050. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  12051. */
  12052. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12053. //* Local Auth List Management Profile*/
  12054. //LocalAuthListEnabled
  12055. /*
  12056. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12057. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12058. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12059. */
  12060. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12061. //LocalAuthListMaxLength
  12062. /*
  12063. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12064. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12065. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  12066. */
  12067. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12068. //SendLocalListMaxLength
  12069. /*
  12070. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12071. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12072. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  12073. */
  12074. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12075. //ReserveConnectorZeroSupported
  12076. /*
  12077. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12078. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12079. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12080. */
  12081. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12082. //* Smart Charging Profile */
  12083. //ChargeProfileMaxStackLevel
  12084. /*
  12085. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12086. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12087. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12088. */
  12089. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12090. // ChargingScheduleAllowedChargingRateUnit
  12091. /*
  12092. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12093. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12094. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  12095. */
  12096. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12097. // ChargingScheduleMaxPeriods
  12098. /*
  12099. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12100. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12101. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12102. */
  12103. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12104. // ConnectorSwitch3to1PhaseSupported
  12105. /*
  12106. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12107. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12108. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  12109. */
  12110. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12111. // MaxChargingProfilesInstalled
  12112. /*
  12113. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12114. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12115. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12116. */
  12117. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12118. fclose(outfile);
  12119. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12120. }
  12121. void getKeyValue(char *keyReq)
  12122. {
  12123. int isEmpty = FALSE;
  12124. int isKnowKey = FALSE;
  12125. DEBUG_INFO("keyReq = %s\n", keyReq);
  12126. if((keyReq == NULL) || (strlen(keyReq) == 0))
  12127. isEmpty = TRUE;
  12128. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  12129. {
  12130. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  12131. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  12132. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  12133. {
  12134. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  12135. }
  12136. else
  12137. {
  12138. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  12139. }
  12140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  12141. isKnowKey = TRUE;
  12142. }
  12143. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  12144. {
  12145. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  12146. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  12147. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  12148. {
  12149. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  12150. }
  12151. else
  12152. {
  12153. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  12154. }
  12155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  12156. isKnowKey = TRUE;
  12157. }
  12158. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  12159. {
  12160. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  12161. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  12162. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  12163. {
  12164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  12165. }
  12166. else
  12167. {
  12168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  12169. }
  12170. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  12171. isKnowKey = TRUE;
  12172. }
  12173. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  12174. {
  12175. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  12176. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  12177. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  12178. {
  12179. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  12180. }
  12181. else
  12182. {
  12183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  12184. }
  12185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  12186. isKnowKey = TRUE;
  12187. }
  12188. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  12189. {
  12190. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  12191. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  12192. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  12193. {
  12194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  12195. }
  12196. else
  12197. {
  12198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  12199. }
  12200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  12201. isKnowKey = TRUE;
  12202. }
  12203. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  12204. {
  12205. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  12206. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  12207. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  12208. {
  12209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  12210. }
  12211. else
  12212. {
  12213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  12214. }
  12215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  12216. isKnowKey = TRUE;
  12217. }
  12218. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  12219. {
  12220. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  12221. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  12222. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  12223. {
  12224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  12225. }
  12226. else
  12227. {
  12228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  12229. }
  12230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  12231. isKnowKey = TRUE;
  12232. }
  12233. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  12234. {
  12235. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  12236. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  12237. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  12238. {
  12239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  12240. }
  12241. else
  12242. {
  12243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  12244. }
  12245. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  12246. isKnowKey = TRUE;
  12247. }
  12248. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  12249. {
  12250. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  12251. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  12252. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  12253. {
  12254. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  12255. }
  12256. else
  12257. {
  12258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  12259. }
  12260. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  12261. isKnowKey = TRUE;
  12262. }
  12263. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  12264. {
  12265. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  12266. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  12267. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  12268. {
  12269. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  12270. }
  12271. else
  12272. {
  12273. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  12274. }
  12275. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  12276. isKnowKey = TRUE;
  12277. }
  12278. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  12279. {
  12280. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  12281. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  12282. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12283. {
  12284. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  12285. }
  12286. else
  12287. {
  12288. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  12289. }
  12290. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  12291. isKnowKey = TRUE;
  12292. }
  12293. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  12294. {
  12295. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  12296. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  12297. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  12298. {
  12299. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  12300. }
  12301. else
  12302. {
  12303. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  12304. }
  12305. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  12306. isKnowKey = TRUE;
  12307. }
  12308. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  12309. {
  12310. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  12311. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  12312. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12313. {
  12314. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  12315. }
  12316. else
  12317. {
  12318. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  12319. }
  12320. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  12321. isKnowKey = TRUE;
  12322. }
  12323. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  12324. {
  12325. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  12326. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  12327. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12328. {
  12329. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12330. }
  12331. else
  12332. {
  12333. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12334. }
  12335. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  12336. isKnowKey = TRUE;
  12337. }
  12338. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  12339. {
  12340. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  12341. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  12342. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12343. {
  12344. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  12345. }
  12346. else
  12347. {
  12348. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  12349. }
  12350. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  12351. isKnowKey = TRUE;
  12352. }
  12353. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  12354. {
  12355. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  12356. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  12357. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12358. {
  12359. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12360. }
  12361. else
  12362. {
  12363. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12364. }
  12365. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  12366. isKnowKey = TRUE;
  12367. }
  12368. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  12369. {
  12370. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  12371. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  12372. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12373. {
  12374. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  12375. }
  12376. else
  12377. {
  12378. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  12379. }
  12380. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  12381. isKnowKey = TRUE;
  12382. }
  12383. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  12384. {
  12385. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  12386. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  12387. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12388. {
  12389. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  12390. }
  12391. else
  12392. {
  12393. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  12394. }
  12395. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  12396. isKnowKey = TRUE;
  12397. }
  12398. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  12399. {
  12400. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  12401. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  12402. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12403. {
  12404. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  12405. }
  12406. else
  12407. {
  12408. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  12409. }
  12410. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  12411. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  12412. isKnowKey = TRUE;
  12413. }
  12414. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  12415. {
  12416. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  12417. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  12418. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12419. {
  12420. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  12421. }
  12422. else
  12423. {
  12424. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  12425. }
  12426. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  12427. isKnowKey = TRUE;
  12428. }
  12429. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  12430. {
  12431. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  12432. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  12433. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12434. {
  12435. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  12436. }
  12437. else
  12438. {
  12439. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  12440. }
  12441. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  12442. isKnowKey = TRUE;
  12443. }
  12444. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  12445. {
  12446. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  12447. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  12448. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12449. {
  12450. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12451. }
  12452. else
  12453. {
  12454. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12455. }
  12456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  12457. isKnowKey = TRUE;
  12458. }
  12459. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  12460. {
  12461. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  12462. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  12463. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12464. {
  12465. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  12466. }
  12467. else
  12468. {
  12469. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  12470. }
  12471. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  12472. isKnowKey = TRUE;
  12473. }
  12474. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  12475. {
  12476. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  12477. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  12478. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12479. {
  12480. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  12481. }
  12482. else
  12483. {
  12484. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  12485. }
  12486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  12487. isKnowKey = TRUE;
  12488. }
  12489. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  12490. {
  12491. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  12492. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  12493. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12494. {
  12495. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  12496. }
  12497. else
  12498. {
  12499. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  12500. }
  12501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  12502. isKnowKey = TRUE;
  12503. }
  12504. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  12505. {
  12506. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  12507. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  12508. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12509. {
  12510. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12511. }
  12512. else
  12513. {
  12514. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12515. }
  12516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  12517. isKnowKey = TRUE;
  12518. }
  12519. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  12520. {
  12521. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  12522. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  12523. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12524. {
  12525. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  12526. }
  12527. else
  12528. {
  12529. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  12530. }
  12531. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  12532. isKnowKey = TRUE;
  12533. }
  12534. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  12535. {
  12536. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  12537. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  12538. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12539. {
  12540. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12541. }
  12542. else
  12543. {
  12544. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12545. }
  12546. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  12547. isKnowKey = TRUE;
  12548. }
  12549. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  12550. {
  12551. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  12552. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  12553. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12554. {
  12555. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  12556. }
  12557. else
  12558. {
  12559. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  12560. }
  12561. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  12562. isKnowKey = TRUE;
  12563. }
  12564. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  12565. {
  12566. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  12567. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  12568. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12569. {
  12570. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12571. }
  12572. else
  12573. {
  12574. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12575. }
  12576. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  12577. isKnowKey = TRUE;
  12578. }
  12579. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  12580. {
  12581. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  12582. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  12583. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12584. {
  12585. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  12586. }
  12587. else
  12588. {
  12589. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  12590. }
  12591. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  12592. isKnowKey = TRUE;
  12593. }
  12594. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  12595. {
  12596. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  12597. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  12598. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12599. {
  12600. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  12601. }
  12602. else
  12603. {
  12604. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  12605. }
  12606. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  12607. isKnowKey = TRUE;
  12608. }
  12609. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  12610. {
  12611. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  12612. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  12613. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12614. {
  12615. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  12616. }
  12617. else
  12618. {
  12619. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  12620. }
  12621. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  12622. isKnowKey = TRUE;
  12623. }
  12624. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  12625. {
  12626. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  12627. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  12628. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12629. {
  12630. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  12631. }
  12632. else
  12633. {
  12634. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  12635. }
  12636. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  12637. isKnowKey = TRUE;
  12638. }
  12639. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  12640. {
  12641. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  12642. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  12643. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12644. {
  12645. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  12646. }
  12647. else
  12648. {
  12649. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  12650. }
  12651. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  12652. isKnowKey = TRUE;
  12653. }
  12654. /*
  12655. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  12656. {
  12657. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  12658. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  12659. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  12660. {
  12661. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  12662. }
  12663. else
  12664. {
  12665. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  12666. }
  12667. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  12668. isKnowKey = TRUE;
  12669. }*/
  12670. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  12671. {
  12672. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  12673. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  12674. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  12675. {
  12676. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  12677. }
  12678. else
  12679. {
  12680. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  12681. }
  12682. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  12683. isKnowKey = TRUE;
  12684. }
  12685. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  12686. {
  12687. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  12688. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  12689. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  12690. {
  12691. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  12692. }
  12693. else
  12694. {
  12695. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  12696. }
  12697. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  12698. isKnowKey = TRUE;
  12699. }
  12700. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  12701. {
  12702. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  12703. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  12704. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  12705. {
  12706. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  12707. }
  12708. else
  12709. {
  12710. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  12711. }
  12712. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  12713. isKnowKey = TRUE;
  12714. }
  12715. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  12716. {
  12717. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  12718. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  12719. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  12720. {
  12721. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  12722. }
  12723. else
  12724. {
  12725. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  12726. }
  12727. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  12728. isKnowKey = TRUE;
  12729. }
  12730. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  12731. {
  12732. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  12733. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  12734. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  12735. {
  12736. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  12737. }
  12738. else
  12739. {
  12740. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  12741. }
  12742. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  12743. isKnowKey = TRUE;
  12744. }
  12745. #if 1
  12746. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  12747. {
  12748. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  12749. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  12750. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12751. {
  12752. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  12753. }
  12754. else
  12755. {
  12756. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  12757. }
  12758. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  12759. isKnowKey = TRUE;
  12760. }
  12761. #endif
  12762. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  12763. {
  12764. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  12765. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  12766. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12767. {
  12768. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12769. }
  12770. else
  12771. {
  12772. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12773. }
  12774. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  12775. isKnowKey = TRUE;
  12776. }
  12777. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  12778. {
  12779. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  12780. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  12781. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12782. {
  12783. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12784. }
  12785. else
  12786. {
  12787. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12788. }
  12789. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  12790. isKnowKey = TRUE;
  12791. }
  12792. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  12793. {
  12794. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  12795. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  12796. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12797. {
  12798. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  12799. }
  12800. else
  12801. {
  12802. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  12803. }
  12804. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12805. isKnowKey = TRUE;
  12806. }
  12807. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  12808. {
  12809. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  12810. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  12811. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12812. {
  12813. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  12814. }
  12815. else
  12816. {
  12817. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  12818. }
  12819. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12820. isKnowKey = TRUE;
  12821. }
  12822. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  12823. {
  12824. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  12825. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  12826. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12827. {
  12828. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  12829. }
  12830. else
  12831. {
  12832. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  12833. }
  12834. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12835. isKnowKey = TRUE;
  12836. }
  12837. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  12838. {
  12839. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  12840. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  12841. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12842. {
  12843. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  12844. }
  12845. else
  12846. {
  12847. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  12848. }
  12849. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12850. isKnowKey = TRUE;
  12851. }
  12852. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  12853. {
  12854. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  12855. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  12856. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12857. {
  12858. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  12859. }
  12860. else
  12861. {
  12862. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  12863. }
  12864. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12865. isKnowKey = TRUE;
  12866. }
  12867. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  12868. {
  12869. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  12870. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  12871. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12872. {
  12873. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  12874. }
  12875. else
  12876. {
  12877. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  12878. }
  12879. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12880. isKnowKey = TRUE;
  12881. }
  12882. //=========================================================
  12883. if(!isEmpty && !isKnowKey)
  12884. {
  12885. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  12886. strcpy(unknownkey[UnknownKeynum], keyReq);
  12887. UnknownKeynum = UnknownKeynum + 1;
  12888. }
  12889. }
  12890. void processUnkownKey(void)
  12891. {
  12892. DEBUG_INFO("processUnkownKey...\n");
  12893. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  12894. for(int index=0; index < UnknownKeynum; index++)
  12895. {
  12896. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  12897. {
  12898. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  12899. }
  12900. }
  12901. }
  12902. int setKeyValue(char *key, char *value)
  12903. {
  12904. int isSuccess = NotSupported;
  12905. int check_ascii=0;
  12906. char str[256]={0};
  12907. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  12908. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  12909. {
  12910. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  12911. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  12912. {
  12913. strcpy(str, (const char*)value);
  12914. for(int i = 0; str[i]; i++){
  12915. str[i] = tolower(str[i]);
  12916. }
  12917. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12918. isSuccess = ConfigurationStatus_Accepted;
  12919. }
  12920. else
  12921. {
  12922. isSuccess = ConfigurationStatus_Rejected;
  12923. }
  12924. }
  12925. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  12926. {
  12927. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  12928. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  12929. {
  12930. strcpy(str, (const char*)value);
  12931. for(int i = 0; str[i]; i++){
  12932. str[i] = tolower(str[i]);
  12933. }
  12934. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12935. isSuccess = ConfigurationStatus_Accepted;
  12936. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  12937. }
  12938. else
  12939. {
  12940. isSuccess = ConfigurationStatus_Rejected;
  12941. }
  12942. }
  12943. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  12944. {
  12945. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  12946. {
  12947. strcpy(str, (const char*)value);
  12948. for(int i = 0; str[i]; i++)
  12949. {
  12950. str[i] = tolower(str[i]);
  12951. }
  12952. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  12953. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12954. isSuccess = ConfigurationStatus_Accepted;
  12955. }
  12956. else
  12957. {
  12958. isSuccess = ConfigurationStatus_Rejected;
  12959. }
  12960. }
  12961. if(strcmp(key, "BlinkRepeat") == 0)
  12962. {
  12963. //Charger.BlinkRepeat = Integer.parseInt(value);
  12964. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  12965. {
  12966. check_ascii = value[0];
  12967. if( (check_ascii < 48) || (check_ascii > 57) )
  12968. {
  12969. isSuccess = ConfigurationStatus_Rejected;
  12970. }
  12971. else
  12972. {
  12973. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  12974. isSuccess = ConfigurationStatus_Accepted;
  12975. }
  12976. }
  12977. else
  12978. {
  12979. isSuccess = ConfigurationStatus_Rejected;
  12980. }
  12981. }
  12982. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  12983. {
  12984. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  12985. {
  12986. check_ascii = value[0];
  12987. if( (check_ascii < 48) || (check_ascii > 57) )
  12988. {
  12989. isSuccess = ConfigurationStatus_Rejected;
  12990. }
  12991. else
  12992. {
  12993. if((atoi(value) == 0) || (atoi(value) >= 10))
  12994. {
  12995. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  12996. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  12997. isSuccess = ConfigurationStatus_Accepted;
  12998. }
  12999. else
  13000. isSuccess = ConfigurationStatus_Rejected;
  13001. }
  13002. }
  13003. else
  13004. {
  13005. isSuccess = ConfigurationStatus_Rejected;
  13006. }
  13007. }
  13008. if(strcmp(key, "ConnectionTimeOut") == 0 )
  13009. {
  13010. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13011. {
  13012. check_ascii = value[0];
  13013. if( (check_ascii < 48) || (check_ascii > 57) )
  13014. {
  13015. isSuccess = ConfigurationStatus_Rejected;
  13016. }
  13017. else
  13018. {
  13019. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  13020. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  13021. isSuccess = ConfigurationStatus_Accepted;
  13022. }
  13023. }
  13024. else
  13025. {
  13026. isSuccess = ConfigurationStatus_Rejected;
  13027. }
  13028. }
  13029. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  13030. {
  13031. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13032. {
  13033. check_ascii = value[0];
  13034. if( (check_ascii < 48) || (check_ascii > 57) )
  13035. {
  13036. isSuccess = ConfigurationStatus_Rejected;
  13037. }
  13038. else
  13039. {
  13040. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13041. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  13042. isSuccess = ConfigurationStatus_Accepted;
  13043. }
  13044. }
  13045. else
  13046. {
  13047. isSuccess = ConfigurationStatus_Rejected;
  13048. }
  13049. }
  13050. if(strcmp(key, "HeartbeatInterval") == 0)
  13051. {
  13052. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13053. {
  13054. check_ascii = value[0];
  13055. if( (check_ascii < 48) || (check_ascii > 57) )
  13056. {
  13057. isSuccess = ConfigurationStatus_Rejected;
  13058. }
  13059. else
  13060. {
  13061. if((atoi(value) == 0) || (atoi(value) >= 10))
  13062. {
  13063. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13064. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  13065. HeartBeatWaitTime = atoi(value);
  13066. isSuccess = ConfigurationStatus_Accepted;
  13067. }
  13068. else
  13069. {
  13070. isSuccess = ConfigurationStatus_Rejected;
  13071. }
  13072. }
  13073. }
  13074. else
  13075. {
  13076. isSuccess = ConfigurationStatus_Rejected;
  13077. }
  13078. }
  13079. if(strcmp(key, "LightIntensity") == 0)
  13080. {
  13081. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13082. {
  13083. check_ascii = value[0];
  13084. if( (check_ascii < 48) || (check_ascii > 57) )
  13085. {
  13086. isSuccess = ConfigurationStatus_Rejected;
  13087. }
  13088. else
  13089. {
  13090. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  13091. isSuccess = ConfigurationStatus_Accepted;
  13092. }
  13093. }
  13094. else
  13095. {
  13096. isSuccess = ConfigurationStatus_Rejected;
  13097. }
  13098. }
  13099. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  13100. {
  13101. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13102. {
  13103. strcpy(str, (const char*)value);
  13104. for(int i = 0; str[i]; i++)
  13105. {
  13106. str[i] = tolower(str[i]);
  13107. }
  13108. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13109. isSuccess = ConfigurationStatus_Accepted;
  13110. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13111. }
  13112. else
  13113. {
  13114. isSuccess = ConfigurationStatus_Rejected;
  13115. }
  13116. }
  13117. if(strcmp(key, "LocalPreAuthorize") == 0)
  13118. {
  13119. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13120. {
  13121. strcpy(str, (const char*)value);
  13122. for(int i = 0; str[i]; i++)
  13123. {
  13124. str[i] = tolower(str[i]);
  13125. }
  13126. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13127. isSuccess = ConfigurationStatus_Accepted;
  13128. }
  13129. else
  13130. {
  13131. isSuccess = ConfigurationStatus_Rejected;
  13132. }
  13133. }
  13134. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  13135. {
  13136. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13137. {
  13138. check_ascii = value[0];
  13139. if( (check_ascii < 48) || (check_ascii > 57) )
  13140. {
  13141. isSuccess = ConfigurationStatus_Rejected;
  13142. }
  13143. else
  13144. {
  13145. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  13146. isSuccess = ConfigurationStatus_Accepted;
  13147. }
  13148. }
  13149. else
  13150. {
  13151. isSuccess = ConfigurationStatus_Rejected;
  13152. }
  13153. }
  13154. if(strcmp(key, "MeterValuesAlignedData") == 0)
  13155. {
  13156. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13157. {
  13158. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  13159. isSuccess = ConfigurationStatus_Accepted;
  13160. }
  13161. else
  13162. {
  13163. isSuccess = ConfigurationStatus_Rejected;
  13164. }
  13165. }
  13166. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  13167. {
  13168. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13169. {
  13170. check_ascii = value[0];
  13171. if( (check_ascii < 48) || (check_ascii > 57) )
  13172. {
  13173. isSuccess = ConfigurationStatus_Rejected;
  13174. }
  13175. else
  13176. {
  13177. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13178. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  13179. isSuccess = ConfigurationStatus_Accepted;
  13180. }
  13181. }
  13182. else
  13183. {
  13184. isSuccess = ConfigurationStatus_Rejected;
  13185. }
  13186. }
  13187. if(strcmp(key, "MeterValuesSampledData") == 0 )
  13188. {
  13189. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13190. {
  13191. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  13192. isSuccess = ConfigurationStatus_Accepted;
  13193. }
  13194. else
  13195. {
  13196. isSuccess = ConfigurationStatus_Rejected;
  13197. }
  13198. }
  13199. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  13200. {
  13201. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13202. {
  13203. check_ascii = value[0];
  13204. if( (check_ascii < 48) || (check_ascii > 57) )
  13205. {
  13206. isSuccess = ConfigurationStatus_Rejected;
  13207. }
  13208. else
  13209. {
  13210. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13211. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  13212. isSuccess = ConfigurationStatus_Accepted;
  13213. }
  13214. }
  13215. else
  13216. {
  13217. isSuccess = ConfigurationStatus_Rejected;
  13218. }
  13219. }
  13220. if(strcmp(key, "MeterValueSampleInterval") == 0)
  13221. {
  13222. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13223. {
  13224. check_ascii = value[0];
  13225. if( (check_ascii < 48) || (check_ascii > 57) )
  13226. {
  13227. isSuccess = ConfigurationStatus_Rejected;
  13228. }
  13229. else
  13230. {
  13231. if((atoi(value) == 0) || (atoi(value) >= 10))
  13232. {
  13233. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13234. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  13235. isSuccess = ConfigurationStatus_Accepted;
  13236. }
  13237. else
  13238. {
  13239. isSuccess = ConfigurationStatus_Rejected;
  13240. }
  13241. }
  13242. }
  13243. else
  13244. {
  13245. isSuccess = ConfigurationStatus_Rejected;
  13246. }
  13247. }
  13248. if(strcmp(key, "MinimumStatusDuration") == 0)
  13249. {
  13250. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13251. {
  13252. check_ascii = value[0];
  13253. if( (check_ascii < 48) || (check_ascii > 57) )
  13254. {
  13255. isSuccess = ConfigurationStatus_Rejected;
  13256. }
  13257. else
  13258. {
  13259. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  13260. {
  13261. isSuccess = ConfigurationStatus_Rejected;
  13262. }
  13263. else
  13264. {
  13265. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  13266. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  13267. server_cycle_Status = atoi(value); //StatusNotification Cycle
  13268. isSuccess = ConfigurationStatus_Accepted;
  13269. }
  13270. }
  13271. }
  13272. else
  13273. {
  13274. isSuccess = ConfigurationStatus_Rejected;
  13275. }
  13276. }
  13277. if(strcmp(key, "NumberOfConnectors") == 0)
  13278. {
  13279. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13280. {
  13281. check_ascii = value[0];
  13282. if( (check_ascii < 48) || (check_ascii > 57) )
  13283. {
  13284. isSuccess = ConfigurationStatus_Rejected;
  13285. }
  13286. else
  13287. {
  13288. //Charger.ResetRetries = Integer.parseInt(value);
  13289. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  13290. isSuccess = ConfigurationStatus_Accepted;
  13291. }
  13292. }
  13293. else
  13294. {
  13295. isSuccess = ConfigurationStatus_Rejected;
  13296. }
  13297. }
  13298. if(strcmp(key, "ResetRetries") == 0)
  13299. {
  13300. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13301. {
  13302. check_ascii = value[0];
  13303. if( (check_ascii < 48) || (check_ascii > 57) )
  13304. {
  13305. isSuccess = ConfigurationStatus_Rejected;
  13306. }
  13307. else
  13308. {
  13309. //Charger.ResetRetries = Integer.parseInt(value);
  13310. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  13311. isSuccess = ConfigurationStatus_Accepted;
  13312. }
  13313. }
  13314. else
  13315. {
  13316. isSuccess = ConfigurationStatus_Rejected;
  13317. }
  13318. }
  13319. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  13320. {
  13321. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13322. {
  13323. strcpy(str, (const char*)value);
  13324. for(int i = 0; str[i]; i++)
  13325. {
  13326. str[i] = tolower(str[i]);
  13327. }
  13328. if(strcmp(str, "notapplicable")== 0)
  13329. {
  13330. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  13331. isSuccess = ConfigurationStatus_Accepted;
  13332. }
  13333. else if(strcmp(str, "unknown")== 0)
  13334. {
  13335. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  13336. isSuccess = ConfigurationStatus_Accepted;
  13337. }
  13338. else if(strcmp(str, "rst")== 0)
  13339. {
  13340. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  13341. isSuccess = ConfigurationStatus_Accepted;
  13342. }
  13343. else if(strcmp(str, "rts")== 0)
  13344. {
  13345. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  13346. isSuccess = ConfigurationStatus_Accepted;
  13347. }
  13348. else if(strcmp(str, "srt")== 0)
  13349. {
  13350. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  13351. isSuccess = ConfigurationStatus_Accepted;
  13352. }
  13353. else if(strcmp(str, "str")== 0)
  13354. {
  13355. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  13356. isSuccess = ConfigurationStatus_Accepted;
  13357. }
  13358. else if(strcmp(str, "trs")== 0)
  13359. {
  13360. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  13361. isSuccess = ConfigurationStatus_Accepted;
  13362. }
  13363. else if(strcmp(str, "tsr")== 0)
  13364. {
  13365. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  13366. isSuccess = ConfigurationStatus_Accepted;
  13367. }
  13368. else
  13369. {
  13370. isSuccess = ConfigurationStatus_Rejected;
  13371. }
  13372. }
  13373. else
  13374. {
  13375. isSuccess = ConfigurationStatus_Rejected;
  13376. }
  13377. }
  13378. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  13379. {
  13380. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13381. {
  13382. check_ascii = value[0];
  13383. if( (check_ascii < 48) || (check_ascii > 57) )
  13384. {
  13385. isSuccess = ConfigurationStatus_Rejected;
  13386. }
  13387. else
  13388. {
  13389. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  13390. isSuccess = ConfigurationStatus_Accepted;
  13391. }
  13392. }
  13393. else
  13394. {
  13395. isSuccess = ConfigurationStatus_Rejected;
  13396. }
  13397. }
  13398. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  13399. {
  13400. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13401. {
  13402. strcpy(str, (const char*)value);
  13403. for(int i = 0; str[i]; i++)
  13404. {
  13405. str[i] = tolower(str[i]);
  13406. }
  13407. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  13408. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13409. isSuccess = ConfigurationStatus_Accepted;
  13410. }
  13411. else
  13412. {
  13413. isSuccess = ConfigurationStatus_Rejected;
  13414. }
  13415. }
  13416. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  13417. {
  13418. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13419. {
  13420. strcpy(str, (const char*)value);
  13421. for(int i = 0; str[i]; i++)
  13422. {
  13423. str[i] = tolower(str[i]);
  13424. }
  13425. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  13426. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13427. isSuccess = ConfigurationStatus_Accepted;
  13428. }
  13429. else
  13430. {
  13431. isSuccess = ConfigurationStatus_Rejected;
  13432. }
  13433. }
  13434. if(strcmp(key, "StopTxnAlignedData") == 0)
  13435. {
  13436. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13437. {
  13438. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  13439. isSuccess = ConfigurationStatus_Accepted;
  13440. }
  13441. else
  13442. {
  13443. isSuccess = ConfigurationStatus_Rejected;
  13444. }
  13445. }
  13446. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  13447. {
  13448. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13449. {
  13450. check_ascii = value[0];
  13451. if( (check_ascii < 48) || (check_ascii > 57) )
  13452. {
  13453. isSuccess = ConfigurationStatus_Rejected;
  13454. }
  13455. else
  13456. {
  13457. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  13458. isSuccess = ConfigurationStatus_Accepted;
  13459. }
  13460. }
  13461. else
  13462. {
  13463. isSuccess = ConfigurationStatus_Rejected;
  13464. }
  13465. }
  13466. if(strcmp(key, "StopTxnSampledData") == 0)
  13467. {
  13468. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13469. {
  13470. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  13471. isSuccess = ConfigurationStatus_Accepted;
  13472. }
  13473. else
  13474. {
  13475. isSuccess = ConfigurationStatus_Rejected;
  13476. }
  13477. }
  13478. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  13479. {
  13480. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13481. {
  13482. check_ascii = value[0];
  13483. if( (check_ascii < 48) || (check_ascii > 57) )
  13484. {
  13485. isSuccess = ConfigurationStatus_Rejected;
  13486. }
  13487. else
  13488. {
  13489. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  13490. isSuccess = ConfigurationStatus_Accepted;
  13491. }
  13492. }
  13493. else
  13494. {
  13495. isSuccess = ConfigurationStatus_Rejected;
  13496. }
  13497. }
  13498. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  13499. {
  13500. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13501. {
  13502. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  13503. isSuccess = ConfigurationStatus_Accepted;
  13504. }
  13505. else
  13506. {
  13507. isSuccess = ConfigurationStatus_Rejected;
  13508. }
  13509. }
  13510. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  13511. {
  13512. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13513. {
  13514. check_ascii = value[0];
  13515. if( (check_ascii < 48) || (check_ascii > 57) )
  13516. {
  13517. isSuccess = ConfigurationStatus_Rejected;
  13518. }
  13519. else
  13520. {
  13521. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  13522. isSuccess = ConfigurationStatus_Accepted;
  13523. }
  13524. }
  13525. else
  13526. {
  13527. isSuccess = ConfigurationStatus_Rejected;
  13528. }
  13529. }
  13530. if(strcmp(key, "TransactionMessageAttempts") == 0)
  13531. {
  13532. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13533. {
  13534. check_ascii = value[0];
  13535. if( (check_ascii < 48) || (check_ascii > 57) )
  13536. {
  13537. isSuccess = ConfigurationStatus_Rejected;
  13538. }
  13539. else
  13540. {
  13541. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  13542. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  13543. TransactionMessageAttemptsValue = atoi(value);
  13544. isSuccess = ConfigurationStatus_Accepted;
  13545. }
  13546. }
  13547. else
  13548. {
  13549. isSuccess = ConfigurationStatus_Rejected;
  13550. }
  13551. }
  13552. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  13553. {
  13554. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13555. {
  13556. check_ascii = value[0];
  13557. if( (check_ascii < 48) || (check_ascii > 57) )
  13558. {
  13559. isSuccess = ConfigurationStatus_Rejected;
  13560. }
  13561. else
  13562. {
  13563. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  13564. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  13565. TransactionMessageRetryIntervalValue = atoi(value);
  13566. isSuccess = ConfigurationStatus_Accepted;
  13567. }
  13568. }
  13569. else
  13570. {
  13571. isSuccess = ConfigurationStatus_Rejected;
  13572. }
  13573. }
  13574. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  13575. {
  13576. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13577. {
  13578. strcpy(str, (const char*)value);
  13579. for(int i = 0; str[i]; i++)
  13580. {
  13581. str[i] = tolower(str[i]);
  13582. }
  13583. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  13584. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13585. isSuccess = ConfigurationStatus_Accepted;
  13586. }
  13587. else
  13588. {
  13589. isSuccess = ConfigurationStatus_Rejected;
  13590. }
  13591. }
  13592. if(strcmp(key, "WebSocketPingInterval") == 0)
  13593. {
  13594. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13595. {
  13596. check_ascii = value[0];
  13597. if( (check_ascii < 48) || (check_ascii > 57) )
  13598. {
  13599. isSuccess = ConfigurationStatus_Rejected;
  13600. }
  13601. else
  13602. {
  13603. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  13604. isSuccess = ConfigurationStatus_Accepted;
  13605. }
  13606. }
  13607. else
  13608. {
  13609. isSuccess = ConfigurationStatus_Rejected;
  13610. }
  13611. }
  13612. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  13613. {
  13614. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  13615. {
  13616. strcpy(str, (const char*)value);
  13617. for(int i = 0; str[i]; i++)
  13618. {
  13619. str[i] = tolower(str[i]);
  13620. }
  13621. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13622. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13623. isSuccess = ConfigurationStatus_Accepted;
  13624. }
  13625. else
  13626. {
  13627. isSuccess = ConfigurationStatus_Rejected;
  13628. }
  13629. }
  13630. if(strcmp(key, "AuthorizationKey") == 0)
  13631. {
  13632. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  13633. {
  13634. strcpy(str, (const char*)value);
  13635. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  13636. isSuccess = ConfigurationStatus_Accepted;
  13637. }
  13638. else
  13639. {
  13640. isSuccess = ConfigurationStatus_Rejected;
  13641. }
  13642. }
  13643. if(strcmp(key, "SecurityProfile") == 0)
  13644. {
  13645. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  13646. {
  13647. check_ascii = value[0];
  13648. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  13649. {
  13650. isSuccess = ConfigurationStatus_Rejected;
  13651. }
  13652. else if(check_ascii == 0x33)
  13653. {
  13654. isSuccess = NotSupported;
  13655. }
  13656. else
  13657. {
  13658. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  13659. {
  13660. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  13661. isSuccess = ConfigurationStatus_Accepted;
  13662. }
  13663. else
  13664. isSuccess = ConfigurationStatus_Rejected;
  13665. }
  13666. }
  13667. else
  13668. {
  13669. isSuccess = ConfigurationStatus_Rejected;
  13670. }
  13671. }
  13672. if(strcmp(key, "DefaultPrice") == 0)
  13673. {
  13674. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  13675. {
  13676. strcpy(str, (const char*)value);
  13677. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  13678. isSuccess = ConfigurationStatus_Accepted;
  13679. }
  13680. else
  13681. {
  13682. isSuccess = ConfigurationStatus_Rejected;
  13683. }
  13684. }
  13685. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  13686. {
  13687. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  13688. {
  13689. strcpy(str, (const char*)value);
  13690. for(int i = 0; str[i]; i++)
  13691. {
  13692. str[i] = tolower(str[i]);
  13693. }
  13694. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13695. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13696. isSuccess = ConfigurationStatus_Accepted;
  13697. }
  13698. else
  13699. {
  13700. isSuccess = ConfigurationStatus_Rejected;
  13701. }
  13702. }
  13703. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  13704. {
  13705. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  13706. {
  13707. strcpy(str, (const char*)value);
  13708. for(int i = 0; str[i]; i++)
  13709. {
  13710. str[i] = tolower(str[i]);
  13711. }
  13712. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13713. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13714. isSuccess = ConfigurationStatus_Accepted;
  13715. }
  13716. else
  13717. {
  13718. isSuccess = ConfigurationStatus_Rejected;
  13719. }
  13720. }
  13721. #if 0
  13722. //For OCPP Test Case
  13723. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  13724. {
  13725. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13726. {
  13727. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  13728. isSuccess = ConfigurationStatus_Accepted;
  13729. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13730. }
  13731. else
  13732. {
  13733. isSuccess = ConfigurationStatus_Rejected;
  13734. }
  13735. }
  13736. #endif
  13737. #if 1
  13738. if(strcmp(key, "LocalAuthListEnabled") == 0)
  13739. {
  13740. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13741. {
  13742. strcpy(str, (const char*)value);
  13743. for(int i = 0; str[i]; i++)
  13744. {
  13745. str[i] = tolower(str[i]);
  13746. }
  13747. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13748. isSuccess = ConfigurationStatus_Accepted;
  13749. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13750. }
  13751. else
  13752. {
  13753. isSuccess = ConfigurationStatus_Rejected;
  13754. }
  13755. }
  13756. #endif
  13757. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  13758. {
  13759. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  13760. {
  13761. check_ascii = value[0];
  13762. if( (check_ascii < 48) || (check_ascii > 57) )
  13763. {
  13764. isSuccess = ConfigurationStatus_Rejected;
  13765. }
  13766. else
  13767. {
  13768. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  13769. isSuccess = ConfigurationStatus_Accepted;
  13770. }
  13771. }
  13772. else
  13773. {
  13774. isSuccess = ConfigurationStatus_Rejected;
  13775. }
  13776. }
  13777. if(strcmp(key, "SendLocalListMaxLength") == 0)
  13778. {
  13779. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  13780. {
  13781. check_ascii = value[0];
  13782. if( (check_ascii < 48) || (check_ascii > 57) )
  13783. {
  13784. isSuccess = ConfigurationStatus_Rejected;
  13785. }
  13786. else
  13787. {
  13788. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  13789. isSuccess = ConfigurationStatus_Accepted;
  13790. }
  13791. }
  13792. else
  13793. {
  13794. isSuccess = ConfigurationStatus_Rejected;
  13795. }
  13796. }
  13797. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  13798. {
  13799. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  13800. {
  13801. strcpy(str, (const char*)value);
  13802. for(int i = 0; str[i]; i++)
  13803. {
  13804. str[i] = tolower(str[i]);
  13805. }
  13806. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13807. isSuccess = ConfigurationStatus_Accepted;
  13808. }
  13809. else
  13810. {
  13811. isSuccess = ConfigurationStatus_Rejected;
  13812. }
  13813. }
  13814. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  13815. {
  13816. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  13817. {
  13818. check_ascii = value[0];
  13819. if( (check_ascii < 48) || (check_ascii > 57) )
  13820. {
  13821. isSuccess = ConfigurationStatus_Rejected;
  13822. }
  13823. else
  13824. {
  13825. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  13826. isSuccess = ConfigurationStatus_Accepted;
  13827. }
  13828. }
  13829. else
  13830. {
  13831. isSuccess = ConfigurationStatus_Rejected;
  13832. }
  13833. }
  13834. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  13835. {
  13836. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  13837. {
  13838. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  13839. isSuccess = ConfigurationStatus_Accepted;
  13840. }
  13841. else
  13842. {
  13843. isSuccess = ConfigurationStatus_Rejected;
  13844. }
  13845. }
  13846. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  13847. {
  13848. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  13849. {
  13850. check_ascii = value[0];
  13851. if( (check_ascii < 48) || (check_ascii > 57) )
  13852. {
  13853. isSuccess = ConfigurationStatus_Rejected;
  13854. }
  13855. else
  13856. {
  13857. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  13858. isSuccess = ConfigurationStatus_Accepted;
  13859. }
  13860. }
  13861. else
  13862. {
  13863. isSuccess = ConfigurationStatus_Rejected;
  13864. }
  13865. }
  13866. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  13867. {
  13868. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  13869. {
  13870. strcpy(str, (const char*)value);
  13871. for(int i = 0; str[i]; i++)
  13872. {
  13873. str[i] = tolower(str[i]);
  13874. }
  13875. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13876. isSuccess = ConfigurationStatus_Accepted;
  13877. }
  13878. else
  13879. {
  13880. isSuccess = ConfigurationStatus_Rejected;
  13881. }
  13882. }
  13883. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  13884. {
  13885. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  13886. {
  13887. check_ascii = value[0];
  13888. if( (check_ascii < 48) || (check_ascii > 57) )
  13889. {
  13890. isSuccess = ConfigurationStatus_Rejected;
  13891. }
  13892. else
  13893. {
  13894. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  13895. isSuccess = ConfigurationStatus_Accepted;
  13896. }
  13897. }
  13898. else
  13899. {
  13900. isSuccess = ConfigurationStatus_Rejected;
  13901. }
  13902. }
  13903. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13904. return isSuccess;
  13905. }
  13906. int TransactionMessageAttemptsGet(void)
  13907. {
  13908. return TransactionMessageAttemptsValue;
  13909. }
  13910. int FirstHeartBeatResponse(void)
  13911. {
  13912. return FirstHeartBeat;
  13913. }
  13914. int TransactionMessageRetryIntervalGet(void)
  13915. {
  13916. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13917. }
  13918. int ReadHttpStatus(int sock)
  13919. {
  13920. //char c;
  13921. char buff[1024]="",*ptr=buff+1;
  13922. int bytes_received, status;
  13923. DEBUG_INFO("Begin Response ..\n");
  13924. while((bytes_received = recv(sock, ptr, 1, 0))){
  13925. if(bytes_received==-1){
  13926. perror("ReadHttpStatus");
  13927. exit(1);
  13928. }
  13929. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  13930. ptr++;
  13931. }
  13932. *ptr=0;
  13933. ptr=buff+1;
  13934. sscanf(ptr,"%*s %d ", &status);
  13935. DEBUG_INFO("%s\n",ptr);
  13936. DEBUG_INFO("status=%d\n",status);
  13937. DEBUG_INFO("End Response ..\n");
  13938. return (bytes_received>0)?status:0;
  13939. }
  13940. //the only filed that it parsed is 'Content-Length'
  13941. int ParseHeader(int sock)
  13942. {
  13943. //char c;
  13944. char buff[1024]="",*ptr=buff+4;
  13945. int bytes_received;
  13946. DEBUG_INFO("Begin HEADER ..\n");
  13947. while((bytes_received = recv(sock, ptr, 1, 0))){
  13948. if(bytes_received==-1){
  13949. perror("Parse Header");
  13950. exit(1);
  13951. }
  13952. if(
  13953. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  13954. (ptr[-1]=='\r') && (*ptr=='\n' )
  13955. ) break;
  13956. ptr++;
  13957. }
  13958. *ptr=0;
  13959. ptr=buff+4;
  13960. //printf("%s",ptr);
  13961. if(bytes_received){
  13962. ptr=strstr(ptr,"Content-Length:");
  13963. if(ptr){
  13964. sscanf(ptr,"%*s %d",&bytes_received);
  13965. }else
  13966. bytes_received=-1; //unknown size
  13967. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  13968. }
  13969. DEBUG_INFO("End HEADER ..\n");
  13970. return bytes_received ;
  13971. }
  13972. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  13973. {
  13974. int result = TRUE;
  13975. char rmFileCmd[100]={0};
  13976. char FilePath[100]={0};
  13977. char ftpbuf[200];
  13978. int systemresult;
  13979. //DEBUG_INFO("filename=%s\n",filename);
  13980. //DEBUG_INFO("url=%s\n",url);
  13981. sprintf(FilePath,"/mnt/%s",filename);
  13982. system("ping 8.8.8.8 &");
  13983. if((access(FilePath,F_OK))!=-1)
  13984. {
  13985. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13986. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13987. system(rmFileCmd);
  13988. }
  13989. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13990. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  13991. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13992. systemresult = system(ftpbuf);
  13993. //DEBUG_INFO("systemresult=%d\n",systemresult);
  13994. if(systemresult != 0)
  13995. {
  13996. DEBUG_INFO("http DownLoad error!\n");
  13997. result = FALSE;
  13998. }
  13999. system("pkill ping");
  14000. return result;
  14001. }
  14002. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  14003. {
  14004. int result = TRUE;
  14005. char rmFileCmd[100]={0};
  14006. char FilePath[100]={0};
  14007. char ftpbuf[200];
  14008. int systemresult;
  14009. //char temp[100];
  14010. sprintf(FilePath,"/mnt/%s",filename);
  14011. system("ping 8.8.8.8 &");
  14012. if((access(FilePath,F_OK))!=-1)
  14013. {
  14014. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14015. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14016. system(rmFileCmd);
  14017. }
  14018. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14019. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14020. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  14021. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14022. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14023. systemresult = system(ftpbuf);
  14024. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14025. if(systemresult != 0)
  14026. {
  14027. printf("wget error!\n");
  14028. result = FALSE;
  14029. }
  14030. system("pkill ping");
  14031. return result;
  14032. }
  14033. int httpUploadFile(char *location, char *path, char *filename,char *url)
  14034. {
  14035. char rmFileCmd[100]={0};
  14036. char FilePath[100]={0};
  14037. char buf[512];
  14038. int systemresult = 0;
  14039. //DEBUG_INFO("filename=%s\n",filename);
  14040. //DEBUG_INFO("url=%s\n",url);
  14041. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  14042. if((access(FilePath,F_OK))!=-1)
  14043. {
  14044. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14045. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14046. system(rmFileCmd);
  14047. }
  14048. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  14049. if(fp == NULL)
  14050. {
  14051. DEBUG_INFO("log is NULL\n");
  14052. return FALSE;
  14053. }
  14054. else
  14055. {
  14056. fprintf(fp, "%s\n", url);
  14057. fprintf(fp, "%s\n", filename);
  14058. fclose(fp);
  14059. }
  14060. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  14061. if(phpFP == NULL)
  14062. {
  14063. DEBUG_INFO("PHP upload fail.\n");
  14064. return FALSE;
  14065. }
  14066. else
  14067. {
  14068. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  14069. {
  14070. if(strstr(buf, "result") != NULL)
  14071. {
  14072. sscanf(buf, "result: %d", &systemresult);
  14073. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  14074. }
  14075. }
  14076. pclose(phpFP);
  14077. }
  14078. if(systemresult != 1)
  14079. {
  14080. DEBUG_INFO("HTTP upload error!\n");
  14081. return FALSE;
  14082. }
  14083. return TRUE;
  14084. }
  14085. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  14086. {
  14087. struct hostent* server;
  14088. char *IPbuffer;
  14089. char ftpbuf[200];
  14090. int systemresult;
  14091. // To retrieve host information
  14092. server = gethostbyname(location);
  14093. // To convert an Internet network
  14094. // address into ASCII string
  14095. IPbuffer = inet_ntoa(*((struct in_addr*)
  14096. server->h_addr_list[0]));
  14097. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14098. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  14099. /* format : ftpput -u username -p passwd IP target source*/
  14100. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  14101. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14102. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14103. systemresult = system(ftpbuf);
  14104. DEBUG_INFO("systemresult=%d\n",systemresult);
  14105. if(systemresult != 0)
  14106. {
  14107. DEBUG_INFO("ftpput error!\n");
  14108. return FALSE;
  14109. }
  14110. return TRUE;
  14111. }
  14112. int GetOcppServerURL()
  14113. {
  14114. int result = FALSE;
  14115. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  14116. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  14117. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  14118. struct yuarel url;
  14119. char urlStr[512];
  14120. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  14121. {
  14122. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  14123. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14124. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  14125. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  14126. if(yuarel_parse(&url, urlStr) != -1)
  14127. {
  14128. sprintf(OcppProtocol, "%s", url.scheme);
  14129. sprintf(OcppHost, "%s", url.host);
  14130. if(url.path == NULL)
  14131. OcppTempPath[0] = '\0';
  14132. else
  14133. {
  14134. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  14135. {
  14136. sprintf(OcppTempPath, "%s/", url.path);
  14137. }
  14138. else
  14139. {
  14140. sprintf(OcppTempPath, "%s", url.path);
  14141. }
  14142. }
  14143. if(url.port == 0)
  14144. {
  14145. if(strcmp(OcppProtocol, "wss") == 0)
  14146. OcppPort = 443;
  14147. else
  14148. OcppPort = 80;
  14149. }
  14150. else
  14151. OcppPort = url.port;
  14152. result = TRUE;
  14153. }
  14154. }
  14155. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  14156. {
  14157. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  14158. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14159. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  14160. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  14161. if(yuarel_parse(&url, urlStr) != -1)
  14162. {
  14163. sprintf(OcppProtocol, "%s", url.scheme);
  14164. sprintf(OcppHost, "%s", url.host);
  14165. if(url.path == NULL)
  14166. OcppTempPath[0] = '\0';
  14167. else
  14168. sprintf(OcppTempPath, "%s", url.path);
  14169. if(url.port == 0)
  14170. {
  14171. if(strcmp(OcppProtocol, "wss") == 0)
  14172. OcppPort = 443;
  14173. else
  14174. OcppPort = 80;
  14175. }
  14176. else
  14177. OcppPort = url.port;
  14178. result = TRUE;
  14179. }
  14180. }
  14181. else
  14182. {
  14183. strcpy(OcppHost,"");
  14184. }
  14185. return result;
  14186. }
  14187. int GetOcppPath()
  14188. {
  14189. int result = FALSE;
  14190. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  14191. {
  14192. if(OcppTempPath == NULL)
  14193. {
  14194. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  14195. }
  14196. else
  14197. {
  14198. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  14199. }
  14200. result = TRUE;
  14201. goto End;
  14202. }
  14203. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  14204. {
  14205. if(OcppTempPath == NULL)
  14206. {
  14207. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  14208. }
  14209. else
  14210. {
  14211. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  14212. }
  14213. result = TRUE;
  14214. goto End;
  14215. }
  14216. else
  14217. {
  14218. strcpy(OcppPath,"");
  14219. }
  14220. End:
  14221. return result;
  14222. }
  14223. int GetOcppPort()
  14224. {
  14225. return OcppPort;
  14226. }
  14227. int GetOcppConnStatus(void)
  14228. {
  14229. return ShmOCPP16Data->OcppConnStatus;
  14230. }
  14231. void SetOcppConnStatus(uint8_t status)
  14232. {
  14233. ShmOCPP16Data->OcppConnStatus = status;
  14234. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  14235. }
  14236. int GetHeartBeatWithNOResponse(void)
  14237. {
  14238. return HeartBeatWithNOResponse;
  14239. }
  14240. void SetHeartBeatWithNOResponse(void)
  14241. {
  14242. HeartBeatWithNOResponse = 0;
  14243. }
  14244. void GetStartTransactionIdTag(int gun_index)
  14245. {
  14246. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  14247. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  14248. }
  14249. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  14250. {
  14251. char ch;
  14252. FILE *fptr1;
  14253. int temptransactionId;
  14254. char str[100]={0};
  14255. temptransactionId = 0;
  14256. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  14257. {
  14258. DEBUG_INFO("IdTag is empty.\n");
  14259. return temptransactionId;
  14260. }
  14261. /*------ Read the file ----------------*/
  14262. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  14263. if (!fptr1)
  14264. {
  14265. DEBUG_INFO("QueueTransactionId file open error.\n");
  14266. //printf(" File not found or unable to open the input file!!\n");
  14267. return temptransactionId;
  14268. }
  14269. ch=fgetc(fptr1);
  14270. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  14271. rewind(fptr1);
  14272. if(ch!=EOF)
  14273. {
  14274. // printf("%c",ch);
  14275. while (fgets(str, 100, fptr1) != NULL)
  14276. {
  14277. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14278. if(str[0]=='\0')
  14279. {
  14280. break;
  14281. }
  14282. char *revbuf[8] = {0}; // Variable store string split
  14283. int num = 0;// Quantity after string split
  14284. DEBUG_INFO("Transaction queue data= %s\n", str);
  14285. splitstring(str,",",revbuf,&num); // String split
  14286. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  14287. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  14288. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  14289. DEBUG_INFO("------------------------------\n");
  14290. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  14291. {
  14292. if(isStopTransaction)
  14293. {
  14294. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  14295. {
  14296. temptransactionId = atoi(revbuf[2]);
  14297. //break;
  14298. }
  14299. }
  14300. else
  14301. {
  14302. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  14303. {
  14304. temptransactionId = atoi(revbuf[2]);
  14305. //break;
  14306. }
  14307. }
  14308. }
  14309. }
  14310. }
  14311. else
  14312. DEBUG_INFO("EOF\n");
  14313. fclose(fptr1);
  14314. /*------- End of reading ---------------*/
  14315. return temptransactionId;
  14316. }
  14317. void SetTransactionIdZero(int transactionId)
  14318. {
  14319. char ch;
  14320. FILE *fptr1, *fptr2;
  14321. int temptransactionId = 0;
  14322. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  14323. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  14324. if (!fptr1)
  14325. {
  14326. //printf(" File not found or unable to open the input file!!\n");
  14327. return ;
  14328. }
  14329. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  14330. if (!fptr2)
  14331. {
  14332. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  14333. fclose(fptr1);
  14334. return ;
  14335. }
  14336. ch=fgetc(fptr1);
  14337. rewind(fptr1);
  14338. if(ch!=EOF)
  14339. {
  14340. // copy all contents to the temporary file except the specific line
  14341. while (fgets(str, 100, fptr1) != NULL)
  14342. {
  14343. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14344. if(str[0]=='\0')
  14345. {
  14346. break;
  14347. }
  14348. char *revbuf[8] = {0};
  14349. int num = 0;
  14350. strcpy(strtemp, str);
  14351. splitstring(str,",",revbuf,&num);
  14352. if(revbuf[2][0] != '\0')
  14353. {
  14354. temptransactionId = atoi(revbuf[2]);
  14355. if(transactionId != temptransactionId)
  14356. {
  14357. fprintf(fptr2, "%s\n", strtemp);
  14358. }
  14359. }
  14360. }
  14361. }
  14362. fclose(fptr1);
  14363. fclose(fptr2);
  14364. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  14365. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  14366. /*------ Read the file ----------------*/
  14367. }
  14368. int InternetDisconnect(void)
  14369. {
  14370. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  14371. }
  14372. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  14373. void storeTempStopTransaction(int gun_index)
  14374. {
  14375. char guid[37]={0};
  14376. int tempIndex = 0;
  14377. char TempStopTransaction[256];
  14378. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  14379. DEBUG_INFO("storeTempStopTransaction...\n");
  14380. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  14381. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  14382. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  14383. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14384. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14385. {
  14386. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14387. {
  14388. tempIndex = ((gun_index==2) ? 1: 0);
  14389. }
  14390. else
  14391. {
  14392. tempIndex = gun_index;
  14393. }
  14394. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14395. {
  14396. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14397. {
  14398. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  14399. }
  14400. }// END OF CHAdeMO_QUANTITY
  14401. }
  14402. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14403. {
  14404. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14405. {
  14406. tempIndex = ((gun_index==2) ? 1: 0);
  14407. }
  14408. else
  14409. {
  14410. tempIndex = gun_index;
  14411. }
  14412. for (int index = 0; index < CCS_QUANTITY; index++)
  14413. {
  14414. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14415. {
  14416. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  14417. }
  14418. }// END OF CCS_QUANTITY
  14419. }
  14420. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14421. {
  14422. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14423. {
  14424. tempIndex = ((gun_index==2) ? 1: 0);
  14425. }
  14426. else
  14427. {
  14428. tempIndex = gun_index;
  14429. }
  14430. for (int index = 0; index < GB_QUANTITY; index++)
  14431. {
  14432. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14433. {
  14434. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  14435. }
  14436. }// END OF GB_QUANTITY
  14437. }
  14438. else if(gunType[gun_index] == GUN_TYPE_DO)
  14439. {
  14440. tempIndex = gun_index;
  14441. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14442. {
  14443. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14444. {
  14445. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  14446. }
  14447. }
  14448. }
  14449. else
  14450. {
  14451. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14452. {
  14453. tempIndex = 2;
  14454. }
  14455. else
  14456. {
  14457. tempIndex = gun_index;
  14458. }
  14459. for (int index = 0; index < AC_QUANTITY; index++)
  14460. {
  14461. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14462. {
  14463. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  14464. }
  14465. }// END OF AC_QUANTITY
  14466. }
  14467. //Stop Transaction Time
  14468. struct timeval tmnow;
  14469. struct tm *tm;
  14470. char buf[28];//, usec_buf[6];
  14471. gettimeofday(&tmnow, NULL);
  14472. time_t t;
  14473. t = time(NULL);
  14474. /*UTC time and date*/
  14475. tm = gmtime(&t);
  14476. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  14477. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  14478. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  14479. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  14480. random_uuid(guid);
  14481. /***********************************transactionData******************************************************/
  14482. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  14483. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  14484. //=================================
  14485. //1. Transaction_Begin
  14486. //=================================
  14487. //============================== Energy.Active.Import.Interval ===========================================
  14488. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  14489. {
  14490. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  14491. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  14492. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  14493. 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*/]);
  14494. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14495. 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))
  14496. {
  14497. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  14498. }
  14499. else
  14500. {
  14501. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  14502. }
  14503. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  14504. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14505. }
  14506. //=================================
  14507. //2. Transaction_End
  14508. //=================================
  14509. //2.1====================================== Current.Import L1 ==============================================
  14510. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  14511. {
  14512. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  14513. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14514. {
  14515. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14516. {
  14517. tempIndex = ((gun_index==2) ? 1: 0);
  14518. }
  14519. else
  14520. {
  14521. tempIndex = gun_index;
  14522. }
  14523. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14524. {
  14525. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14526. {
  14527. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14528. }
  14529. }// End of for CHAdeMO_QUANTITY
  14530. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14531. }
  14532. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14533. {
  14534. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14535. {
  14536. tempIndex = ((gun_index==2) ? 1: 0);
  14537. }
  14538. else
  14539. {
  14540. tempIndex = gun_index;
  14541. }
  14542. for (int index = 0; index < CCS_QUANTITY; index++)
  14543. {
  14544. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14545. {
  14546. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14547. }
  14548. }// End of for CCS_QUANTITY
  14549. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14550. }
  14551. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14552. {
  14553. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14554. {
  14555. tempIndex = ((gun_index==2) ? 1: 0);
  14556. }
  14557. else
  14558. {
  14559. tempIndex = gun_index;
  14560. }
  14561. for (int index = 0; index < GB_QUANTITY; index++)
  14562. {
  14563. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14564. {
  14565. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14566. }
  14567. }// End of for GB_QUANTITY
  14568. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14569. }
  14570. else if(gunType[gun_index] == GUN_TYPE_DO)
  14571. {
  14572. tempIndex = gun_index;
  14573. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14574. {
  14575. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14576. {
  14577. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14578. }
  14579. }
  14580. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14581. }
  14582. else
  14583. {
  14584. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14585. {
  14586. tempIndex = 2;
  14587. }
  14588. else
  14589. {
  14590. tempIndex = gun_index;
  14591. }
  14592. for (int index = 0; index < AC_QUANTITY; index++)
  14593. {
  14594. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14595. {
  14596. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  14597. }
  14598. }// End of for AC_QUANTITY
  14599. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  14600. }
  14601. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14602. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  14603. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  14604. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  14605. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  14606. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14607. }
  14608. //2.2===================================== Energy.Active.Import.Interval ==========================================
  14609. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  14610. {
  14611. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14612. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14613. {
  14614. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14615. {
  14616. tempIndex = ((gun_index==2) ? 1: 0);
  14617. }
  14618. else
  14619. {
  14620. tempIndex = gun_index;
  14621. }
  14622. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14623. {
  14624. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14625. {
  14626. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14627. }
  14628. }// END OF CHAdeMO_QUANTITY
  14629. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14630. }
  14631. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14632. {
  14633. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14634. {
  14635. tempIndex = ((gun_index==2) ? 1: 0);
  14636. }
  14637. else
  14638. {
  14639. tempIndex = gun_index;
  14640. }
  14641. for (int index = 0; index < CCS_QUANTITY; index++)
  14642. {
  14643. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14644. {
  14645. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14646. }
  14647. }// END OF CCS_QUANTITY
  14648. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14649. }
  14650. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14651. {
  14652. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14653. {
  14654. tempIndex = ((gun_index==2) ? 1: 0);
  14655. }
  14656. else
  14657. {
  14658. tempIndex = gun_index;
  14659. }
  14660. for (int index = 0; index < GB_QUANTITY; index++)
  14661. {
  14662. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14663. {
  14664. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14665. }
  14666. }// END OF GB_QUANTITY
  14667. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14668. }
  14669. else if(gunType[gun_index] == GUN_TYPE_DO)
  14670. {
  14671. tempIndex = gun_index;
  14672. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14673. {
  14674. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14675. {
  14676. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14677. }
  14678. }
  14679. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14680. }
  14681. else
  14682. {
  14683. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14684. {
  14685. tempIndex = 2;
  14686. }
  14687. else
  14688. {
  14689. tempIndex = gun_index;
  14690. }
  14691. for (int index = 0; index < AC_QUANTITY; index++)
  14692. {
  14693. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14694. {
  14695. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14696. }
  14697. }// END OF AC_QUANTITY
  14698. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14699. }
  14700. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14701. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  14702. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  14703. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14704. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  14705. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14706. }
  14707. //2.3====================================== Power.Active.Import =========================================
  14708. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  14709. {
  14710. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14711. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14712. {
  14713. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14714. {
  14715. tempIndex = ((gun_index==2) ? 1: 0);
  14716. }
  14717. else
  14718. {
  14719. tempIndex = gun_index;
  14720. }
  14721. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14722. {
  14723. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14724. {
  14725. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14726. }
  14727. } // End for CHAdeMO_QUANTITY
  14728. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14729. }
  14730. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14731. {
  14732. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14733. {
  14734. tempIndex = ((gun_index==2) ? 1: 0);
  14735. }
  14736. else
  14737. {
  14738. tempIndex = gun_index;
  14739. }
  14740. for (int index = 0; index < CCS_QUANTITY; index++)
  14741. {
  14742. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14743. {
  14744. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14745. }
  14746. } // END for CCS_QUANTITY
  14747. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14748. }
  14749. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14750. {
  14751. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14752. {
  14753. tempIndex = ((gun_index==2) ? 1: 0);
  14754. }
  14755. else
  14756. {
  14757. tempIndex = gun_index;
  14758. }
  14759. for (int index = 0; index < GB_QUANTITY; index++)
  14760. {
  14761. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14762. {
  14763. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14764. }
  14765. }// END for GB_QUANTITY
  14766. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14767. }
  14768. else if(gunType[gun_index] == GUN_TYPE_DO)
  14769. {
  14770. tempIndex = gun_index;
  14771. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14772. {
  14773. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14774. {
  14775. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14776. }
  14777. }
  14778. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14779. }
  14780. else
  14781. {
  14782. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14783. {
  14784. tempIndex = 2;
  14785. }
  14786. else
  14787. {
  14788. tempIndex = gun_index;
  14789. }
  14790. for (int index = 0; index < AC_QUANTITY; index++)
  14791. {
  14792. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14793. {
  14794. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14795. }
  14796. } // END for AC_QUANTITY
  14797. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14798. }
  14799. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14800. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  14801. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  14802. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14803. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  14804. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  14805. }
  14806. //2.4====================================== Voltage L1 ====================================================
  14807. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  14808. {
  14809. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14810. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14811. {
  14812. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14813. {
  14814. tempIndex = ((gun_index==2) ? 1: 0);
  14815. }
  14816. else
  14817. {
  14818. tempIndex = gun_index;
  14819. }
  14820. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14821. {
  14822. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14823. {
  14824. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14825. }
  14826. } // END OF FOR CHAdeMO_QUANTITY
  14827. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14828. }
  14829. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14830. {
  14831. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14832. {
  14833. tempIndex = ((gun_index==2) ? 1: 0);
  14834. }
  14835. else
  14836. {
  14837. tempIndex = gun_index;
  14838. }
  14839. for (int index = 0; index < CCS_QUANTITY; index++)
  14840. {
  14841. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14842. {
  14843. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14844. }
  14845. } // END OF FOR CCS_QUANTITY
  14846. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14847. }
  14848. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14849. {
  14850. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14851. {
  14852. tempIndex = ((gun_index==2) ? 1: 0);
  14853. }
  14854. else
  14855. {
  14856. tempIndex = gun_index;
  14857. }
  14858. for (int index = 0; index < GB_QUANTITY; index++)
  14859. {
  14860. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14861. {
  14862. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14863. }
  14864. } // END OF FOR GB_QUANTITY
  14865. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14866. }
  14867. else if(gunType[gun_index] == GUN_TYPE_DO)
  14868. {
  14869. tempIndex = gun_index;
  14870. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14871. {
  14872. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14873. {
  14874. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14875. }
  14876. }
  14877. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14878. }
  14879. else
  14880. {
  14881. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14882. {
  14883. tempIndex = 2;
  14884. }
  14885. else
  14886. {
  14887. tempIndex = gun_index;
  14888. }
  14889. for (int index = 0; index < AC_QUANTITY; index++)
  14890. {
  14891. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14892. {
  14893. 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
  14894. }
  14895. } // END OF FOR AC_QUANTITY
  14896. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  14897. }
  14898. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14899. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  14900. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  14901. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  14902. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  14903. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14904. }
  14905. //2.5============================================== End SoC =========================================================
  14906. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  14907. {
  14908. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14909. 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))
  14910. {
  14911. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  14912. {
  14913. tempIndex = ((gun_index==2) ? 1: 0);
  14914. }
  14915. else
  14916. {
  14917. tempIndex = gun_index;
  14918. }
  14919. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14920. {
  14921. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14922. {
  14923. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14924. {
  14925. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  14926. }
  14927. }
  14928. }
  14929. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14930. {
  14931. for (int index = 0; index < CCS_QUANTITY; index++)
  14932. {
  14933. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14934. {
  14935. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  14936. }
  14937. }
  14938. }
  14939. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14940. {
  14941. for (int index = 0; index < GB_QUANTITY; index++)
  14942. {
  14943. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14944. {
  14945. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  14946. }
  14947. }
  14948. }
  14949. else if(gunType[gun_index] == GUN_TYPE_DO)
  14950. {
  14951. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14952. {
  14953. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14954. {
  14955. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  14956. }
  14957. }
  14958. }
  14959. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14960. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  14961. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  14962. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  14963. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  14964. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  14965. } // END FOR DC CASE
  14966. }
  14967. //2.6====================================== Current.Import L2 ==============================================
  14968. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  14969. {
  14970. // AC 3 phase L2 current
  14971. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14972. {
  14973. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14974. {
  14975. tempIndex = 2;
  14976. }
  14977. else
  14978. {
  14979. tempIndex = gun_index;
  14980. }
  14981. for (int index = 0; index < AC_QUANTITY; index++)
  14982. {
  14983. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14984. {
  14985. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  14986. }
  14987. }// End of for AC_QUANTITY
  14988. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  14989. }
  14990. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14991. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  14992. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  14993. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  14994. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14995. }
  14996. //2.7====================================== Current.Import L3 ==============================================
  14997. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  14998. {
  14999. // AC 3 phase L3 current
  15000. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15001. {
  15002. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15003. {
  15004. tempIndex = 2;
  15005. }
  15006. else
  15007. {
  15008. tempIndex = gun_index;
  15009. }
  15010. for (int index = 0; index < AC_QUANTITY; index++)
  15011. {
  15012. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15013. {
  15014. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  15015. }
  15016. }// End of for AC_QUANTITY
  15017. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  15018. }
  15019. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15020. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  15021. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  15022. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  15023. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15024. }
  15025. //2.9====================================== Voltage L2 ====================================================
  15026. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15027. {
  15028. // AC 3 phase L2 volatge
  15029. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15030. {
  15031. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15032. {
  15033. tempIndex = 2;
  15034. }
  15035. else
  15036. {
  15037. tempIndex = gun_index;
  15038. }
  15039. for (int index = 0; index < AC_QUANTITY; index++)
  15040. {
  15041. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15042. {
  15043. 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
  15044. }
  15045. } // END OF FOR AC_QUANTITY
  15046. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  15047. }
  15048. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15049. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  15050. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  15051. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  15052. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15053. }
  15054. //2.10====================================== Voltage L3 ====================================================
  15055. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15056. {
  15057. // AC 3 phase L3 volatge
  15058. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15059. {
  15060. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15061. {
  15062. tempIndex = 2;
  15063. }
  15064. else
  15065. {
  15066. tempIndex = gun_index;
  15067. }
  15068. for (int index = 0; index < AC_QUANTITY; index++)
  15069. {
  15070. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15071. {
  15072. 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
  15073. }
  15074. } // END OF FOR AC_QUANTITY
  15075. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  15076. }
  15077. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15078. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  15079. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  15080. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  15081. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15082. }
  15083. //====================== Start SoC ================================
  15084. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  15085. {
  15086. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15087. 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))
  15088. {
  15089. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15090. {
  15091. tempIndex = ((gun_index==2) ? 1: 0);
  15092. }
  15093. else
  15094. {
  15095. tempIndex = gun_index;
  15096. }
  15097. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15098. {
  15099. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15100. {
  15101. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15102. {
  15103. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  15104. }
  15105. }
  15106. }
  15107. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15108. {
  15109. for (int index = 0; index < CCS_QUANTITY; index++)
  15110. {
  15111. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15112. {
  15113. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  15114. }
  15115. }
  15116. }
  15117. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15118. {
  15119. for (int index = 0; index < GB_QUANTITY; index++)
  15120. {
  15121. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15122. {
  15123. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  15124. }
  15125. }
  15126. }
  15127. else if(gunType[gun_index] == GUN_TYPE_DO)
  15128. {
  15129. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15130. {
  15131. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15132. {
  15133. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  15134. }
  15135. }
  15136. }
  15137. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15138. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  15139. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15140. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  15141. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  15142. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15143. } // END FOR DC CASE
  15144. }
  15145. //======================================== Message create ==============================================
  15146. json_object *StopTransaction = json_object_new_object();
  15147. json_object *transactionDatas = json_object_new_array();
  15148. json_object *sampledValues = json_object_new_array();
  15149. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  15150. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  15151. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  15152. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  15153. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  15154. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  15155. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  15156. {
  15157. json_object *transactionData = json_object_new_object();
  15158. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  15159. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  15160. {
  15161. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  15162. {
  15163. json_object *sampledValue = json_object_new_object();
  15164. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  15165. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  15166. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  15167. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  15168. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  15169. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  15170. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  15171. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  15172. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  15173. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  15174. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  15175. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  15176. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  15177. json_object_array_add(sampledValues, sampledValue);
  15178. }
  15179. }
  15180. json_object_object_add(transactionData, "sampledValue", sampledValues);
  15181. json_object_array_add(transactionDatas, transactionData);
  15182. }
  15183. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  15184. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  15185. ,MESSAGE_TYPE_CALL
  15186. ,guid
  15187. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  15188. json_object_put(StopTransaction);
  15189. // Check File "TempStopTransaction" Exist
  15190. if((access(TempStopTransaction,F_OK))!=-1)
  15191. {
  15192. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  15193. fclose(fopen(TempStopTransaction, "w"));
  15194. }
  15195. else
  15196. {
  15197. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  15198. FILE *log = fopen(TempStopTransaction, "w+");
  15199. if(log == NULL)
  15200. {
  15201. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  15202. return ;
  15203. }
  15204. else
  15205. {
  15206. fclose(log);
  15207. }
  15208. }
  15209. //Add TempStopTransaction | Update TempStopTransaction
  15210. // open file for writing
  15211. FILE *outfile;
  15212. outfile = fopen (TempStopTransaction, "a");
  15213. //DEBUG_INFO("data = %s\n", queuedata);
  15214. fputs(queuedata, outfile);
  15215. fputs("\n", outfile);
  15216. fclose (outfile);
  15217. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15218. }
  15219. void checkTempStopTransaction(int gun_index)
  15220. {
  15221. FILE *fptr1;
  15222. char ch;
  15223. char str[QUEUE_MESSAGE_LENGTH]={0};
  15224. char guid[37]={0};
  15225. char tempdata[65]={0};
  15226. char connectorStr[2]={0};
  15227. char TempStopTransaction[256];
  15228. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  15229. fptr1 = fopen(TempStopTransaction, "r");
  15230. //TempStopTransaction格式: 槍號,StopTransaction封包
  15231. if (!fptr1)
  15232. {
  15233. //printf(" File not found or unable to open the input file!!\n");
  15234. return ;
  15235. }
  15236. ch=fgetc(fptr1);
  15237. //printf(" Now the content of the file %s is : \n",fname);
  15238. rewind(fptr1);
  15239. if(ch!=EOF)
  15240. {
  15241. // copy all contents to the temporary file except the specific line
  15242. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  15243. {
  15244. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15245. if(str[0]=='\0')
  15246. {
  15247. break;
  15248. }
  15249. //TempStopTransaction格式: 槍號,StopTransaction封包
  15250. strncpy(connectorStr, str, 1);
  15251. if(atoi(connectorStr) != (gun_index+1))
  15252. {
  15253. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  15254. fclose(fptr1);
  15255. return ;
  15256. }
  15257. //random_uuid(guid);
  15258. strncpy(guid, str+6, 36); //copy guid
  15259. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  15260. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  15261. {
  15262. //DEBUG_INFO("StopTransaction mapitem pass\n");
  15263. }
  15264. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  15265. OCPP_insert_transaction_msg(NO, str);
  15266. memset(str,0,ARRAY_SIZE(str));
  15267. }
  15268. }
  15269. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  15270. fclose(fptr1);
  15271. remove(TempStopTransaction); // remove the original file
  15272. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15273. }
  15274. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  15275. {
  15276. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  15277. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  15278. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  15279. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  15280. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  15281. }
  15282. int GetWebSocketPingInterval(void)
  15283. {
  15284. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15285. }
  15286. int GetServerSign(void)
  15287. {
  15288. return server_sign;
  15289. }
  15290. uint8_t GetOcppSecurityProfile()
  15291. {
  15292. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15293. }
  15294. void GetOcppChargerBoxId(uint8_t *data)
  15295. {
  15296. sprintf((char*)data, "%s", ShmOCPP16Data->ChargeBoxId);
  15297. }
  15298. void GetOcppSecurityPassword(uint8_t *data)
  15299. {
  15300. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15301. }
  15302. void SetOcppVersion(uint8_t *version)
  15303. {
  15304. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  15305. DEBUG_INFO("ocpp version: %s\n", version);
  15306. if(strstr((char*)version, "ocpp1.6") != NULL)
  15307. {
  15308. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  15309. }
  15310. else if(strstr((char*)version, "ocpp2.0") != NULL)
  15311. {
  15312. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  15313. system("pkill OcppBackend");
  15314. }
  15315. }
  15316. void SetServerSign(int value)
  15317. {
  15318. server_sign = value;
  15319. }
  15320. int GetBootNotificationInterval(void)
  15321. {
  15322. return BootNotificationInterval;
  15323. }
  15324. int GetInternetConn(void)
  15325. {
  15326. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  15327. }
  15328. int isConnectorInitMode(int gun_index)
  15329. {
  15330. int tempIndex = 0;
  15331. int result = TRUE;
  15332. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15333. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15334. {
  15335. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15336. {
  15337. tempIndex = ((gun_index==2) ? 1: 0);
  15338. }
  15339. else
  15340. {
  15341. tempIndex = gun_index;
  15342. }
  15343. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15344. {
  15345. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  15346. {
  15347. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15348. } //end of the same index
  15349. }//end of for CHAdeMO_QUANTITY
  15350. }
  15351. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15352. {
  15353. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15354. {
  15355. tempIndex = ((gun_index==2) ? 1: 0);
  15356. }
  15357. else
  15358. {
  15359. tempIndex = gun_index;
  15360. }
  15361. for (int index = 0; index < CCS_QUANTITY; index++)
  15362. {
  15363. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15364. {
  15365. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15366. } //end of the same index
  15367. } // end of for CCS_QUANTITY
  15368. }
  15369. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15370. {
  15371. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15372. {
  15373. tempIndex = ((gun_index==2) ? 1: 0);
  15374. }
  15375. else
  15376. {
  15377. tempIndex = gun_index;
  15378. }
  15379. for (int index = 0; index < GB_QUANTITY; index++)
  15380. {
  15381. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15382. {
  15383. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15384. } //end of the same index
  15385. } // end of for GB_QUANTITY
  15386. }
  15387. else if(gunType[gun_index] == GUN_TYPE_DO)
  15388. {
  15389. tempIndex = gun_index;
  15390. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15391. {
  15392. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15393. {
  15394. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15395. } //end of the same index
  15396. }
  15397. }
  15398. else
  15399. {
  15400. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15401. {
  15402. tempIndex = 2;
  15403. }
  15404. else
  15405. {
  15406. tempIndex = gun_index;
  15407. }
  15408. for (int index = 0; index < AC_QUANTITY; index++)
  15409. {
  15410. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15411. {
  15412. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15413. }//end of the same index
  15414. }//end of for AC_QUANTITY
  15415. }
  15416. return result;
  15417. }
  15418. void refreshProcDogTimer()
  15419. {
  15420. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  15421. }
  15422. void InitialSystemValue(void)
  15423. {
  15424. int connectorIndex = 0;
  15425. //int valueASCII = 0;
  15426. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15427. gunTotalNumber=0;
  15428. SystemInitial = 0;
  15429. localversion=0;
  15430. BootNotificationInterval = 0;
  15431. authorizeRetryTimes = 0;
  15432. GunStatusInterval = 10;
  15433. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15434. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15435. //Hear Beat
  15436. HeartBeatWithNOResponse = 0;
  15437. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  15438. FirstHeartBeat = 0;
  15439. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  15440. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  15441. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  15442. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  15443. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  15444. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  15445. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  15446. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  15447. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  15448. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  15449. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  15450. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  15451. memset(gunType, 0, ARRAY_SIZE(gunType));
  15452. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  15453. {
  15454. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O')
  15455. {
  15456. // DO series
  15457. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  15458. {
  15459. SystemInitial = SystemInitial + 1;
  15460. gunTotalNumber = gunTotalNumber + 1;
  15461. gunType[connectorIndex] = GUN_TYPE_DO;
  15462. connectorIndex = connectorIndex + 1;
  15463. }
  15464. }
  15465. else
  15466. {
  15467. // DM, DW, DS series
  15468. //check connector / socket type (index: 8, 9, 10)
  15469. for(int index=7; index <10 ; index++)
  15470. {
  15471. if(index != 8)
  15472. {
  15473. // DC Connector
  15474. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  15475. {
  15476. SystemInitial = SystemInitial + 1;
  15477. gunTotalNumber = gunTotalNumber + 1;
  15478. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  15479. connectorIndex = connectorIndex + 1;
  15480. }
  15481. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  15482. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  15483. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  15484. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  15485. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  15486. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  15487. {
  15488. SystemInitial = SystemInitial + 1;
  15489. gunTotalNumber = gunTotalNumber + 1;
  15490. gunType[connectorIndex] = GUN_TYPE_CCS;
  15491. connectorIndex = connectorIndex + 1;
  15492. }
  15493. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  15494. {
  15495. SystemInitial = SystemInitial + 1;
  15496. gunTotalNumber = gunTotalNumber + 1;
  15497. gunType[connectorIndex] = GUN_TYPE_GBT;
  15498. connectorIndex = connectorIndex + 1;
  15499. }
  15500. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  15501. {
  15502. SystemInitial = SystemInitial + 1;
  15503. gunTotalNumber = gunTotalNumber + 1;
  15504. gunType[connectorIndex] = GUN_TYPE_DO;
  15505. connectorIndex = connectorIndex + 1;
  15506. }
  15507. }
  15508. else
  15509. {
  15510. // AC Connector
  15511. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15512. {
  15513. SystemInitial = SystemInitial + 1;
  15514. gunTotalNumber = gunTotalNumber + 1;
  15515. gunType[connectorIndex] = GUN_TYPE_AC;
  15516. connectorIndex = connectorIndex + 1;
  15517. }
  15518. }
  15519. }
  15520. }
  15521. //DEBUG_INFO("DC ...\n");
  15522. }
  15523. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  15524. {
  15525. //check connector / socket type (index: 8, 9, 10)
  15526. for(int index=7; index <10 ; index++)
  15527. {
  15528. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15529. {
  15530. SystemInitial = SystemInitial + 1;
  15531. gunTotalNumber = gunTotalNumber + 1;
  15532. gunType[connectorIndex] = GUN_TYPE_AC;
  15533. connectorIndex = connectorIndex + 1;
  15534. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  15535. }
  15536. }
  15537. }
  15538. //Status && ConnectorPlugIn Setting
  15539. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15540. {
  15541. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  15542. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  15543. }
  15544. for (int index = 0; index < CCS_QUANTITY; index++)
  15545. {
  15546. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  15547. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  15548. }
  15549. for (int index = 0; index < GB_QUANTITY; index++)
  15550. {
  15551. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  15552. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  15553. }
  15554. for (int index = 0; index < AC_QUANTITY; index++)
  15555. {
  15556. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  15557. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  15558. }
  15559. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15560. {
  15561. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  15562. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  15563. }
  15564. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  15565. {
  15566. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  15567. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  15568. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  15569. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  15570. }
  15571. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  15572. clientTime.Heartbeat=time((time_t*)NULL);
  15573. sleep(1);
  15574. }
  15575. void LWS_Send(char * str)
  15576. {
  15577. //=====================================================
  15578. // Check InternetConn 0: disconnected, 1: connected
  15579. //====================================================
  15580. if(GetOcppConnStatus() == 0)
  15581. {
  15582. DEBUG_INFO("offline now !!!\n");
  15583. return;
  15584. }
  15585. pthread_mutex_lock(&lock_send);
  15586. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  15587. sprintf((char *)SendBuffer, "%s", str);
  15588. SendBufLen = strlen(str);
  15589. pthread_mutex_unlock(&lock_send);
  15590. lws_callback_on_writable(wsi_client);
  15591. //lws_service(context, 0);
  15592. //sleep(1);
  15593. }
  15594. void LWS_SendNow(char * str)
  15595. {
  15596. //=====================================================
  15597. // Check InternetConn 0: disconnected, 1: connected
  15598. //====================================================
  15599. if(GetOcppConnStatus() == 0)
  15600. {
  15601. DEBUG_INFO("offline now !!!\n");
  15602. return;
  15603. }
  15604. pthread_mutex_lock(&lock_send);
  15605. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  15606. sprintf((char *)SendBuffer, "%s", str);
  15607. SendBufLen = strlen(str);
  15608. pthread_mutex_unlock(&lock_send);
  15609. lws_callback_on_writable(wsi_client);
  15610. lws_service(context, 0);
  15611. //sleep(1);
  15612. }