MessageHandler.c 767 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023
  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("rm -f /tmp/*.json");
  867. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  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. // Delete duplicate period
  2187. if(compositePeriodIdx > 1)
  2188. {
  2189. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2190. {
  2191. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2192. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2193. compositePeriodIdx -= 1;
  2194. }
  2195. }
  2196. }
  2197. else
  2198. break;
  2199. }
  2200. }
  2201. else
  2202. {
  2203. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2204. {
  2205. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2206. compositePeriodIdx++;
  2207. }
  2208. else
  2209. {
  2210. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2211. }
  2212. }
  2213. }
  2214. }
  2215. }
  2216. }
  2217. }
  2218. }
  2219. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2220. else if(defaultTxProfile.ChargingProfileId != -1)
  2221. {
  2222. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2223. {
  2224. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2225. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2226. (defaultTxProfile.ChargingSchedule.Duration > 0))
  2227. {
  2228. if(maxProfile.ChargingProfileId != -1)
  2229. {
  2230. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2231. {
  2232. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2233. {
  2234. if((maxProfile.ChargingSchedule.Duration > 0))
  2235. {
  2236. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2237. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2238. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  2239. }
  2240. else
  2241. {
  2242. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2243. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2244. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2245. }
  2246. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2247. {
  2248. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2249. {
  2250. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2251. compositePeriodIdx++;
  2252. }
  2253. else
  2254. {
  2255. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2256. }
  2257. }
  2258. // Delete duplicate period
  2259. if(compositePeriodIdx > 1)
  2260. {
  2261. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2262. {
  2263. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2264. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2265. compositePeriodIdx -= 1;
  2266. }
  2267. }
  2268. }
  2269. else
  2270. break;
  2271. }
  2272. }
  2273. else
  2274. {
  2275. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2276. {
  2277. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2278. compositePeriodIdx++;
  2279. }
  2280. else
  2281. {
  2282. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2283. }
  2284. }
  2285. }
  2286. }
  2287. }
  2288. // Fill other period by MaxProfile
  2289. if(maxProfile.ChargingProfileId != -1)
  2290. {
  2291. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2292. {
  2293. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2294. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2295. (maxProfile.ChargingSchedule.Duration > 0))
  2296. {
  2297. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  2298. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2299. {
  2300. tmpPeriod.StartPeriod = (compositePeriodIdx==0)?0:compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  2301. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  2302. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2303. }
  2304. if((compositePeriodIdx > 0 ) && (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2305. {
  2306. tmpPeriod.StartPeriod = (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod>compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod:compositeProfile->ChargingSchedule.Duration;
  2307. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  2308. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2309. }
  2310. if(tmpPeriod.Limit != -1)
  2311. {
  2312. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2313. {
  2314. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2315. {
  2316. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2317. compositePeriodIdx++;
  2318. }
  2319. else
  2320. {
  2321. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2322. }
  2323. }
  2324. // Delete duplicate period
  2325. if(compositePeriodIdx > 1)
  2326. {
  2327. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2328. {
  2329. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2330. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2331. compositePeriodIdx -= 1;
  2332. }
  2333. }
  2334. }
  2335. }
  2336. }
  2337. }
  2338. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  2339. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2340. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  2341. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  2342. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2343. {
  2344. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2345. {
  2346. compositeProfile->ChargingProfileId = 1;
  2347. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2348. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2349. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2350. }
  2351. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2352. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2353. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2354. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2355. }
  2356. if(line)
  2357. free(line);
  2358. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  2359. }
  2360. //==========================================
  2361. // Init all share memory
  2362. //==========================================
  2363. int InitShareMemory()
  2364. {
  2365. int result = PASS;
  2366. int MeterSMId;
  2367. //creat ShmSysConfigAndInfo
  2368. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  2369. {
  2370. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  2371. result = FAIL;
  2372. }
  2373. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2374. {
  2375. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  2376. result = FAIL;
  2377. }
  2378. else
  2379. {}
  2380. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  2381. {
  2382. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  2383. result = FAIL;
  2384. }
  2385. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2386. {
  2387. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  2388. result = FAIL;
  2389. }
  2390. else
  2391. {}
  2392. //creat ShmPsuData
  2393. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  2394. {
  2395. DEBUG_ERROR("shmget ShmPsuData NG\n");
  2396. result = FAIL;
  2397. }
  2398. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2399. {
  2400. DEBUG_ERROR("shmat ShmPsuData NG\n");
  2401. result = FAIL;
  2402. }
  2403. else
  2404. {}
  2405. //creat ShmOCPP16Data
  2406. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  2407. {
  2408. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  2409. result = FAIL;
  2410. }
  2411. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2412. {
  2413. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  2414. result = FAIL;
  2415. }
  2416. else
  2417. {}
  2418. /****************************** For Initial Settings************************************************/
  2419. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  2420. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  2421. // allocate Configuration memory address
  2422. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  2423. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  2424. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  2425. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  2426. //offline MeterValue Interval
  2427. TempMeterValueInterval = 0;
  2428. return result;
  2429. }
  2430. int ProcessShareMemory()
  2431. {
  2432. if(InitShareMemory() == FAIL)
  2433. {
  2434. DEBUG_ERROR("InitShareMemory NG\n");
  2435. if(ShmStatusCodeData!=NULL)
  2436. {
  2437. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  2438. }
  2439. sleep(5);
  2440. return FAIL;
  2441. }
  2442. return PASS;
  2443. }
  2444. void CheckSystemValue(void)
  2445. {
  2446. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  2447. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  2448. char filenmae[100]={0};
  2449. char str[100]={0};
  2450. int tempIndex = 0;
  2451. //===============================
  2452. // send Heartbeat
  2453. //===============================
  2454. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2455. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2456. {
  2457. clientTime.Heartbeat=time((time_t*)NULL);
  2458. if(server_sign == TRUE)
  2459. {
  2460. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2461. }
  2462. else
  2463. {
  2464. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2465. }
  2466. }
  2467. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  2468. {
  2469. //parameter for test
  2470. sendHeartbeatRequest(0);
  2471. //==============================================
  2472. // Reset Waiting Time
  2473. //==============================================
  2474. HeartBeatWithNOResponse += 1;
  2475. }
  2476. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2477. {
  2478. //==========================================
  2479. // csu trigger DataTransferReq
  2480. //==========================================
  2481. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2482. {
  2483. sendDataTransferRequest(gun_index);
  2484. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2485. }
  2486. //===============================
  2487. // CSU Trigger Authorize Request
  2488. //===============================
  2489. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2490. {
  2491. sendAuthorizeRequest(0);
  2492. authorizeRetryTimes = authorizeRetryTimes + 1;
  2493. if(authorizeRetryTimes < 3)
  2494. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2495. }
  2496. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  2497. {
  2498. authorizeRetryTimes = 0;
  2499. SetOcppConnStatus(FALSE);
  2500. server_sign = FALSE;
  2501. }
  2502. 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))
  2503. {
  2504. sendAuthorizeRequest(0);
  2505. }
  2506. //==============================================
  2507. // CSU Trigger Smart Charging Profilw
  2508. //==============================================
  2509. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2510. {
  2511. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  2512. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2513. }
  2514. //==============================================
  2515. // Charger start transaction
  2516. //==============================================
  2517. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2518. {
  2519. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  2520. sendStartTransactionRequest(gun_index);
  2521. clientTime.StartTransaction = time((time_t*)NULL);
  2522. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2523. storeTempStopTransaction(gun_index);
  2524. }
  2525. //==============================================
  2526. // Charger stop transaction
  2527. //==============================================
  2528. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2529. {
  2530. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2531. sendStopTransactionRequest(gun_index);
  2532. clientTime.StopTransaction = time((time_t*)NULL);
  2533. }
  2534. //==============================================
  2535. // Charger status report
  2536. //==============================================
  2537. //--- Check Mode Change ---//
  2538. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2539. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2540. {
  2541. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2542. {
  2543. tempIndex = ((gun_index==2) ? 1: 0);
  2544. }
  2545. else
  2546. {
  2547. tempIndex = gun_index;
  2548. }
  2549. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2550. {
  2551. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2552. {
  2553. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  2554. {
  2555. // Sent unplug message for California pricing logic
  2556. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  2557. {
  2558. uint8_t ts[20];
  2559. getNowDatetime(ts);
  2560. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2561. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2562. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2563. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2564. }
  2565. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2566. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2567. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2568. statusModeChage[gun_index] = TRUE;
  2569. }
  2570. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2571. {
  2572. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2573. if((access(filenmae,F_OK))!=-1)
  2574. {
  2575. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2576. sprintf(str,"rm -f %s",filenmae);
  2577. system(str);
  2578. }
  2579. }
  2580. #if 1 // for TempStopTransaction
  2581. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2582. {
  2583. checkTempStopTransaction(gun_index);
  2584. }
  2585. #endif
  2586. }
  2587. }
  2588. }
  2589. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2590. {
  2591. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2592. {
  2593. tempIndex = ((gun_index==2) ? 1: 0);
  2594. }
  2595. else
  2596. {
  2597. tempIndex = gun_index;
  2598. }
  2599. for (int index = 0; index < CCS_QUANTITY; index++)
  2600. {
  2601. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2602. {
  2603. 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]*/ )
  2604. {
  2605. // Sent unplug message for California pricing logic
  2606. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  2607. {
  2608. uint8_t ts[20];
  2609. getNowDatetime(ts);
  2610. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2611. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2612. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2613. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2614. }
  2615. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2616. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2617. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2618. statusModeChage[gun_index] = TRUE;
  2619. }
  2620. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2621. {
  2622. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2623. if((access(filenmae,F_OK))!=-1)
  2624. {
  2625. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2626. sprintf(str,"rm -f %s",filenmae);
  2627. system(str);
  2628. }
  2629. }
  2630. #if 1 // for TempStopTransaction
  2631. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2632. {
  2633. checkTempStopTransaction(gun_index);
  2634. }
  2635. #endif
  2636. }
  2637. }
  2638. }
  2639. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2640. {
  2641. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2642. {
  2643. tempIndex = ((gun_index==2) ? 1: 0);
  2644. }
  2645. else
  2646. {
  2647. tempIndex = gun_index;
  2648. }
  2649. for (int index = 0; index < GB_QUANTITY; index++)
  2650. {
  2651. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2652. {
  2653. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2654. {
  2655. // Sent unplug message for California pricing logic
  2656. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  2657. {
  2658. uint8_t ts[20];
  2659. getNowDatetime(ts);
  2660. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2661. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2662. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2663. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2664. }
  2665. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2666. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2667. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2668. statusModeChage[gun_index] = TRUE;
  2669. }
  2670. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2671. {
  2672. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2673. if((access(filenmae,F_OK))!=-1)
  2674. {
  2675. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2676. sprintf(str,"rm -f %s",filenmae);
  2677. system(str);
  2678. }
  2679. }
  2680. #if 1 // for TempStopTransaction
  2681. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2682. {
  2683. checkTempStopTransaction(gun_index);
  2684. }
  2685. #endif
  2686. }
  2687. }
  2688. }
  2689. else if(gunType[gun_index] == GUN_TYPE_DO)
  2690. {
  2691. tempIndex = gun_index;
  2692. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2693. {
  2694. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2695. {
  2696. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  2697. {
  2698. // Sent unplug message for California pricing logic
  2699. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  2700. {
  2701. uint8_t ts[20];
  2702. getNowDatetime(ts);
  2703. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2704. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2705. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2706. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2707. }
  2708. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  2709. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  2710. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2711. statusModeChage[gun_index] = TRUE;
  2712. }
  2713. 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
  2714. {
  2715. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2716. if((access(filenmae,F_OK))!=-1)
  2717. {
  2718. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2719. sprintf(str,"rm -f %s",filenmae);
  2720. system(str);
  2721. }
  2722. }
  2723. #if 1 // for TempStopTransaction
  2724. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2725. {
  2726. checkTempStopTransaction(gun_index);
  2727. }
  2728. #endif
  2729. }
  2730. }
  2731. }
  2732. else
  2733. {
  2734. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2735. {
  2736. tempIndex = 2;
  2737. }
  2738. else
  2739. {
  2740. tempIndex = gun_index;
  2741. }
  2742. for (int index = 0; index < AC_QUANTITY; index++)
  2743. {
  2744. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2745. {
  2746. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2747. {
  2748. // Sent unplug message for California pricing logic
  2749. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)
  2750. {
  2751. uint8_t ts[20];
  2752. getNowDatetime(ts);
  2753. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2754. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2755. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2756. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2757. }
  2758. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2759. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2760. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2761. statusModeChage[gun_index] = TRUE;
  2762. }
  2763. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2764. {
  2765. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2766. if((access(filenmae,F_OK))!=-1)
  2767. {
  2768. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2769. sprintf(str,"rm -f %s",filenmae);
  2770. system(str);
  2771. }
  2772. }
  2773. #if 1 // for TempStopTransaction
  2774. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2775. {
  2776. checkTempStopTransaction(gun_index);
  2777. }
  2778. #endif
  2779. }
  2780. }// END
  2781. }
  2782. if(isWebsocketSendable && (server_sign == TRUE) &&
  2783. (
  2784. (statusModeChage[gun_index] == TRUE) ||
  2785. //((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index))) ||
  2786. ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 5))
  2787. )
  2788. )
  2789. {
  2790. if(SystemInitial > 0)
  2791. SystemInitial -= 1;
  2792. sendStatusNotificationRequest(gun_index);
  2793. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2794. statusModeChage[gun_index] = FALSE;
  2795. }
  2796. //==============================================
  2797. // Meter report
  2798. //==============================================
  2799. // Trigger MeterValue
  2800. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  2801. {
  2802. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  2803. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  2804. }
  2805. // ClockAlign MeterValue
  2806. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  2807. {
  2808. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2809. {
  2810. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2811. {
  2812. tempIndex = ((gun_index==2) ? 1: 0);
  2813. }
  2814. else
  2815. {
  2816. tempIndex = gun_index;
  2817. }
  2818. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2819. {
  2820. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2821. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2822. {
  2823. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2824. {
  2825. reqClockAlignMeter[gun_index] = 1;
  2826. }
  2827. }
  2828. }// End for CHAdeMO
  2829. }
  2830. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2831. {
  2832. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2833. {
  2834. tempIndex = ((gun_index==2) ? 1: 0);
  2835. }
  2836. else
  2837. {
  2838. tempIndex = gun_index;
  2839. }
  2840. for (int index = 0; index < CCS_QUANTITY; index++)
  2841. {
  2842. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2843. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2844. {
  2845. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2846. {
  2847. reqClockAlignMeter[gun_index] = 1;
  2848. }
  2849. }
  2850. } // End for CCS
  2851. }
  2852. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2853. {
  2854. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2855. {
  2856. tempIndex = ((gun_index==2) ? 1: 0);
  2857. }
  2858. else
  2859. {
  2860. tempIndex = gun_index;
  2861. }
  2862. for (int index = 0; index < GB_QUANTITY; index++)
  2863. {
  2864. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2865. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2866. {
  2867. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2868. {
  2869. reqClockAlignMeter[gun_index] = 1;
  2870. }
  2871. }
  2872. }// End for GB
  2873. }
  2874. else if(gunType[gun_index] == GUN_TYPE_DO)
  2875. {
  2876. tempIndex = gun_index;
  2877. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2878. {
  2879. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2880. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2881. {
  2882. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_CHARGING)
  2883. {
  2884. reqClockAlignMeter[gun_index] = 1;
  2885. }
  2886. }
  2887. }
  2888. }
  2889. else
  2890. {
  2891. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2892. {
  2893. tempIndex = 2;
  2894. }
  2895. else
  2896. {
  2897. tempIndex = gun_index;
  2898. }
  2899. for (int index = 0; index < AC_QUANTITY; index++)
  2900. {
  2901. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2902. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2903. {
  2904. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2905. {
  2906. reqClockAlignMeter[gun_index] = 1;
  2907. }
  2908. }
  2909. }//End for AC
  2910. }
  2911. if(reqClockAlignMeter[gun_index] == 1)
  2912. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2913. }
  2914. // Sample period MeterValue
  2915. if((((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1))))
  2916. {
  2917. //check Transaction active
  2918. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2919. {
  2920. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2921. {
  2922. tempIndex = ((gun_index==2) ? 1: 0);
  2923. }
  2924. else
  2925. {
  2926. tempIndex = gun_index;
  2927. }
  2928. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2929. {
  2930. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2931. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2932. {
  2933. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2934. {
  2935. reqSampleMeter[gun_index] = 1;
  2936. }
  2937. }
  2938. }// End for CHAdeMO
  2939. }
  2940. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2941. {
  2942. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2943. {
  2944. tempIndex = ((gun_index==2) ? 1: 0);
  2945. }
  2946. else
  2947. {
  2948. tempIndex = gun_index;
  2949. }
  2950. for (int index = 0; index < CCS_QUANTITY; index++)
  2951. {
  2952. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2953. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2954. {
  2955. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2956. {
  2957. reqSampleMeter[gun_index] = 1;
  2958. }
  2959. }
  2960. } // End for CCS
  2961. }
  2962. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2963. {
  2964. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2965. {
  2966. tempIndex = ((gun_index==2) ? 1: 0);
  2967. }
  2968. else
  2969. {
  2970. tempIndex = gun_index;
  2971. }
  2972. for (int index = 0; index < GB_QUANTITY; index++)
  2973. {
  2974. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2975. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2976. {
  2977. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2978. {
  2979. reqSampleMeter[gun_index] = 1;
  2980. }
  2981. }
  2982. }// End for GB
  2983. }
  2984. else if(gunType[gun_index] == GUN_TYPE_DO)
  2985. {
  2986. tempIndex = gun_index;
  2987. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2988. {
  2989. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2990. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2991. {
  2992. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  2993. {
  2994. reqSampleMeter[gun_index] = 1;
  2995. }
  2996. }
  2997. }
  2998. }
  2999. else
  3000. {
  3001. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3002. {
  3003. tempIndex = 2;
  3004. }
  3005. else
  3006. {
  3007. tempIndex = gun_index;
  3008. }
  3009. for (int index = 0; index < AC_QUANTITY; index++)
  3010. {
  3011. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3012. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3013. {
  3014. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  3015. {
  3016. reqSampleMeter[gun_index] = 1;
  3017. }
  3018. }
  3019. }//End for AC
  3020. }
  3021. if(reqSampleMeter[gun_index] == 1)
  3022. {
  3023. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  3024. storeTempStopTransaction(gun_index);
  3025. }
  3026. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3027. }
  3028. //==============================================
  3029. // Check Connector reserved
  3030. //==============================================
  3031. //===============================
  3032. // Check if Reserve is expired
  3033. //===============================
  3034. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  3035. {
  3036. double diff_t;
  3037. struct tm tp;
  3038. // current time
  3039. time_t t = time(NULL);
  3040. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  3041. tp.tm_isdst = -1;
  3042. time_t utc = mktime(&tp);
  3043. diff_t = difftime(utc, t);
  3044. if(diff_t <= 0)
  3045. {
  3046. DEBUG_INFO("reserve expired.\n");
  3047. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  3048. }
  3049. }//END OF Check if Reserve is expired
  3050. //==========================================
  3051. // csu trigger FirmwareStatusNotificationReq
  3052. //==========================================
  3053. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  3054. {
  3055. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  3056. }
  3057. //==========================================
  3058. // csu trigger DiagnosticsStatusNotificationReq
  3059. //==========================================
  3060. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  3061. {
  3062. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  3063. }
  3064. //==========================================
  3065. // csu trigger CancelReservationConf
  3066. //==========================================
  3067. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  3068. {
  3069. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  3070. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  3071. }
  3072. //==========================================
  3073. // csu trigger ChangeAvailabilityConf
  3074. //==========================================
  3075. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  3076. {
  3077. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  3078. }
  3079. //==========================================
  3080. // csu trigger UnlockConnectorConf
  3081. //==========================================
  3082. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  3083. {
  3084. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  3085. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  3086. }
  3087. //==========================================
  3088. // csu trigger ReserveNowConf
  3089. //==========================================
  3090. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  3091. {
  3092. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  3093. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  3094. }
  3095. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  3096. {
  3097. sendSignCertificateRequest();
  3098. }
  3099. }
  3100. }
  3101. //==========================================
  3102. // send request routine
  3103. //==========================================
  3104. int sendAuthorizeRequest(int gun_index)
  3105. {
  3106. mtrace();
  3107. int result = FAIL;
  3108. char message[100]={0};
  3109. char guid[37];
  3110. char tempdata[65]={0};
  3111. DEBUG_INFO("sendAuthorizeRequest...\n");
  3112. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  3113. //Local Authorize
  3114. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  3115. {
  3116. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  3117. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  3118. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  3119. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  3120. result = PASS;
  3121. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3122. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3123. authorizeRetryTimes = 0;
  3124. return result;
  3125. }
  3126. 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))||
  3127. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  3128. {
  3129. // Query from cache
  3130. DEBUG_INFO("Authorize from cache.\n");
  3131. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3132. // Query from list
  3133. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3134. {
  3135. DEBUG_INFO("Authorize from list.\n");
  3136. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3137. }
  3138. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3139. {
  3140. if(strcmp(idTagQuery.idTagstr,"") == 0)
  3141. {
  3142. DEBUG_INFO("off-line Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  3143. }
  3144. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  3145. {
  3146. DEBUG_INFO("off-line Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  3147. }
  3148. DEBUG_INFO("off-line Local Authorization Fail !!!!\n");
  3149. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3150. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3151. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  3152. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3153. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3154. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3155. authorizeRetryTimes = 0;
  3156. return result;
  3157. }
  3158. else
  3159. {
  3160. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  3161. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3162. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3163. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  3164. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  3165. else
  3166. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  3167. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3168. result = PASS;
  3169. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3170. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3171. authorizeRetryTimes = 0;
  3172. return result;
  3173. }
  3174. }
  3175. //initialize struct Authorize
  3176. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  3177. //get data from shared memory
  3178. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3179. random_uuid(guid);
  3180. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  3181. LWS_Send(message);
  3182. sprintf(tempdata, "Authorize,%d", gun_index);
  3183. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3184. {
  3185. result = PASS;
  3186. DEBUG_INFO("Authorize mapItem pass\n");
  3187. }
  3188. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3189. return result;
  3190. }
  3191. int sendBootNotificationRequest(void)
  3192. {
  3193. mtrace();
  3194. int result = FAIL;
  3195. char message[500]={0}, payload[700]={0};
  3196. char guid[37]={0};
  3197. char tempdata[65]={0};
  3198. // Fill BootNotification fields
  3199. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  3200. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  3201. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  3202. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3203. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  3204. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  3205. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  3206. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  3207. ShmOCPP16Data->ChargeBoxId
  3208. ,ShmSysConfigAndInfo->SysConfig.ModelName
  3209. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  3210. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  3211. ,ShmOCPP16Data->BootNotification.CpFwVersion
  3212. ,ShmOCPP16Data->BootNotification.CpIccid
  3213. ,ShmOCPP16Data->BootNotification.CpImsi);
  3214. random_uuid(guid);
  3215. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  3216. LWS_Send(message);
  3217. sprintf(tempdata, "BootNotification,0");
  3218. 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*/)
  3219. {
  3220. result = PASS;
  3221. }
  3222. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3223. strcpy(queuedata,message);
  3224. return result;
  3225. }
  3226. int sendDataTransferRequest(int gun_index)
  3227. {
  3228. mtrace();
  3229. char message[1000]={0};
  3230. char guid[37]={0};
  3231. char tempdata[65]={0};
  3232. int result = FAIL;
  3233. random_uuid(guid);
  3234. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  3235. MESSAGE_TYPE_CALL,
  3236. guid,
  3237. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  3238. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  3239. ShmOCPP16Data->DataTransfer[gun_index].Data);
  3240. LWS_Send(message);
  3241. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  3242. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3243. {
  3244. result = PASS;
  3245. DEBUG_INFO("DataTransfer mapItem pass\n");
  3246. }
  3247. return result;
  3248. }
  3249. int sendDiagnosticsStatusNotificationRequest(char *status)
  3250. {
  3251. mtrace();
  3252. int result = FAIL;
  3253. char message[110]={0};
  3254. char guid[37]={0};
  3255. char tempdata[65]={0};
  3256. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  3257. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  3258. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  3259. random_uuid(guid);
  3260. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  3261. LWS_SendNow(message);
  3262. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  3263. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3264. {
  3265. result = PASS;
  3266. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  3267. }
  3268. //#ifdef SystemLogMessage
  3269. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  3270. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3271. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  3272. //#endif
  3273. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  3274. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  3275. //record status
  3276. if(strcmp(status,"Idle")==0)
  3277. {
  3278. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  3279. }
  3280. else if(strcmp(status,"Uploaded")==0)
  3281. {
  3282. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  3283. }
  3284. else if(strcmp(status,"UploadFailed")==0)
  3285. {
  3286. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  3287. }
  3288. else if(strcmp(status,"Uploading")==0)
  3289. {
  3290. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  3291. }
  3292. return result;
  3293. }
  3294. int sendFirmwareStatusNotificationRequest(char *status)
  3295. {
  3296. mtrace();
  3297. int result = FAIL;
  3298. char message[110]={0};
  3299. char guid[37]={0};
  3300. char tempdata[65]={0};
  3301. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  3302. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  3303. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  3304. random_uuid(guid);
  3305. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  3306. LWS_SendNow(message);
  3307. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  3308. 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*/)
  3309. {
  3310. result = PASS;
  3311. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  3312. }
  3313. //#ifdef SystemLogMessage
  3314. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  3315. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3316. //#endif
  3317. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  3318. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  3319. //record status
  3320. if(strcmp(status,"Downloaded")==0)
  3321. {
  3322. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  3323. }
  3324. else if(strcmp(status,"DownloadFailed")==0)
  3325. {
  3326. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  3327. }
  3328. else if(strcmp(status,"Downloading")==0)
  3329. {
  3330. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  3331. }
  3332. else if(strcmp(status,"Idle")==0)
  3333. {
  3334. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  3335. }
  3336. else if(strcmp(status,"InstallationFailed")==0)
  3337. {
  3338. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  3339. }
  3340. else if(strcmp(status,"Installing")==0)
  3341. {
  3342. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  3343. }
  3344. else if(strcmp(status,"Installed")==0)
  3345. {
  3346. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  3347. }
  3348. return result;
  3349. }
  3350. int sendHeartbeatRequest(int gun_index)
  3351. {
  3352. mtrace();
  3353. int result = FAIL;
  3354. char message[80]={0};
  3355. char guid[37]={0};
  3356. char tempdata[65]={0};
  3357. random_uuid(guid);
  3358. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  3359. , MESSAGE_TYPE_CALL
  3360. , guid );
  3361. LWS_Send(message);
  3362. sprintf(tempdata, "Heartbeat,%d", 0);
  3363. 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*/)
  3364. {
  3365. result = PASS;
  3366. }
  3367. return result;
  3368. }
  3369. int sendStartTransactionRequest(int gun_index)
  3370. {
  3371. mtrace();
  3372. int result = FAIL;
  3373. char message[250]={0};
  3374. char guid[37]={0};
  3375. struct timeval tmnow;
  3376. struct tm *tm;
  3377. char buf[28];//, usec_buf[6];
  3378. char tempdata[65]={0};
  3379. int tempIndex = 0;
  3380. DEBUG_INFO("sendStartTransactionRequest...\n");
  3381. gettimeofday(&tmnow, NULL);
  3382. time_t t;
  3383. t = time(NULL);
  3384. /*UTC time and date*/
  3385. tm = gmtime(&t);
  3386. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3387. #if 0 // remove temporally
  3388. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3389. strcat(buf,".");
  3390. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3391. strcat(buf,usec_buf);
  3392. #endif
  3393. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  3394. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  3395. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3396. // clear StartTransaction Response
  3397. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  3398. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  3399. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  3400. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  3401. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3402. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3403. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3404. {
  3405. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3406. {
  3407. tempIndex = ((gun_index==2) ? 1: 0);
  3408. }
  3409. else
  3410. {
  3411. tempIndex = gun_index;
  3412. }
  3413. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3414. {
  3415. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3416. {
  3417. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3418. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  3419. }
  3420. }
  3421. }
  3422. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3423. {
  3424. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3425. {
  3426. tempIndex = ((gun_index==2) ? 1: 0);
  3427. }
  3428. else
  3429. {
  3430. tempIndex = gun_index;
  3431. }
  3432. for (int index = 0; index < CCS_QUANTITY; index++)
  3433. {
  3434. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3435. {
  3436. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3437. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  3438. }
  3439. }
  3440. }
  3441. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3442. {
  3443. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3444. {
  3445. tempIndex = ((gun_index==2) ? 1: 0);
  3446. }
  3447. else
  3448. {
  3449. tempIndex = gun_index;
  3450. }
  3451. for (int index = 0; index < GB_QUANTITY; index++)
  3452. {
  3453. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3454. {
  3455. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3456. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  3457. }
  3458. }
  3459. }
  3460. else if(gunType[gun_index] == GUN_TYPE_DO)
  3461. {
  3462. tempIndex = gun_index;
  3463. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3464. {
  3465. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3466. {
  3467. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3468. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  3469. }
  3470. }
  3471. }
  3472. else
  3473. {
  3474. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3475. {
  3476. tempIndex = 2;
  3477. }
  3478. else
  3479. {
  3480. tempIndex = gun_index;
  3481. }
  3482. for (int index = 0; index < AC_QUANTITY; index++)
  3483. {
  3484. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3485. {
  3486. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3487. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  3488. }
  3489. }
  3490. }
  3491. random_uuid(guid);
  3492. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  3493. {
  3494. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  3495. , gun_index +1
  3496. , MESSAGE_TYPE_CALL
  3497. , guid
  3498. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3499. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3500. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3501. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3502. }
  3503. else
  3504. {
  3505. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  3506. , gun_index +1
  3507. , MESSAGE_TYPE_CALL
  3508. , guid
  3509. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3510. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3511. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3512. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  3513. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3514. }
  3515. #if 1
  3516. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  3517. 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*/)
  3518. {
  3519. result = PASS;
  3520. }
  3521. #endif
  3522. strcpy(queuedata, message);
  3523. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3524. OCPP_insert_transaction_msg(YES, queuedata);
  3525. return result;
  3526. }
  3527. int sendStatusNotificationRequest(int gun_index)
  3528. {
  3529. mtrace();
  3530. int result = FAIL;
  3531. char message[600]={0};
  3532. char guid[37];
  3533. int currentStatus = 0;
  3534. struct timeval tmnow;
  3535. struct tm *tm;
  3536. char buf[28];//, usec_buf[6];
  3537. char tempdata[65]={0};
  3538. int tempIndex = 0;
  3539. uint8_t isStateChanged = TRUE;
  3540. DEBUG_INFO("sendStatusNotificationRequest...\n");
  3541. gettimeofday(&tmnow, NULL);
  3542. time_t t;
  3543. t = time(NULL);
  3544. /*UTC time and date*/
  3545. tm = gmtime(&t);
  3546. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3547. #if 0 // remove temporally
  3548. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3549. strcat(buf,".");
  3550. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3551. strcat(buf,usec_buf);
  3552. #endif
  3553. printf("%s",buf);
  3554. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  3555. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  3556. // it's option
  3557. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  3558. /*
  3559. enum _SYSTEM_STATUS
  3560. {
  3561. S_BOOTING = 0,
  3562. S_IDLE, = 1
  3563. S_AUTHORIZING, =2
  3564. S_REASSIGN_CHECK, =3
  3565. S_REASSIGN, =4
  3566. S_PRECHARGE, =5
  3567. S_PREPARING_FOR_EV, =6
  3568. S_PREPARING_FOR_EVSE, =7
  3569. S_CHARGING, =8
  3570. S_TERMINATING, =9
  3571. S_COMPLETE, =10
  3572. S_ALARM, =11
  3573. S_FAULT =12
  3574. }
  3575. */
  3576. //check Transaction active
  3577. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3578. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3579. {
  3580. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3581. {
  3582. tempIndex = ((gun_index==2) ? 1: 0);
  3583. }
  3584. else
  3585. {
  3586. tempIndex = gun_index;
  3587. }
  3588. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3589. {
  3590. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  3591. {
  3592. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  3593. {
  3594. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3595. {
  3596. currentStatus = Preparing; //OCPP Status: Preparing
  3597. }
  3598. else
  3599. {
  3600. currentStatus = Available; //OCPP Status: Available
  3601. }
  3602. }
  3603. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3604. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3605. ) //S_PRECHARGE
  3606. {
  3607. currentStatus = Preparing; //OCPP Status: Preparing
  3608. }
  3609. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3610. {
  3611. currentStatus = Charging; //OCPP Status: Charging
  3612. }
  3613. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3614. {
  3615. currentStatus = Finishing; //OCPP Status: Finishing
  3616. }
  3617. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3618. {
  3619. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3620. }
  3621. 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
  3622. {
  3623. currentStatus = Unavailable; //OCPP Status: Unavailable
  3624. }
  3625. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3626. {
  3627. currentStatus = Faulted; //OCPP Status: Faulted
  3628. }
  3629. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3630. {
  3631. currentStatus = Reserved; //OCPP Status: Reserved
  3632. }
  3633. } //end of the same index
  3634. }//end of for CHAdeMO_QUANTITY
  3635. }
  3636. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3637. {
  3638. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3639. {
  3640. tempIndex = ((gun_index==2) ? 1: 0);
  3641. }
  3642. else
  3643. {
  3644. tempIndex = gun_index;
  3645. }
  3646. for (int index = 0; index < CCS_QUANTITY; index++)
  3647. {
  3648. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3649. {
  3650. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3651. {
  3652. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3653. {
  3654. currentStatus = Preparing; //OCPP Status: Preparing
  3655. }
  3656. else
  3657. {
  3658. currentStatus = Available; //OCPP Status: Available
  3659. }
  3660. }
  3661. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3662. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3663. ) //S_PRECHARGE
  3664. {
  3665. currentStatus = Preparing; //OCPP Status: Preparing
  3666. }
  3667. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3668. {
  3669. currentStatus = Charging; //OCPP Status: Charging
  3670. }
  3671. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3672. {
  3673. currentStatus = Finishing; //OCPP Status: Finishing
  3674. }
  3675. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3676. {
  3677. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3678. }
  3679. 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
  3680. {
  3681. currentStatus = Unavailable; //OCPP Status : Unavailable
  3682. }
  3683. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3684. {
  3685. currentStatus = Faulted; //OCPP Status: Faulted
  3686. }
  3687. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3688. {
  3689. currentStatus = Reserved; //OCPP Status: Reserved
  3690. }
  3691. } //end of the same index
  3692. } // end of for CCS_QUANTITY
  3693. }
  3694. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3695. {
  3696. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3697. {
  3698. tempIndex = ((gun_index==2) ? 1: 0);
  3699. }
  3700. else
  3701. {
  3702. tempIndex = gun_index;
  3703. }
  3704. for (int index = 0; index < GB_QUANTITY; index++)
  3705. {
  3706. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3707. {
  3708. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3709. {
  3710. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3711. {
  3712. currentStatus = Preparing; //OCPP Status: Preparing
  3713. }
  3714. else
  3715. {
  3716. currentStatus = Available; //OCPP Status: Available
  3717. }
  3718. }
  3719. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3720. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3721. ) //S_PRECHARGE
  3722. {
  3723. currentStatus = Preparing; //OCPP Status: Preparing
  3724. }
  3725. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3726. {
  3727. currentStatus = Charging; //OCPP Status: Charging
  3728. }
  3729. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3730. {
  3731. currentStatus = Finishing; //OCPP Status: Finishing
  3732. }
  3733. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3734. {
  3735. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3736. }
  3737. 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
  3738. {
  3739. currentStatus = Unavailable; //OCPP Status: Unavailable
  3740. }
  3741. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3742. {
  3743. currentStatus = Faulted; //OCPP Status: Faulted
  3744. }
  3745. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3746. {
  3747. currentStatus = Reserved; //OCPP Status: Reserved
  3748. }
  3749. } //end of the same index
  3750. } // end of for GB_QUANTITY
  3751. }
  3752. else if(gunType[gun_index] == GUN_TYPE_DO)
  3753. {
  3754. tempIndex = gun_index;
  3755. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3756. {
  3757. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3758. {
  3759. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3760. {
  3761. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3762. {
  3763. currentStatus = Preparing; //OCPP Status: Preparing
  3764. }
  3765. else
  3766. {
  3767. currentStatus = Available; //OCPP Status: Available
  3768. }
  3769. }
  3770. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3771. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3772. ) //S_PRECHARGE
  3773. {
  3774. currentStatus = Preparing; //OCPP Status: Preparing
  3775. }
  3776. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3777. {
  3778. currentStatus = Charging; //OCPP Status: Charging
  3779. }
  3780. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3781. {
  3782. currentStatus = Finishing; //OCPP Status: Finishing
  3783. }
  3784. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3785. {
  3786. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3787. }
  3788. 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
  3789. {
  3790. currentStatus = Unavailable; //OCPP Status: Unavailable
  3791. }
  3792. 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
  3793. {
  3794. currentStatus = Faulted; //OCPP Status: Faulted
  3795. }
  3796. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3797. {
  3798. currentStatus = Reserved; //OCPP Status: Reserved
  3799. }
  3800. } //end of the same index
  3801. }
  3802. }
  3803. else
  3804. {
  3805. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3806. {
  3807. tempIndex = 2;
  3808. }
  3809. else
  3810. {
  3811. tempIndex = gun_index;
  3812. }
  3813. for (int index = 0; index < AC_QUANTITY; index++)
  3814. {
  3815. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3816. {
  3817. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3818. {
  3819. 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))
  3820. {
  3821. currentStatus = Preparing; //OCPP Status: Preparing
  3822. }
  3823. else
  3824. {
  3825. currentStatus = Available; //OCPP Status: Available
  3826. }
  3827. }
  3828. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3829. {
  3830. currentStatus = Preparing; //OCPP Status: Preparing
  3831. }
  3832. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3833. {
  3834. currentStatus = Charging; //OCPP Status: Charging
  3835. }
  3836. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3837. {
  3838. currentStatus = Finishing; //OCPP Status: Finishing
  3839. }
  3840. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3841. {
  3842. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  3843. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3844. else
  3845. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  3846. }
  3847. 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
  3848. {
  3849. currentStatus = Unavailable; //OCPP Status: Unavailable
  3850. }
  3851. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3852. {
  3853. currentStatus = Faulted; //OCPP Status: Faulted
  3854. }
  3855. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3856. {
  3857. currentStatus = Reserved; //OCPP Status: Reserved
  3858. }
  3859. }//end of the same index
  3860. }//end of for AC_QUANTITY
  3861. }
  3862. //it's option
  3863. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  3864. !ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq)
  3865. {
  3866. isStateChanged = FALSE;
  3867. }
  3868. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  3869. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3870. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3871. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3872. random_uuid(guid);
  3873. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3874. , MESSAGE_TYPE_CALL
  3875. , guid
  3876. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3877. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3878. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3879. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3880. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3881. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3882. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3883. if((server_sign == TRUE) && isStateChanged)
  3884. {
  3885. LWS_Send(message);
  3886. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3887. 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*/)
  3888. {
  3889. //DEBUG_ERROR("statusNotification mapitem pass");
  3890. result = PASS;
  3891. }
  3892. }
  3893. else
  3894. {
  3895. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  3896. result = PASS;
  3897. }
  3898. return result;
  3899. }
  3900. int sendStopTransactionRequest(int gun_index)
  3901. {
  3902. mtrace();
  3903. int result = FAIL;
  3904. //char message[1500]={0};
  3905. char guid[37]={0};
  3906. char tempdata[65]={0};
  3907. int tempIndex = 0;
  3908. char TempStopTransaction[256];
  3909. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  3910. //int idx_sample=0;
  3911. DEBUG_INFO("sendStopTransactionRequest \n");
  3912. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3913. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  3914. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3915. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3916. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3917. {
  3918. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3919. {
  3920. tempIndex = ((gun_index==2) ? 1: 0);
  3921. }
  3922. else
  3923. {
  3924. tempIndex = gun_index;
  3925. }
  3926. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3927. {
  3928. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3929. {
  3930. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3931. }
  3932. }// END OF CHAdeMO_QUANTITY
  3933. }
  3934. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3935. {
  3936. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3937. {
  3938. tempIndex = ((gun_index==2) ? 1: 0);
  3939. }
  3940. else
  3941. {
  3942. tempIndex = gun_index;
  3943. }
  3944. for (int index = 0; index < CCS_QUANTITY; index++)
  3945. {
  3946. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3947. {
  3948. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3949. }
  3950. }// END OF CCS_QUANTITY
  3951. }
  3952. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3953. {
  3954. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3955. {
  3956. tempIndex = ((gun_index==2) ? 1: 0);
  3957. }
  3958. else
  3959. {
  3960. tempIndex = gun_index;
  3961. }
  3962. for (int index = 0; index < GB_QUANTITY; index++)
  3963. {
  3964. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3965. {
  3966. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3967. }
  3968. }// END OF GB_QUANTITY
  3969. }
  3970. else if(gunType[gun_index] == GUN_TYPE_DO)
  3971. {
  3972. tempIndex = gun_index;
  3973. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3974. {
  3975. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3976. {
  3977. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3978. }
  3979. }// END OF GB_QUANTITY
  3980. }
  3981. else
  3982. {
  3983. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3984. {
  3985. tempIndex = 2;
  3986. }
  3987. else
  3988. {
  3989. tempIndex = gun_index;
  3990. }
  3991. for (int index = 0; index < AC_QUANTITY; index++)
  3992. {
  3993. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3994. {
  3995. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3996. }
  3997. }// END OF AC_QUANTITY
  3998. }
  3999. //====================================== Stop Transaction Time =====================================================
  4000. struct timeval tmnow;
  4001. struct tm *tm;
  4002. char buf[28];//, usec_buf[6];
  4003. gettimeofday(&tmnow, NULL);
  4004. time_t t;
  4005. t = time(NULL);
  4006. /*UTC time and date*/
  4007. tm = gmtime(&t);
  4008. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4009. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  4010. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  4011. random_uuid(guid);
  4012. /***********************************transactionData******************************************************/
  4013. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  4014. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  4015. //=================================
  4016. // Transaction_Begin
  4017. //=================================
  4018. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4019. {
  4020. //============================================ Energy.Active.Import.Interval ================================
  4021. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  4022. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4023. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  4024. 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*/]);
  4025. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4026. 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))
  4027. {
  4028. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  4029. }
  4030. else
  4031. {
  4032. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  4033. }
  4034. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  4035. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4036. }
  4037. //=================================
  4038. // Transaction_End
  4039. //=================================
  4040. // ================================= Current.Import L1 ===============================================
  4041. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4042. {
  4043. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  4044. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4045. {
  4046. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4047. {
  4048. tempIndex = ((gun_index==2) ? 1: 0);
  4049. }
  4050. else
  4051. {
  4052. tempIndex = gun_index;
  4053. }
  4054. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4055. {
  4056. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4057. {
  4058. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4059. }
  4060. }// End of for CHAdeMO_QUANTITY
  4061. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4062. }
  4063. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4064. {
  4065. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4066. {
  4067. tempIndex = ((gun_index==2) ? 1: 0);
  4068. }
  4069. else
  4070. {
  4071. tempIndex = gun_index;
  4072. }
  4073. for (int index = 0; index < CCS_QUANTITY; index++)
  4074. {
  4075. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4076. {
  4077. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4078. }
  4079. }// End of for CCS_QUANTITY
  4080. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4081. }
  4082. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4083. {
  4084. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4085. {
  4086. tempIndex = ((gun_index==2) ? 1: 0);
  4087. }
  4088. else
  4089. {
  4090. tempIndex = gun_index;
  4091. }
  4092. for (int index = 0; index < GB_QUANTITY; index++)
  4093. {
  4094. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4095. {
  4096. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4097. }
  4098. }// End of for GB_QUANTITY
  4099. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4100. }
  4101. else if(gunType[gun_index] == GUN_TYPE_DO)
  4102. {
  4103. tempIndex = gun_index;
  4104. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4105. {
  4106. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4107. {
  4108. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4109. }
  4110. }
  4111. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4112. }
  4113. else
  4114. {
  4115. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4116. {
  4117. tempIndex = 2;
  4118. }
  4119. else
  4120. {
  4121. tempIndex = gun_index;
  4122. }
  4123. for (int index = 0; index < AC_QUANTITY; index++)
  4124. {
  4125. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4126. {
  4127. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  4128. }
  4129. }// End of for AC_QUANTITY
  4130. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  4131. }
  4132. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4133. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  4134. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  4135. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  4136. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4137. }
  4138. // ================================= Energy.Active.Import.Interval ==============================================
  4139. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4140. {
  4141. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4142. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4143. {
  4144. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4145. {
  4146. tempIndex = ((gun_index==2) ? 1: 0);
  4147. }
  4148. else
  4149. {
  4150. tempIndex = gun_index;
  4151. }
  4152. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4153. {
  4154. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4155. {
  4156. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4157. }
  4158. }// END OF CHAdeMO_QUANTITY
  4159. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4160. }
  4161. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4162. {
  4163. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4164. {
  4165. tempIndex = ((gun_index==2) ? 1: 0);
  4166. }
  4167. else
  4168. {
  4169. tempIndex = gun_index;
  4170. }
  4171. for (int index = 0; index < CCS_QUANTITY; index++)
  4172. {
  4173. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4174. {
  4175. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4176. }
  4177. }// END OF CCS_QUANTITY
  4178. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4179. }
  4180. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4181. {
  4182. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4183. {
  4184. tempIndex = ((gun_index==2) ? 1: 0);
  4185. }
  4186. else
  4187. {
  4188. tempIndex = gun_index;
  4189. }
  4190. for (int index = 0; index < GB_QUANTITY; index++)
  4191. {
  4192. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4193. {
  4194. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4195. }
  4196. }// END OF GB_QUANTITY
  4197. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4198. }
  4199. else if(gunType[gun_index] == GUN_TYPE_DO)
  4200. {
  4201. tempIndex = gun_index;
  4202. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4203. {
  4204. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4205. {
  4206. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4207. }
  4208. }
  4209. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4210. }
  4211. else
  4212. {
  4213. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4214. {
  4215. tempIndex = 2;
  4216. }
  4217. else
  4218. {
  4219. tempIndex = gun_index;
  4220. }
  4221. for (int index = 0; index < AC_QUANTITY; index++)
  4222. {
  4223. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4224. {
  4225. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4226. }
  4227. }// END OF AC_QUANTITY
  4228. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  4229. }
  4230. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4231. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  4232. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  4233. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  4234. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4235. }
  4236. //=================================== Power.Active.Import ==================================================
  4237. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  4238. {
  4239. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4240. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4241. {
  4242. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4243. {
  4244. tempIndex = ((gun_index==2) ? 1: 0);
  4245. }
  4246. else
  4247. {
  4248. tempIndex = gun_index;
  4249. }
  4250. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4251. {
  4252. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4253. {
  4254. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4255. }
  4256. } // End for CHAdeMO_QUANTITY
  4257. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4258. }
  4259. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4260. {
  4261. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4262. {
  4263. tempIndex = ((gun_index==2) ? 1: 0);
  4264. }
  4265. else
  4266. {
  4267. tempIndex = gun_index;
  4268. }
  4269. for (int index = 0; index < CCS_QUANTITY; index++)
  4270. {
  4271. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4272. {
  4273. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4274. }
  4275. } // END for CCS_QUANTITY
  4276. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4277. }
  4278. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4279. {
  4280. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4281. {
  4282. tempIndex = ((gun_index==2) ? 1: 0);
  4283. }
  4284. else
  4285. {
  4286. tempIndex = gun_index;
  4287. }
  4288. for (int index = 0; index < GB_QUANTITY; index++)
  4289. {
  4290. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4291. {
  4292. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4293. }
  4294. }// END for GB_QUANTITY
  4295. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4296. }
  4297. else if(gunType[gun_index] == GUN_TYPE_DO)
  4298. {
  4299. tempIndex = gun_index;
  4300. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4301. {
  4302. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4303. {
  4304. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4305. }
  4306. }
  4307. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4308. }
  4309. else
  4310. {
  4311. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4312. {
  4313. tempIndex = 2;
  4314. }
  4315. else
  4316. {
  4317. tempIndex = gun_index;
  4318. }
  4319. for (int index = 0; index < AC_QUANTITY; index++)
  4320. {
  4321. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4322. {
  4323. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4324. }
  4325. } // END for AC_QUANTITY
  4326. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  4327. }
  4328. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4329. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  4330. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  4331. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  4332. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  4333. }
  4334. //============================ Voltage L1 ====================================
  4335. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4336. {
  4337. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4338. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4339. {
  4340. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4341. {
  4342. tempIndex = ((gun_index==2) ? 1: 0);
  4343. }
  4344. else
  4345. {
  4346. tempIndex = gun_index;
  4347. }
  4348. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4349. {
  4350. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4351. {
  4352. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4353. }
  4354. } // END OF FOR CHAdeMO_QUANTITY
  4355. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4356. }
  4357. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4358. {
  4359. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4360. {
  4361. tempIndex = ((gun_index==2) ? 1: 0);
  4362. }
  4363. else
  4364. {
  4365. tempIndex = gun_index;
  4366. }
  4367. for (int index = 0; index < CCS_QUANTITY; index++)
  4368. {
  4369. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4370. {
  4371. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4372. }
  4373. } // END OF FOR CCS_QUANTITY
  4374. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4375. }
  4376. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4377. {
  4378. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4379. {
  4380. tempIndex = ((gun_index==2) ? 1: 0);
  4381. }
  4382. else
  4383. {
  4384. tempIndex = gun_index;
  4385. }
  4386. for (int index = 0; index < GB_QUANTITY; index++)
  4387. {
  4388. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4389. {
  4390. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4391. }
  4392. } // END OF FOR GB_QUANTITY
  4393. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4394. }
  4395. else if(gunType[gun_index] == GUN_TYPE_DO)
  4396. {
  4397. tempIndex = gun_index;
  4398. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4399. {
  4400. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4401. {
  4402. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4403. }
  4404. }
  4405. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4406. }
  4407. else
  4408. {
  4409. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4410. {
  4411. tempIndex = 2;
  4412. }
  4413. else
  4414. {
  4415. tempIndex = gun_index;
  4416. }
  4417. for (int index = 0; index < AC_QUANTITY; index++)
  4418. {
  4419. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4420. {
  4421. 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
  4422. }
  4423. } // END OF FOR AC_QUANTITY
  4424. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  4425. }
  4426. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4427. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  4428. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  4429. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  4430. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4431. }
  4432. //====================== End SoC ================================
  4433. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4434. {
  4435. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4436. 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))
  4437. {
  4438. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4439. {
  4440. tempIndex = ((gun_index==2) ? 1: 0);
  4441. }
  4442. else
  4443. {
  4444. tempIndex = gun_index;
  4445. }
  4446. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4447. {
  4448. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4449. {
  4450. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4451. {
  4452. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  4453. }
  4454. }
  4455. }
  4456. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4457. {
  4458. for (int index = 0; index < CCS_QUANTITY; index++)
  4459. {
  4460. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4461. {
  4462. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  4463. }
  4464. }
  4465. }
  4466. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4467. {
  4468. for (int index = 0; index < GB_QUANTITY; index++)
  4469. {
  4470. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4471. {
  4472. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  4473. }
  4474. }
  4475. }
  4476. else if(gunType[gun_index] == GUN_TYPE_DO)
  4477. {
  4478. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4479. {
  4480. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4481. {
  4482. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  4483. }
  4484. }
  4485. }
  4486. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4487. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  4488. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4489. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  4490. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  4491. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4492. } // END FOR DC CASE
  4493. }
  4494. // ================================= Current.Import L2 ===============================================
  4495. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4496. {
  4497. // AC 3 phse L2 current
  4498. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4499. {
  4500. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4501. {
  4502. tempIndex = 2;
  4503. }
  4504. else
  4505. {
  4506. tempIndex = gun_index;
  4507. }
  4508. for (int index = 0; index < AC_QUANTITY; index++)
  4509. {
  4510. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4511. {
  4512. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  4513. }
  4514. }// End of for AC_QUANTITY
  4515. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  4516. }
  4517. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4518. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  4519. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  4520. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  4521. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4522. }
  4523. // ================================= Current.Import L3 ===============================================
  4524. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4525. {
  4526. // AC 3 phse L3 current
  4527. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4528. {
  4529. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4530. {
  4531. tempIndex = 2;
  4532. }
  4533. else
  4534. {
  4535. tempIndex = gun_index;
  4536. }
  4537. for (int index = 0; index < AC_QUANTITY; index++)
  4538. {
  4539. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4540. {
  4541. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  4542. }
  4543. }// End of for AC_QUANTITY
  4544. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  4545. }
  4546. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4547. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  4548. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  4549. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  4550. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4551. }
  4552. //============================ Voltage L2 ====================================
  4553. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4554. {
  4555. // AC 3 phse L2 voltage
  4556. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4557. {
  4558. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4559. {
  4560. tempIndex = 2;
  4561. }
  4562. else
  4563. {
  4564. tempIndex = gun_index;
  4565. }
  4566. for (int index = 0; index < AC_QUANTITY; index++)
  4567. {
  4568. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4569. {
  4570. 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
  4571. }
  4572. } // END OF FOR AC_QUANTITY
  4573. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  4574. }
  4575. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4576. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  4577. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  4578. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  4579. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4580. }
  4581. //============================ Voltage L3 ====================================
  4582. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4583. {
  4584. // AC 3 phse L3 voltage
  4585. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4586. {
  4587. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4588. {
  4589. tempIndex = 2;
  4590. }
  4591. else
  4592. {
  4593. tempIndex = gun_index;
  4594. }
  4595. for (int index = 0; index < AC_QUANTITY; index++)
  4596. {
  4597. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4598. {
  4599. 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
  4600. }
  4601. } // END OF FOR AC_QUANTITY
  4602. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  4603. }
  4604. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4605. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  4606. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  4607. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  4608. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4609. }
  4610. //====================== Start SoC ================================
  4611. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4612. {
  4613. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4614. 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))
  4615. {
  4616. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4617. {
  4618. tempIndex = ((gun_index==2) ? 1: 0);
  4619. }
  4620. else
  4621. {
  4622. tempIndex = gun_index;
  4623. }
  4624. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4625. {
  4626. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4627. {
  4628. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4629. {
  4630. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  4631. }
  4632. }
  4633. }
  4634. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4635. {
  4636. for (int index = 0; index < CCS_QUANTITY; index++)
  4637. {
  4638. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4639. {
  4640. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  4641. }
  4642. }
  4643. }
  4644. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4645. {
  4646. for (int index = 0; index < GB_QUANTITY; index++)
  4647. {
  4648. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4649. {
  4650. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  4651. }
  4652. }
  4653. }
  4654. else if(gunType[gun_index] == GUN_TYPE_DO)
  4655. {
  4656. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4657. {
  4658. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4659. {
  4660. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  4661. }
  4662. }
  4663. }
  4664. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4665. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  4666. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4667. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  4668. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  4669. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4670. } // END FOR DC CASE
  4671. }
  4672. //================================================ Message create ====================================================
  4673. json_object *StopTransaction = json_object_new_object();
  4674. json_object *transactionDatas = json_object_new_array();
  4675. json_object *sampledValues = json_object_new_array();
  4676. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  4677. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  4678. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  4679. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  4680. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  4681. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  4682. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  4683. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  4684. {
  4685. json_object *transactionData = json_object_new_object();
  4686. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  4687. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  4688. {
  4689. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  4690. {
  4691. json_object *sampledValue = json_object_new_object();
  4692. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  4693. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  4694. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  4695. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  4696. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  4697. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  4698. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  4699. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  4700. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  4701. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  4702. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  4703. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  4704. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  4705. json_object_array_add(sampledValues, sampledValue);
  4706. }
  4707. }
  4708. json_object_object_add(transactionData, "sampledValue", sampledValues);
  4709. json_object_array_add(transactionDatas, transactionData);
  4710. }
  4711. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  4712. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  4713. ,MESSAGE_TYPE_CALL
  4714. ,guid
  4715. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  4716. json_object_put(StopTransaction);
  4717. #if 1 // for TempStopTransaction
  4718. //Delete TempStopTransaction
  4719. if((access(TempStopTransaction,F_OK))!=-1)
  4720. {
  4721. remove(TempStopTransaction); // remove file "TempStopTransaction"
  4722. }
  4723. #endif
  4724. #if 1
  4725. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4726. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4727. {
  4728. result = PASS;
  4729. //DEBUG_INFO("StopTransaction mapitem pass\n");
  4730. }
  4731. #endif
  4732. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4733. OCPP_insert_transaction_msg(NO, queuedata);
  4734. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4735. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4736. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  4737. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4738. {
  4739. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4740. }
  4741. //for test
  4742. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4743. return result;
  4744. }
  4745. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4746. {
  4747. mtrace();
  4748. int result = FAIL;
  4749. char guid[37]={0};
  4750. char tempdata[65]={0};
  4751. int tempIndex = 0;
  4752. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4753. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4754. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  4755. //set value
  4756. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4757. 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) )?
  4758. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  4759. -1);
  4760. random_uuid(guid);
  4761. //UTC Date time
  4762. struct timeval tmnow;
  4763. struct tm *tm;
  4764. char buf[28];//, usec_buf[6];
  4765. gettimeofday(&tmnow, NULL);
  4766. time_t t;
  4767. t = time(NULL);
  4768. /*UTC time and date*/
  4769. tm = gmtime(&t);
  4770. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4771. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4772. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4773. //********************************(1)Current.Import L1************************************************/
  4774. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  4775. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  4776. (dataType == ReadingContext_Trigger))
  4777. {
  4778. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4779. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4780. {
  4781. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4782. {
  4783. tempIndex = ((gun_index==2) ? 1: 0);
  4784. }
  4785. else
  4786. {
  4787. tempIndex = gun_index;
  4788. }
  4789. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4790. {
  4791. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4792. {
  4793. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4794. }
  4795. }
  4796. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4797. }
  4798. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4799. {
  4800. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4801. {
  4802. tempIndex = ((gun_index==2) ? 1: 0);
  4803. }
  4804. else
  4805. {
  4806. tempIndex = gun_index;
  4807. }
  4808. for (int index = 0; index < CCS_QUANTITY; index++)
  4809. {
  4810. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4811. {
  4812. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4813. }
  4814. }
  4815. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4816. }
  4817. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4818. {
  4819. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4820. {
  4821. tempIndex = ((gun_index==2) ? 1: 0);
  4822. }
  4823. else
  4824. {
  4825. tempIndex = gun_index;
  4826. }
  4827. for (int index = 0; index < GB_QUANTITY; index++)
  4828. {
  4829. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4830. {
  4831. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4832. }
  4833. }
  4834. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4835. }
  4836. else if(gunType[gun_index] == GUN_TYPE_DO)
  4837. {
  4838. tempIndex = gun_index;
  4839. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4840. {
  4841. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4842. {
  4843. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  4844. }
  4845. }
  4846. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4847. }
  4848. else
  4849. {
  4850. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4851. {
  4852. tempIndex = 2;
  4853. }
  4854. else
  4855. {
  4856. tempIndex = gun_index;
  4857. }
  4858. for (int index = 0; index < AC_QUANTITY; index++)
  4859. {
  4860. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4861. {
  4862. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4863. }
  4864. }
  4865. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4866. }
  4867. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4868. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4869. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4870. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4871. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4872. }
  4873. //********************************(2)Energy.Active.Import.Register ************************************************/
  4874. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4875. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4876. (dataType == ReadingContext_Trigger))
  4877. {
  4878. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4879. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4880. {
  4881. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4882. {
  4883. tempIndex = ((gun_index==2) ? 1: 0);
  4884. }
  4885. else
  4886. {
  4887. tempIndex = gun_index;
  4888. }
  4889. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4890. {
  4891. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4892. {
  4893. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4894. }
  4895. }
  4896. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4897. }
  4898. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4899. {
  4900. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4901. {
  4902. tempIndex = ((gun_index==2) ? 1: 0);
  4903. }
  4904. else
  4905. {
  4906. tempIndex = gun_index;
  4907. }
  4908. for (int index = 0; index < CCS_QUANTITY; index++)
  4909. {
  4910. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4911. {
  4912. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4913. }
  4914. }
  4915. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4916. }
  4917. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4918. {
  4919. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4920. {
  4921. tempIndex = ((gun_index==2) ? 1: 0);
  4922. }
  4923. else
  4924. {
  4925. tempIndex = gun_index;
  4926. }
  4927. for (int index = 0; index < GB_QUANTITY; index++)
  4928. {
  4929. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4930. {
  4931. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4932. }
  4933. }
  4934. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4935. }
  4936. else if(gunType[gun_index] == GUN_TYPE_DO)
  4937. {
  4938. tempIndex = gun_index;
  4939. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4940. {
  4941. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4942. {
  4943. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  4944. }
  4945. }
  4946. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4947. }
  4948. else
  4949. {
  4950. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4951. {
  4952. tempIndex = 2;
  4953. }
  4954. else
  4955. {
  4956. tempIndex = gun_index;
  4957. }
  4958. for (int index = 0; index < AC_QUANTITY; index++)
  4959. {
  4960. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4961. {
  4962. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4963. }
  4964. }
  4965. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4966. }
  4967. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  4968. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4969. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4970. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4971. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4972. }
  4973. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  4974. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  4975. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  4976. (dataType == ReadingContext_Trigger))
  4977. {
  4978. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4979. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4980. {
  4981. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4982. {
  4983. tempIndex = ((gun_index==2) ? 1: 0);
  4984. }
  4985. else
  4986. {
  4987. tempIndex = gun_index;
  4988. }
  4989. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4990. {
  4991. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4992. {
  4993. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4994. }
  4995. } // END OF FOR CHAdeMO_QUANTITY
  4996. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4997. }
  4998. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4999. {
  5000. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5001. {
  5002. tempIndex = ((gun_index==2) ? 1: 0);
  5003. }
  5004. else
  5005. {
  5006. tempIndex = gun_index;
  5007. }
  5008. for (int index = 0; index < CCS_QUANTITY; index++)
  5009. {
  5010. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5011. {
  5012. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  5013. }
  5014. } // END OF CCS_QUANTITY
  5015. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5016. }
  5017. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5018. {
  5019. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5020. {
  5021. tempIndex = ((gun_index==2) ? 1: 0);
  5022. }
  5023. else
  5024. {
  5025. tempIndex = gun_index;
  5026. }
  5027. for (int index = 0; index < GB_QUANTITY; index++)
  5028. {
  5029. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5030. {
  5031. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  5032. }
  5033. } // END OF GB_QUANTITY
  5034. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5035. }
  5036. else if(gunType[gun_index] == GUN_TYPE_DO)
  5037. {
  5038. tempIndex = gun_index;
  5039. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5040. {
  5041. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5042. {
  5043. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  5044. }
  5045. }
  5046. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5047. }
  5048. else
  5049. {
  5050. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5051. {
  5052. tempIndex = 2;
  5053. }
  5054. else
  5055. {
  5056. tempIndex = gun_index;
  5057. }
  5058. for (int index = 0; index < AC_QUANTITY; index++)
  5059. {
  5060. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5061. {
  5062. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  5063. }
  5064. }
  5065. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  5066. }
  5067. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  5068. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  5069. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  5070. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  5071. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5072. }
  5073. //********************************(4)Power.Active.Import************************************************/
  5074. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Power.Active.Import") != NULL)) ||
  5075. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Power.Active.Import") != NULL)) ||
  5076. (dataType == ReadingContext_Trigger))
  5077. {
  5078. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5079. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5080. {
  5081. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5082. {
  5083. tempIndex = ((gun_index==2) ? 1: 0);
  5084. }
  5085. else
  5086. {
  5087. tempIndex = gun_index;
  5088. }
  5089. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5090. {
  5091. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5092. {
  5093. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  5094. }
  5095. } // END OF FOR
  5096. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5097. }
  5098. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5099. {
  5100. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5101. {
  5102. tempIndex = ((gun_index==2) ? 1: 0);
  5103. }
  5104. else
  5105. {
  5106. tempIndex = gun_index;
  5107. }
  5108. for (int index = 0; index < CCS_QUANTITY; index++)
  5109. {
  5110. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5111. {
  5112. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  5113. }
  5114. }
  5115. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5116. }
  5117. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5118. {
  5119. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5120. {
  5121. tempIndex = ((gun_index==2) ? 1: 0);
  5122. }
  5123. else
  5124. {
  5125. tempIndex = gun_index;
  5126. }
  5127. for (int index = 0; index < GB_QUANTITY; index++)
  5128. {
  5129. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5130. {
  5131. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5132. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  5133. }
  5134. }
  5135. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5136. }
  5137. else if(gunType[gun_index] == GUN_TYPE_DO)
  5138. {
  5139. tempIndex = gun_index;
  5140. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5141. {
  5142. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5143. {
  5144. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5145. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  5146. }
  5147. }
  5148. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5149. }
  5150. else
  5151. {
  5152. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5153. {
  5154. tempIndex = 2;
  5155. }
  5156. else
  5157. {
  5158. tempIndex = gun_index;
  5159. }
  5160. for (int index = 0; index < AC_QUANTITY; index++)
  5161. {
  5162. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5163. {
  5164. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  5165. }
  5166. }
  5167. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  5168. }
  5169. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  5170. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  5171. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  5172. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  5173. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  5174. }
  5175. //***********************************************(5)VOLTAGE L1******************************************************/
  5176. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5177. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5178. (dataType == ReadingContext_Trigger))
  5179. {
  5180. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5181. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5182. {
  5183. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5184. {
  5185. tempIndex = ((gun_index==2) ? 1: 0);
  5186. }
  5187. else
  5188. {
  5189. tempIndex = gun_index;
  5190. }
  5191. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5192. {
  5193. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5194. {
  5195. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  5196. }
  5197. }
  5198. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5199. }
  5200. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5201. {
  5202. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5203. {
  5204. tempIndex = ((gun_index==2) ? 1: 0);
  5205. }
  5206. else
  5207. {
  5208. tempIndex = gun_index;
  5209. }
  5210. for (int index = 0; index < CCS_QUANTITY; index++)
  5211. {
  5212. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5213. {
  5214. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  5215. }
  5216. }
  5217. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5218. }
  5219. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5220. {
  5221. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5222. {
  5223. tempIndex = ((gun_index==2) ? 1: 0);
  5224. }
  5225. else
  5226. {
  5227. tempIndex = gun_index;
  5228. }
  5229. for (int index = 0; index < GB_QUANTITY; index++)
  5230. {
  5231. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5232. {
  5233. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  5234. }
  5235. }
  5236. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5237. }
  5238. else if(gunType[gun_index] == GUN_TYPE_DO)
  5239. {
  5240. tempIndex = gun_index;
  5241. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5242. {
  5243. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5244. {
  5245. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  5246. }
  5247. }
  5248. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5249. }
  5250. else
  5251. {
  5252. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5253. {
  5254. tempIndex = 2;
  5255. }
  5256. else
  5257. {
  5258. tempIndex = gun_index;
  5259. }
  5260. for (int index = 0; index < AC_QUANTITY; index++)
  5261. {
  5262. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5263. {
  5264. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  5265. }
  5266. }
  5267. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  5268. }
  5269. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  5270. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  5271. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  5272. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  5273. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5274. }
  5275. //***********************************************(6)SOC******************************************************/
  5276. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "SOC") != NULL)) ||
  5277. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "SOC") != NULL)) ||
  5278. (dataType == ReadingContext_Trigger))
  5279. {
  5280. 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))
  5281. {
  5282. //idx_sample=5;
  5283. //sampledValue = NULL;
  5284. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5285. {
  5286. tempIndex = ((gun_index==2) ? 1: 0);
  5287. }
  5288. else
  5289. {
  5290. tempIndex = gun_index;
  5291. }
  5292. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5293. {
  5294. //tempIndex = ((gun_index==2) ? 1: 0);
  5295. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5296. {
  5297. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5298. {
  5299. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  5300. }
  5301. }
  5302. }
  5303. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5304. {
  5305. //tempIndex = ((gun_index==2) ? 1: 0);
  5306. for (int index = 0; index < CCS_QUANTITY; index++)
  5307. {
  5308. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5309. {
  5310. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  5311. }
  5312. }
  5313. }
  5314. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5315. {
  5316. //tempIndex = ((gun_index==2) ? 1: 0);
  5317. for (int index = 0; index < GB_QUANTITY; index++)
  5318. {
  5319. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5320. {
  5321. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  5322. }
  5323. }
  5324. }
  5325. else if(gunType[gun_index] == GUN_TYPE_DO)
  5326. {
  5327. //tempIndex = ((gun_index==2) ? 1: 0);
  5328. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5329. {
  5330. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5331. {
  5332. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  5333. }
  5334. }
  5335. }
  5336. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  5337. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  5338. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  5339. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  5340. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  5341. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  5342. }
  5343. }
  5344. //********************************(7)Current.Import L2************************************************/
  5345. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5346. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5347. (dataType == ReadingContext_Trigger))
  5348. {
  5349. // Only for AC 3 phase
  5350. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5351. {
  5352. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5353. {
  5354. tempIndex = 2;
  5355. }
  5356. else
  5357. {
  5358. tempIndex = gun_index;
  5359. }
  5360. for (int index = 0; index < AC_QUANTITY; index++)
  5361. {
  5362. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5363. {
  5364. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  5365. }
  5366. }
  5367. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  5368. }
  5369. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  5370. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  5371. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  5372. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  5373. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5374. }
  5375. //********************************(8)Current.Import L3************************************************/
  5376. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5377. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5378. (dataType == ReadingContext_Trigger))
  5379. {
  5380. // Only for AC 3 phase
  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[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  5396. }
  5397. }
  5398. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  5399. }
  5400. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  5401. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  5402. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  5403. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  5404. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5405. }
  5406. //***********************************************(9)VOLTAGE L2******************************************************/
  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[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  5426. }
  5427. }
  5428. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  5429. }
  5430. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  5431. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  5432. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  5433. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  5434. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5435. }
  5436. //***********************************************(10)VOLTAGE L3******************************************************/
  5437. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5438. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5439. (dataType == ReadingContext_Trigger))
  5440. {
  5441. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5442. {
  5443. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5444. {
  5445. tempIndex = 2;
  5446. }
  5447. else
  5448. {
  5449. tempIndex = gun_index;
  5450. }
  5451. for (int index = 0; index < AC_QUANTITY; index++)
  5452. {
  5453. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5454. {
  5455. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  5456. }
  5457. }
  5458. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  5459. }
  5460. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  5461. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  5462. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  5463. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  5464. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5465. }
  5466. // Message create ====================================================================================================
  5467. if(TRUE)
  5468. {
  5469. json_object *MeterValueReq = json_object_new_object();
  5470. json_object *MeterValues = json_object_new_array();
  5471. json_object *sampledValues = json_object_new_array();
  5472. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  5473. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  5474. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  5475. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  5476. {
  5477. json_object *MeterValue = json_object_new_object();
  5478. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  5479. {
  5480. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  5481. {
  5482. json_object *sampledValue = json_object_new_object();
  5483. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  5484. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  5485. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  5486. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  5487. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  5488. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  5489. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  5490. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  5491. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  5492. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  5493. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  5494. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  5495. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  5496. json_object_array_add(sampledValues, sampledValue);
  5497. }
  5498. }
  5499. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  5500. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  5501. json_object_array_add(MeterValues, MeterValue);
  5502. }
  5503. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  5504. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  5505. ,gun_index + 1
  5506. ,MESSAGE_TYPE_CALL
  5507. ,guid
  5508. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  5509. json_object_put(MeterValueReq);
  5510. }
  5511. // Put request guid to hash map
  5512. sprintf(tempdata, "MeterValues,%d", (gun_index));
  5513. 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*/)
  5514. {
  5515. result = PASS;
  5516. //DEBUG_INFO("MeterValues mapitem pass\n");
  5517. }
  5518. if((dataType != ReadingContext_Trigger) &&
  5519. (dataType != ReadingContext_Sample_Clock) &&
  5520. (ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1))
  5521. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  5522. else
  5523. {
  5524. if(FirstHeartBeat)
  5525. LWS_Send(queuedata +2);
  5526. }
  5527. return result;
  5528. }
  5529. int sendLogStatusNotificationRequest(char *status)
  5530. {
  5531. mtrace();
  5532. int result = PASS;
  5533. char message[4096]={0};
  5534. char guid[37]={0};
  5535. char tempdata[128]={0};
  5536. json_object *LogStatusNotification = json_object_new_object();
  5537. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  5538. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  5539. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  5540. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  5541. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  5542. random_uuid(guid);
  5543. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  5544. json_object_put(LogStatusNotification);
  5545. LWS_Send(message);
  5546. sprintf(tempdata, "LogStatusNotification,%d", 0);
  5547. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5548. {
  5549. result = PASS;
  5550. }
  5551. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  5552. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  5553. return result;
  5554. }
  5555. int sendSecurityEventNotificationRequest()
  5556. {
  5557. mtrace();
  5558. int result = PASS;
  5559. char message[4096]={0};
  5560. char guid[37]={0};
  5561. char tempdata[128]={0};
  5562. json_object *SecurityEventNotification = json_object_new_object();
  5563. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  5564. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  5565. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  5566. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  5567. random_uuid(guid);
  5568. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  5569. json_object_put(SecurityEventNotification);
  5570. LWS_Send(message);
  5571. sprintf(tempdata, "SecurityEventNotification,0");
  5572. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5573. {
  5574. result = PASS;
  5575. }
  5576. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  5577. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  5578. return result;
  5579. }
  5580. int sendSignCertificateRequest()
  5581. {
  5582. mtrace();
  5583. int result = PASS;
  5584. char message[4096]={0};
  5585. char guid[37]={0};
  5586. char tempdata[128]={0};
  5587. json_object *SignCertificate = json_object_new_object();
  5588. DEBUG_INFO("sendSignCertificateRequest...\n");
  5589. // Read csr file content
  5590. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  5591. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  5592. char *line = NULL;
  5593. size_t len = 0;
  5594. while(getline(&line, &len, fp) != -1)
  5595. {
  5596. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  5597. {
  5598. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  5599. }
  5600. }
  5601. fclose(fp);
  5602. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  5603. random_uuid(guid);
  5604. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  5605. json_object_put(SignCertificate);
  5606. LWS_Send(message);
  5607. sprintf(tempdata, "SignCertificate,0");
  5608. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5609. {
  5610. result = PASS;
  5611. }
  5612. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  5613. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  5614. return result;
  5615. }
  5616. int sendSignedFirmwareStatusNotificationRequest(char *status)
  5617. {
  5618. mtrace();
  5619. int result = PASS;
  5620. char message[110]={0};
  5621. char guid[37]={0};
  5622. char tempdata[65]={0};
  5623. json_object *FirmwareStatusNotification = json_object_new_object();
  5624. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  5625. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  5626. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  5627. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  5628. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  5629. random_uuid(guid);
  5630. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  5631. json_object_put(FirmwareStatusNotification);
  5632. LWS_Send(message);
  5633. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5634. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5635. {
  5636. result = PASS;
  5637. }
  5638. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  5639. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  5640. return result;
  5641. }
  5642. //==========================================
  5643. // send confirm routine
  5644. //==========================================
  5645. int sendCancelReservationConfirmation(char *uuid,char *payload)
  5646. {
  5647. mtrace();
  5648. int result = FAIL;
  5649. char message[100]={0};
  5650. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  5651. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5652. LWS_Send(message);
  5653. result = TRUE;
  5654. return result;
  5655. }
  5656. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  5657. {
  5658. mtrace();
  5659. int result = FAIL;
  5660. char message[100]={0};
  5661. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  5662. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5663. LWS_Send(message);
  5664. result = TRUE;
  5665. return result;
  5666. }
  5667. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  5668. {
  5669. mtrace();
  5670. int result = FAIL;
  5671. char message[100]={0};
  5672. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  5673. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5674. LWS_Send(message);
  5675. result = TRUE;
  5676. return result;
  5677. }
  5678. int sendClearCacheConfirmation(char *uuid,char *payload)
  5679. {
  5680. mtrace();
  5681. int result = FAIL;
  5682. char message[500]={0};
  5683. DEBUG_INFO("sendClearCacheConfirmation...\n");
  5684. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5685. LWS_Send(message);
  5686. return result;
  5687. }
  5688. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  5689. {
  5690. mtrace();
  5691. int result = FAIL;
  5692. char message[500]={0};
  5693. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  5694. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5695. LWS_Send(message);
  5696. return result;
  5697. }
  5698. int sendDataTransferConfirmation(char *uuid,char *payload)
  5699. {
  5700. mtrace();
  5701. char statusStr[20]={0};
  5702. char dataStr[10]={0};
  5703. char sstr[20]={0};
  5704. int c = 0;
  5705. char *loc;
  5706. int result = FAIL;
  5707. DEBUG_INFO("sendDataTransferConfirmation...\n");
  5708. /**********************status**************************/
  5709. loc = strstr(payload, "status");
  5710. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5711. c = 0;
  5712. while (loc[3+strlen("status")+c] != '\"')
  5713. {
  5714. sstr[c] = loc[3+strlen("status")+c];
  5715. c++;
  5716. }
  5717. sstr[c] = '\0';
  5718. strcpy(statusStr, sstr);
  5719. /**********************data**************************/
  5720. loc = strstr(payload, "data");
  5721. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5722. c = 0;
  5723. while (loc[3+strlen("data")+c] != '\"')
  5724. {
  5725. sstr[c] = loc[3+strlen("data")+c];
  5726. c++;
  5727. }
  5728. sstr[c] = '\0';
  5729. strcpy(dataStr, sstr);
  5730. return result;
  5731. }
  5732. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  5733. {
  5734. mtrace();
  5735. int result = FAIL;
  5736. char message[1000]={0};
  5737. int CompositeScheduleIndex = 0;
  5738. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  5739. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  5740. if(nPeriod == 0)
  5741. {
  5742. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  5743. {
  5744. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  5745. ,MESSAGE_TYPE_CALLRESULT
  5746. ,uuid
  5747. ,payload
  5748. ,connectorIdInt);
  5749. }
  5750. else
  5751. {
  5752. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  5753. ,MESSAGE_TYPE_CALLRESULT
  5754. ,uuid
  5755. ,payload
  5756. ,connectorIdInt
  5757. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5758. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5759. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5760. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  5761. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  5762. }
  5763. }
  5764. else
  5765. {
  5766. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  5767. ,MESSAGE_TYPE_CALLRESULT
  5768. ,uuid
  5769. ,payload
  5770. ,connectorIdInt
  5771. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5772. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5773. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5774. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  5775. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  5776. {
  5777. if (idx_sample == 0)
  5778. {
  5779. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5780. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5781. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5782. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5783. }
  5784. else
  5785. {
  5786. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5787. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5788. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5789. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5790. }
  5791. }
  5792. sprintf(message + strlen(message), "]}}]");
  5793. }
  5794. LWS_Send(message);
  5795. result = TRUE;
  5796. return result;
  5797. }
  5798. int sendGetConfigurationConfirmation(char *uuid)
  5799. {
  5800. mtrace();
  5801. int result = FAIL;
  5802. int MaxKeySupported = 0;
  5803. int sentConfigurationNumber= 0;
  5804. int sentunConfigurationNumber= 0;
  5805. char message[4000]={0};
  5806. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5807. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5808. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5809. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5810. ,MESSAGE_TYPE_CALLRESULT
  5811. ,uuid );
  5812. //configuration key
  5813. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5814. {
  5815. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5816. {
  5817. if (sentConfigurationNumber == 0)
  5818. {
  5819. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5820. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5821. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5822. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5823. }
  5824. else
  5825. {
  5826. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5827. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5828. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5829. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5830. }
  5831. sentConfigurationNumber = sentConfigurationNumber + 1;
  5832. }
  5833. }
  5834. sprintf(message + strlen(message), "]");
  5835. if(UnknownKeynum != 0)
  5836. {
  5837. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5838. //unkown key
  5839. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5840. {
  5841. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5842. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5843. if(sentunConfigurationNumber == 0)
  5844. {
  5845. sprintf(message + strlen(message), "\"%s\""
  5846. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5847. }
  5848. else
  5849. {
  5850. sprintf(message + strlen(message), ",\"%s\""
  5851. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5852. }
  5853. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5854. }
  5855. sprintf(message + strlen(message), "]");
  5856. }
  5857. sprintf(message + strlen(message), "}]");
  5858. LWS_Send(message);
  5859. return result;
  5860. }
  5861. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5862. {
  5863. mtrace();
  5864. int result = FAIL;
  5865. char message[400]={0};
  5866. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5867. if(strcmp(payload,"")==0)
  5868. {
  5869. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5870. }
  5871. else
  5872. {
  5873. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5874. }
  5875. LWS_Send(message);
  5876. result = TRUE;
  5877. return result;
  5878. }
  5879. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5880. {
  5881. mtrace();
  5882. int result = FAIL;
  5883. char message[80]={0};
  5884. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5885. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  5886. LWS_Send(message);
  5887. result = TRUE;
  5888. return result;
  5889. }
  5890. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5891. {
  5892. mtrace();
  5893. int result = FAIL;
  5894. char message[80]={0};
  5895. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5896. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5897. LWS_Send(message);
  5898. result = TRUE;
  5899. return result;
  5900. }
  5901. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5902. {
  5903. mtrace();
  5904. int result = FAIL;
  5905. char message[80]={0};
  5906. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5907. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5908. LWS_Send(message);
  5909. result = TRUE;
  5910. return result;
  5911. }
  5912. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5913. {
  5914. mtrace();
  5915. int result = FAIL;
  5916. char message[80]={0};
  5917. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5918. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5919. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5920. LWS_Send(message);
  5921. result = TRUE;
  5922. return result;
  5923. }
  5924. int sendResetConfirmation(char *uuid,char *payload)
  5925. {
  5926. mtrace();
  5927. int result = FAIL;
  5928. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  5929. char message[80]={0};
  5930. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  5931. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5932. LWS_Send(message);
  5933. result = TRUE;
  5934. return result;
  5935. }
  5936. int sendSendLocalListConfirmation(char *uuid,char *payload)
  5937. {
  5938. mtrace();
  5939. int result = FAIL;
  5940. char message[500]={0};
  5941. // [ 3, "1571284266109", { "status": "Accepted" } ]
  5942. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5943. LWS_Send(message);
  5944. result = TRUE;
  5945. return result;
  5946. }
  5947. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  5948. {
  5949. mtrace();
  5950. int result = FAIL;
  5951. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  5952. char message[80]={0};
  5953. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  5954. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5955. LWS_Send(message);
  5956. result = TRUE;
  5957. return result;
  5958. }
  5959. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  5960. {
  5961. mtrace();
  5962. int result = FAIL;
  5963. char message[80]={0};
  5964. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  5965. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5966. LWS_Send(message);
  5967. result = TRUE;
  5968. return result;
  5969. }
  5970. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  5971. {
  5972. mtrace();
  5973. int result = FAIL;
  5974. char message[80]={0};
  5975. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5976. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  5977. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5978. LWS_Send(message);
  5979. result = TRUE;
  5980. return result;
  5981. }
  5982. int sendUpdateFirmwareConfirmation(char *uuid)
  5983. {
  5984. mtrace();
  5985. int result = FAIL;
  5986. char message[60]={0};
  5987. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5988. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  5989. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5990. LWS_Send(message);
  5991. result = TRUE;
  5992. return result;
  5993. }
  5994. int sendCertificateSignedConfirmation(char *uuid)
  5995. {
  5996. mtrace();
  5997. int result = PASS;
  5998. char message[4096]={0};
  5999. json_object *CertificateSigned = json_object_new_object();
  6000. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  6001. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  6002. sprintf(message,"[%d,\"%s\",%s]"
  6003. ,MESSAGE_TYPE_CALLRESULT
  6004. ,uuid
  6005. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  6006. json_object_put(CertificateSigned);
  6007. LWS_Send(message);
  6008. return result;
  6009. }
  6010. int sendDeleteCertificateConfirmation(char *uuid)
  6011. {
  6012. mtrace();
  6013. int result = PASS;
  6014. char message[4096]={0};
  6015. json_object *DeleteCertificate = json_object_new_object();
  6016. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  6017. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  6018. sprintf(message,"[%d,\"%s\",%s]"
  6019. ,MESSAGE_TYPE_CALLRESULT
  6020. ,uuid
  6021. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  6022. json_object_put(DeleteCertificate);
  6023. LWS_Send(message);
  6024. return result;
  6025. }
  6026. int sendExtendedTriggerMessageConfirmation(char *uuid)
  6027. {
  6028. mtrace();
  6029. int result = PASS;
  6030. char message[4096]={0};
  6031. json_object *ExtendedTriggerMessage = json_object_new_object();
  6032. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  6033. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  6034. sprintf(message,"[%d,\"%s\",%s]"
  6035. ,MESSAGE_TYPE_CALLRESULT
  6036. ,uuid
  6037. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  6038. json_object_put(ExtendedTriggerMessage);
  6039. LWS_Send(message);
  6040. return result;
  6041. }
  6042. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  6043. {
  6044. mtrace();
  6045. int result = PASS;
  6046. char message[4096]={0};
  6047. json_object *GetInstalledCertificateIds = json_object_new_object();
  6048. json_object *certificateHashDataDatas = json_object_new_array();
  6049. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  6050. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  6051. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  6052. {
  6053. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  6054. {
  6055. json_object *certificateHashData = json_object_new_object();
  6056. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  6057. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  6058. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  6059. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  6060. json_object_array_add(certificateHashDataDatas, certificateHashData);
  6061. }
  6062. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  6063. }
  6064. else
  6065. {
  6066. json_object_put(certificateHashDataDatas);
  6067. }
  6068. sprintf(message,"[%d,\"%s\",%s]"
  6069. ,MESSAGE_TYPE_CALLRESULT
  6070. ,uuid
  6071. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  6072. json_object_put(GetInstalledCertificateIds);
  6073. LWS_Send(message);
  6074. return result;
  6075. }
  6076. int sendGetLogConfirmation(char *uuid)
  6077. {
  6078. mtrace();
  6079. int result = PASS;
  6080. char message[4096]={0};
  6081. json_object *GetLog = json_object_new_object();
  6082. DEBUG_INFO("sendGetLogConfirmation...\n");
  6083. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  6084. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  6085. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  6086. sprintf(message,"[%d,\"%s\",%s]"
  6087. ,MESSAGE_TYPE_CALLRESULT
  6088. ,uuid
  6089. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  6090. json_object_put(GetLog);
  6091. LWS_Send(message);
  6092. return result;
  6093. }
  6094. int sendInstallCertificateConfirmation(char *uuid)
  6095. {
  6096. mtrace();
  6097. int result = PASS;
  6098. char message[4096]={0};
  6099. json_object *InstallCertificate = json_object_new_object();
  6100. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  6101. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  6102. sprintf(message,"[%d,\"%s\",%s]"
  6103. ,MESSAGE_TYPE_CALLRESULT
  6104. ,uuid
  6105. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  6106. json_object_put(InstallCertificate);
  6107. LWS_Send(message);
  6108. return result;
  6109. }
  6110. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  6111. {
  6112. mtrace();
  6113. int result = PASS;
  6114. char message[4096]={0};
  6115. json_object *SignedUpdateFirmware = json_object_new_object();
  6116. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  6117. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  6118. sprintf(message,"[%d,\"%s\",%s]"
  6119. ,MESSAGE_TYPE_CALLRESULT
  6120. ,uuid
  6121. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  6122. json_object_put(SignedUpdateFirmware);
  6123. LWS_Send(message);
  6124. return result;
  6125. }
  6126. int sendUnknownConfirmation(char *uuid)
  6127. {
  6128. mtrace();
  6129. int result = PASS;
  6130. char message[256]={0};
  6131. DEBUG_INFO("sendUnknownConfirmation...\n");
  6132. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  6133. LWS_Send(message);
  6134. return result;
  6135. }
  6136. //==========================================
  6137. // Handle server request routine Start
  6138. //==========================================
  6139. int handleCancelReservationRequest(char *uuid, char *payload)
  6140. {
  6141. mtrace();
  6142. int result = FAIL;
  6143. int gunNO = 0;
  6144. int reservationIdInt = -1;
  6145. char comfirmstr[20];
  6146. DEBUG_INFO("handleCancelReservationRequest...\n");
  6147. json_object *CancelReservation;
  6148. CancelReservation = json_tokener_parse(payload);
  6149. if(!is_error(CancelReservation))
  6150. {
  6151. // Required data
  6152. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  6153. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  6154. }
  6155. json_object_put(CancelReservation);
  6156. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  6157. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6158. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  6159. if(reservationIdInt != -1)
  6160. {
  6161. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6162. //check Transaction active
  6163. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6164. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6165. {
  6166. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  6167. {
  6168. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6169. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6170. if(gunType[2] == GUN_TYPE_CHAdeMO)
  6171. {
  6172. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  6173. }
  6174. else
  6175. {
  6176. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  6177. }
  6178. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6179. goto end;
  6180. }
  6181. }
  6182. for (int index = 0; index < CCS_QUANTITY; index++)
  6183. {
  6184. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  6185. {
  6186. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6187. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6188. if(gunType[2] == GUN_TYPE_CCS)
  6189. {
  6190. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  6191. }
  6192. else
  6193. {
  6194. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  6195. }
  6196. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6197. goto end;
  6198. }
  6199. }
  6200. for (int index = 0; index < GB_QUANTITY; index++)
  6201. {
  6202. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  6203. {
  6204. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6205. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6206. if(gunType[2] == GUN_TYPE_GBT)
  6207. {
  6208. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  6209. }
  6210. else
  6211. {
  6212. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  6213. }
  6214. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6215. goto end;
  6216. }
  6217. }
  6218. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6219. {
  6220. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  6221. {
  6222. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6223. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6224. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  6225. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6226. goto end;
  6227. }
  6228. }
  6229. for (int index = 0; index < AC_QUANTITY; index++)
  6230. {
  6231. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  6232. {
  6233. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6234. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6235. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6236. {
  6237. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  6238. }
  6239. else
  6240. {
  6241. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  6242. }
  6243. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6244. goto end;
  6245. }
  6246. }
  6247. }
  6248. //The reservationId does NOT match the reservationId
  6249. sendCancelReservationConfirmation(uuid, comfirmstr);
  6250. end:
  6251. // Fill in ocpp packet uuid
  6252. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  6253. return result;
  6254. }
  6255. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  6256. {
  6257. mtrace();
  6258. int result = FAIL;
  6259. int gunIndex = 0;
  6260. char typeStr[16]={0};
  6261. char comfirmstr[20];
  6262. int specificId = FALSE;
  6263. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  6264. json_object *ChangeAvailability;
  6265. ChangeAvailability = json_tokener_parse(payload);
  6266. if(!is_error(ChangeAvailability))
  6267. {
  6268. // Required data
  6269. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  6270. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  6271. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  6272. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  6273. }
  6274. json_object_put(ChangeAvailability);
  6275. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6276. {
  6277. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  6278. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  6279. }
  6280. else if(gunIndex == 0)
  6281. {
  6282. for(int i=0; i < gunTotalNumber; i++)
  6283. {
  6284. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  6285. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  6286. }
  6287. }
  6288. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6289. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6290. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  6291. {
  6292. specificId = TRUE;
  6293. }
  6294. if(specificId == FALSE)
  6295. goto end;
  6296. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  6297. {
  6298. //----------------------gunIndex is 0 ------------------------------------------------//
  6299. if(gunIndex == 0)
  6300. {
  6301. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6302. {
  6303. for(int i=0; i < gunTotalNumber; i++)
  6304. {
  6305. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6306. {
  6307. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  6308. {
  6309. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6310. {
  6311. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6312. goto end;
  6313. }
  6314. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6315. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6316. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6317. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6318. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6319. {
  6320. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6321. goto end;
  6322. }
  6323. }
  6324. }//END FOR CHAdeMO_QUANTITY
  6325. for (int index = 0; index < CCS_QUANTITY; index++)
  6326. {
  6327. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  6328. {
  6329. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  6330. {
  6331. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6332. goto end;
  6333. }
  6334. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6335. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6336. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6337. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6338. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6339. {
  6340. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6341. goto end;
  6342. }
  6343. }
  6344. }//END FOR CCS_QUANTITY
  6345. for (int index = 0; index < GB_QUANTITY; index++)
  6346. {
  6347. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  6348. {
  6349. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6350. {
  6351. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6352. goto end;
  6353. }
  6354. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6355. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6356. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6357. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6358. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6359. {
  6360. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6361. goto end;
  6362. }
  6363. }
  6364. }// END FOR GB_QUANTITY
  6365. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6366. {
  6367. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  6368. {
  6369. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6370. {
  6371. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6372. goto end;
  6373. }
  6374. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6375. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6376. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6377. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6378. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6379. {
  6380. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6381. goto end;
  6382. }
  6383. }
  6384. }// END FOR GENERAL_GUN_QUANTITY
  6385. for (int index = 0; index < AC_QUANTITY; index++)
  6386. {
  6387. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  6388. {
  6389. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6390. {
  6391. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6392. goto end;
  6393. }
  6394. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6395. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6396. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6397. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6398. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6399. {
  6400. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6401. goto end;
  6402. }
  6403. }
  6404. }//END FOR AC_QUANTITY
  6405. }// END FOR gunTotalNumber
  6406. }
  6407. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6408. {
  6409. for(int i=0; i < gunTotalNumber; i++)
  6410. {
  6411. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6412. {
  6413. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6414. goto end;
  6415. }
  6416. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6417. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  6418. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  6419. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  6420. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6421. {
  6422. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6423. goto end;
  6424. }
  6425. }
  6426. }
  6427. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6428. goto end;
  6429. }
  6430. //----------------------gunIndex is not 0 ------------------------------------------------//
  6431. //check Transaction active
  6432. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6433. {
  6434. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  6435. {
  6436. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  6437. {
  6438. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6439. goto end;
  6440. }
  6441. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6442. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6443. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6444. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6445. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6446. {
  6447. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6448. goto end;
  6449. }
  6450. else
  6451. {
  6452. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  6453. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6454. goto end;
  6455. }
  6456. }
  6457. }//END FOR CHAdeMO_QUANTITY
  6458. for (int index = 0; index < CCS_QUANTITY; index++)
  6459. {
  6460. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  6461. {
  6462. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  6463. {
  6464. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6465. goto end;
  6466. }
  6467. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6468. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6469. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6470. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6471. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6472. {
  6473. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6474. goto end;
  6475. }
  6476. else
  6477. {
  6478. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  6479. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6480. goto end;
  6481. }
  6482. }
  6483. }//END FOR CCS_QUANTITY
  6484. for (int index = 0; index < GB_QUANTITY; index++)
  6485. {
  6486. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  6487. {
  6488. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6489. {
  6490. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6491. goto end;
  6492. }
  6493. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6494. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6495. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6496. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6497. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6498. {
  6499. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6500. goto end;
  6501. }
  6502. else
  6503. {
  6504. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  6505. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6506. goto end;
  6507. }
  6508. }
  6509. }// END FOR GB_QUANTITY
  6510. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6511. {
  6512. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  6513. {
  6514. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6515. {
  6516. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6517. goto end;
  6518. }
  6519. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6520. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6521. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6522. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6523. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6524. {
  6525. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6526. goto end;
  6527. }
  6528. else
  6529. {
  6530. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  6531. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6532. goto end;
  6533. }
  6534. }
  6535. }// END FOR GENERAL_GUN_QUANTITY
  6536. for (int index = 0; index < AC_QUANTITY; index++)
  6537. {
  6538. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  6539. {
  6540. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6541. {
  6542. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6543. goto end;
  6544. }
  6545. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6546. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6547. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6548. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6549. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6550. {
  6551. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6552. goto end;
  6553. }
  6554. else
  6555. {
  6556. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  6557. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6558. goto end;
  6559. }
  6560. }
  6561. }//END FOR AC_QUANTITY
  6562. }//END FOR AvailabilityTypeStr[Inoperative]
  6563. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  6564. {
  6565. //----------------------gunIndex is 0 ------------------------------------------------//
  6566. if(gunIndex == 0)
  6567. {
  6568. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6569. {
  6570. for(int i=0; i < gunTotalNumber; i++)
  6571. {
  6572. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6573. {
  6574. 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
  6575. {
  6576. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6577. goto end;
  6578. }
  6579. }//END FOR CHAdeMO_QUANTITY
  6580. for (int index = 0; index < CCS_QUANTITY; index++)
  6581. {
  6582. 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
  6583. {
  6584. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6585. goto end;
  6586. }
  6587. }//END FOR CCS_QUANTITY
  6588. for (int index = 0; index < GB_QUANTITY; index++)
  6589. {
  6590. 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
  6591. {
  6592. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6593. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6594. goto end;
  6595. }
  6596. }// END FOR GB_QUANTITY
  6597. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6598. {
  6599. 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
  6600. {
  6601. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6602. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6603. goto end;
  6604. }
  6605. }// END FOR GENERAL_GUN_QUANTITY
  6606. for (int index = 0; index < AC_QUANTITY; index++)
  6607. {
  6608. 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
  6609. {
  6610. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6611. goto end;
  6612. }
  6613. }//END FOR CHAdeMO_QUANTITY
  6614. }// END FOR gunTotalNumber
  6615. }
  6616. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6617. {
  6618. for(int i=0; i < gunTotalNumber; i++)
  6619. {
  6620. for (int index = 0; index < AC_QUANTITY; index++)
  6621. {
  6622. 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
  6623. {
  6624. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6625. goto end;
  6626. }
  6627. }//END FOR CHAdeMO_QUANTITY
  6628. } // END FOR gunTotalNumber
  6629. }
  6630. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6631. goto end;
  6632. }
  6633. //----------------------gunIndex is not 0 ------------------------------------------------//
  6634. //check Transaction active
  6635. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6636. {
  6637. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6638. {
  6639. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6640. goto end;
  6641. }
  6642. }//END FOR CHAdeMO_QUANTITY
  6643. for (int index = 0; index < CCS_QUANTITY; index++)
  6644. {
  6645. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6646. {
  6647. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6648. goto end;
  6649. }
  6650. }//END FOR CCS_QUANTITY
  6651. for (int index = 0; index < GB_QUANTITY; index++)
  6652. {
  6653. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6654. {
  6655. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6656. goto end;
  6657. }
  6658. }// END FOR GB_QUANTITY
  6659. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6660. {
  6661. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6662. {
  6663. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6664. goto end;
  6665. }
  6666. }// END FOR GENERAL_GUN_QUANTITY
  6667. for (int index = 0; index < AC_QUANTITY; index++)
  6668. {
  6669. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6670. {
  6671. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6672. goto end;
  6673. }
  6674. }//END FOR AC_QUANTITY
  6675. }//END FOR AvailabilityTypeStr[Operative]
  6676. end:
  6677. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6678. {
  6679. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  6680. }
  6681. else
  6682. {
  6683. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  6684. }
  6685. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6686. {
  6687. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6688. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6689. }
  6690. else if(gunIndex == 0)
  6691. {
  6692. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6693. {
  6694. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  6695. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  6696. }
  6697. }
  6698. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  6699. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6700. return result;
  6701. }
  6702. int handleChangeConfigurationRequest(char *uuid, char *payload)
  6703. {
  6704. mtrace();
  6705. int result = FAIL;
  6706. char keystr[40]={0};
  6707. char valuestr[256]={0};
  6708. char comfirmstr[20]={0};
  6709. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  6710. json_object *ChangeConfiguration;
  6711. ChangeConfiguration = json_tokener_parse(payload);
  6712. if(!is_error(ChangeConfiguration))
  6713. {
  6714. // Required data
  6715. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  6716. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  6717. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  6718. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  6719. }
  6720. json_object_put(ChangeConfiguration);
  6721. if((uuid==NULL) || (payload ==NULL) )
  6722. {
  6723. DEBUG_ERROR("Payload is null\n");
  6724. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6725. }
  6726. else
  6727. {
  6728. int status = setKeyValue(keystr, valuestr);
  6729. switch(status)
  6730. {
  6731. case ConfigurationStatus_Accepted:
  6732. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  6733. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  6734. StoreConfigurationTable();
  6735. break;
  6736. case RebootRequired:
  6737. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  6738. StoreConfigurationTable();
  6739. break;
  6740. case NotSupported:
  6741. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  6742. break;
  6743. case ConfigurationStatus_Rejected:
  6744. default:
  6745. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6746. break;
  6747. }
  6748. }
  6749. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  6750. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  6751. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6752. {
  6753. ChageWebSocketPingInterval(atoi(valuestr));
  6754. }
  6755. if((strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6756. {
  6757. SetOcppConnStatus(FALSE);
  6758. }
  6759. return result;
  6760. }
  6761. int handleClearCacheRequest(char *uuid, char *payload)
  6762. {
  6763. mtrace();
  6764. int result = FAIL;
  6765. char comfirmstr[20];
  6766. char rmFileCmd[100]={0};
  6767. struct stat stats;
  6768. DEBUG_INFO("handleClearCacheRequest...\n");
  6769. stat("/Storage/OCPP", &stats);
  6770. // Check for directory existence
  6771. if (S_ISDIR(stats.st_mode) == 1)
  6772. {}
  6773. else
  6774. {
  6775. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  6776. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  6777. system(rmFileCmd);
  6778. }
  6779. if(OCPP_cleanLocalCache())
  6780. {
  6781. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  6782. }
  6783. else
  6784. {
  6785. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  6786. }
  6787. sendClearCacheConfirmation(uuid, comfirmstr);
  6788. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6789. return result;
  6790. }
  6791. int handleClearChargingProfileRequest(char *uuid, char *payload)
  6792. {
  6793. mtrace();
  6794. int result = FAIL;
  6795. int resultRename;
  6796. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  6797. char chargingProfilePurposeStr[26]={0};
  6798. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  6799. char tempchargingProfilePurposeStr[26]={0};
  6800. char str[100]={0};
  6801. char fname[200]={0};
  6802. char comfirmstr[20]={0};
  6803. char word[1600]={0};
  6804. int clearflag = FALSE;
  6805. int chargingProfileIdIsNULL = FALSE;
  6806. int connectorIsNULL = FALSE;
  6807. int chargingProfilePurposeIsNULL = FALSE;
  6808. int stackLevelIsNULL = FALSE;
  6809. //int GotoEnd = FALSE;
  6810. FILE *fptr1, *fptr2;
  6811. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  6812. int n_chargingProfile=0;
  6813. int isEmptyFile = FALSE;
  6814. char sLineWord[1600]={0};
  6815. char chargingProfiles[10][100]={0};
  6816. int ChargeProfileCount = 0;
  6817. int ch;
  6818. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  6819. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  6820. json_object *ClearChargingProfile;
  6821. ClearChargingProfile = json_tokener_parse(payload);
  6822. if(!is_error(ClearChargingProfile))
  6823. {
  6824. // Optional data
  6825. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  6826. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  6827. else
  6828. chargingProfileIdIsNULL = TRUE;
  6829. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  6830. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  6831. else
  6832. connectorIsNULL = TRUE;
  6833. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  6834. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  6835. else
  6836. chargingProfilePurposeIsNULL = TRUE;
  6837. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  6838. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  6839. else
  6840. stackLevelIsNULL = TRUE;
  6841. }
  6842. json_object_put(ClearChargingProfile);
  6843. if(connectorIsNULL == FALSE)
  6844. {
  6845. switch(connectorIdInt)
  6846. {
  6847. case 0:
  6848. if(chargingProfilePurposeIsNULL == TRUE)
  6849. {
  6850. int l = 0;
  6851. strcpy(fname, ChargePointMaxProfile_JSON);
  6852. if((access(fname,F_OK))!=-1)
  6853. {
  6854. strcpy(chargingProfiles[l], fname);
  6855. l = l + 1;
  6856. }
  6857. strcpy(fname, TxDefaultProfile_0_JSON);
  6858. if((access(fname,F_OK))!=-1)
  6859. {
  6860. strcpy(chargingProfiles[l], fname);
  6861. l = l + 1;
  6862. }
  6863. ChargeProfileCount = l;
  6864. }
  6865. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  6866. {
  6867. strcpy(fname, ChargePointMaxProfile_JSON);
  6868. if((access(fname,F_OK))!=-1)
  6869. {
  6870. strcpy(chargingProfiles[0], fname);
  6871. ChargeProfileCount = 1;
  6872. }
  6873. }
  6874. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6875. {
  6876. strcpy(fname, TxDefaultProfile_0_JSON);
  6877. if((access(fname,F_OK))!=-1)
  6878. {
  6879. strcpy(chargingProfiles[0], fname);
  6880. ChargeProfileCount = 1;
  6881. }
  6882. }
  6883. break;
  6884. default:
  6885. if(chargingProfilePurposeIsNULL == TRUE)
  6886. {
  6887. int m = 0;
  6888. memset(fname, 0, ARRAY_SIZE(fname));
  6889. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6890. if((access(fname,F_OK))!=-1)
  6891. {
  6892. strcpy(chargingProfiles[m], fname);
  6893. m = m + 1;
  6894. }
  6895. memset(fname, 0, ARRAY_SIZE(fname));
  6896. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6897. if((access(fname,F_OK))!=-1)
  6898. {
  6899. strcpy(chargingProfiles[m], fname);
  6900. m = m + 1;
  6901. }
  6902. ChargeProfileCount = m;
  6903. }
  6904. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6905. {
  6906. //strcpy(fname, TxDefaultProfile_1_JSON);
  6907. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6908. if((access(fname,F_OK))!=-1)
  6909. {
  6910. strcpy(chargingProfiles[0], fname);
  6911. ChargeProfileCount = 1;
  6912. }
  6913. }
  6914. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  6915. {
  6916. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6917. if((access(fname,F_OK))!=-1)
  6918. {
  6919. strcpy(chargingProfiles[0], fname);
  6920. ChargeProfileCount = 1;
  6921. }
  6922. //strcpy(fname, TxProfile_1_JSON);
  6923. }
  6924. //strcpy(fname, ChargePointMaxProfile_JSON );
  6925. break;
  6926. }
  6927. }
  6928. else // Check all Charging Profiles
  6929. {
  6930. int i = 0;
  6931. char fnametemp[200]={0};
  6932. ChargeProfileCount = 0;
  6933. //Check ChargePointMaxProfile.json exit
  6934. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  6935. {
  6936. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  6937. i = i + 1;
  6938. }
  6939. //Check TxDefaultProfile_0.json exit
  6940. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  6941. {
  6942. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  6943. i = i + 1;
  6944. }
  6945. //Check TxDefaultProfile_%d.json
  6946. for(int j=1; j <= gunTotalNumber; j++)
  6947. {
  6948. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6949. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  6950. if((access(fnametemp,F_OK))!=-1)
  6951. {
  6952. strcpy(chargingProfiles[i], fnametemp);
  6953. i = i + 1;
  6954. }
  6955. }
  6956. //Check TxProfile_%d.json
  6957. for(int j=1; j <= gunTotalNumber; j++)
  6958. {
  6959. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6960. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  6961. if((access(fnametemp,F_OK))!=-1)
  6962. {
  6963. strcpy(chargingProfiles[i], fnametemp);
  6964. i = i + 1;
  6965. }
  6966. }
  6967. ChargeProfileCount = i;
  6968. }// End connectorIsNULL is TRUE
  6969. if(ChargeProfileCount == 0)
  6970. {
  6971. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6972. goto end;
  6973. }
  6974. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  6975. {
  6976. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6977. goto end;
  6978. }
  6979. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  6980. {
  6981. memset(str, 0, ARRAY_SIZE(str));
  6982. // clear temp file
  6983. sprintf(str,"rm -f %s",temp);
  6984. system(str);
  6985. for(int k=0; k < ChargeProfileCount; k++)
  6986. {
  6987. memset(str, 0, ARRAY_SIZE(str));
  6988. //clear file in C
  6989. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6990. system(str);
  6991. }
  6992. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6993. goto end;
  6994. }
  6995. else if(connectorIsNULL == TRUE)
  6996. {
  6997. for(int k=0; k < ChargeProfileCount; k++)
  6998. {
  6999. fptr1 = fopen(chargingProfiles[k], "r");
  7000. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  7001. //Check Charging Profile Count
  7002. while(fscanf(fptr1, "%s", word) != EOF)
  7003. {
  7004. //DEBUG_INFO("word=%s\n",word);
  7005. if(strstr(word, "chargingProfileId")!= NULL)
  7006. {
  7007. //DEBUG_INFO("test chargingProfileId \n");
  7008. n_chargingProfile = n_chargingProfile + 1;
  7009. //DEBUG_INFO("chargingProfileId Found\n");
  7010. }
  7011. }
  7012. rewind(fptr1);
  7013. //search Charging Profile Element
  7014. //int i= 0;
  7015. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7016. {
  7017. json_object *tmpProfilee;
  7018. tmpProfilee = json_tokener_parse(sLineWord);
  7019. if(!is_error(tmpProfilee))
  7020. {
  7021. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7022. {
  7023. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7024. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7025. }
  7026. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7027. {
  7028. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7029. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7030. }
  7031. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7032. {
  7033. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7034. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7035. }
  7036. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7037. {
  7038. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7039. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7040. }
  7041. }
  7042. json_object_put(tmpProfilee);
  7043. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7044. {
  7045. //------- not write to fptr2-------//
  7046. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7047. //clearflag = TRUE;
  7048. }
  7049. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7050. {
  7051. //------- not write to fptr2-------//
  7052. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7053. }
  7054. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7055. {
  7056. //------- not write to fptr2-------//
  7057. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7058. }
  7059. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  7060. {
  7061. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7062. }
  7063. else
  7064. {
  7065. fprintf(fptr2, sLineWord);//writing data into file
  7066. }
  7067. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7068. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7069. if(clearflag == TRUE)
  7070. {
  7071. fclose(fptr1);
  7072. fclose(fptr2);
  7073. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7074. system(str);
  7075. // clear temp file
  7076. sprintf(str,"rm -f %s",temp);
  7077. system(str);
  7078. }
  7079. else
  7080. {
  7081. fclose(fptr1);
  7082. fclose(fptr2);
  7083. memset(str, 0, ARRAY_SIZE(str));
  7084. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7085. system(str);
  7086. resultRename = rename(temp, chargingProfiles[k]);
  7087. if(resultRename == 0)
  7088. {
  7089. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  7090. }
  7091. else
  7092. {
  7093. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  7094. }
  7095. if(comfirmstr[0]== 0)
  7096. {
  7097. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7098. }
  7099. //Check chargingProfile is empty file
  7100. /*------ Read the file ----------------*/
  7101. fptr1=fopen(chargingProfiles[k],"r");
  7102. ch=fgetc(fptr1);
  7103. rewind(fptr1);
  7104. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7105. if(ch!=EOF)
  7106. {
  7107. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7108. {
  7109. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7110. if(sLineWord[0]=='\0')
  7111. {
  7112. isEmptyFile = TRUE;
  7113. break;
  7114. }
  7115. else
  7116. {
  7117. isEmptyFile = FALSE;
  7118. break;
  7119. }
  7120. }
  7121. }
  7122. else
  7123. isEmptyFile = TRUE;
  7124. fclose(fptr1);
  7125. if(isEmptyFile == TRUE)
  7126. {
  7127. memset(str, 0, ARRAY_SIZE(str));
  7128. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7129. system(str);
  7130. }
  7131. }
  7132. }// End of while(int k=0; k < ChargePointCount; k++)
  7133. }
  7134. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  7135. {
  7136. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  7137. for(int k=0; k < ChargeProfileCount; k++)
  7138. {
  7139. fptr1 = fopen(chargingProfiles[k], "r");
  7140. fptr2 = fopen(temp, "w+");
  7141. //Check Charging Profile Count
  7142. while(fscanf(fptr1, "%s", word) != EOF)
  7143. {
  7144. //DEBUG_INFO("word=%s\n",word);
  7145. if(strstr(word, "chargingProfileId")!= NULL)
  7146. {
  7147. n_chargingProfile = n_chargingProfile + 1;
  7148. }
  7149. }
  7150. rewind(fptr1);
  7151. //search Charging Profile Element
  7152. //int i= 0;
  7153. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7154. {
  7155. json_object *tmpProfilee;
  7156. tmpProfilee = json_tokener_parse(sLineWord);
  7157. if(!is_error(tmpProfilee))
  7158. {
  7159. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7160. {
  7161. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7162. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7163. }
  7164. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7165. {
  7166. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7167. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7168. }
  7169. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7170. {
  7171. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7172. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7173. }
  7174. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7175. {
  7176. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7177. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7178. }
  7179. }
  7180. json_object_put(tmpProfilee);
  7181. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7182. {
  7183. //------- not write to fptr2-------//
  7184. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7185. //clearflag = TRUE;
  7186. }
  7187. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7188. {
  7189. //------- not write to fptr2-------//
  7190. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7191. }
  7192. else if(stackLevelIsNULL == TRUE)
  7193. {
  7194. //Clear Whole File
  7195. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7196. clearflag = TRUE;
  7197. break;
  7198. }
  7199. else
  7200. {
  7201. fprintf(fptr2, sLineWord);//writing data into file
  7202. }
  7203. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7204. }
  7205. if(clearflag == TRUE)
  7206. {
  7207. fclose(fptr1);
  7208. fclose(fptr2);
  7209. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7210. system(str);
  7211. // clear temp file
  7212. sprintf(str,"rm -f %s",temp);
  7213. system(str);
  7214. }
  7215. else
  7216. {
  7217. fclose(fptr1);
  7218. fclose(fptr2);
  7219. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7220. system(str);
  7221. resultRename = rename(temp, chargingProfiles[k]);
  7222. if(resultRename == 0)
  7223. {
  7224. DEBUG_INFO("File ChargingProfile renamed successfully");
  7225. }
  7226. else
  7227. {
  7228. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  7229. }
  7230. if(comfirmstr[0]== 0)
  7231. {
  7232. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7233. }
  7234. //Check chargingProfile is empty file
  7235. /*------ Read the file ----------------*/
  7236. fptr1=fopen(chargingProfiles[k],"r");
  7237. ch=fgetc(fptr1);
  7238. rewind(fptr1);
  7239. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7240. if(ch!=EOF)
  7241. {
  7242. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7243. {
  7244. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7245. if(sLineWord[0]=='\0')
  7246. {
  7247. isEmptyFile = TRUE;
  7248. break;
  7249. }
  7250. else
  7251. {
  7252. isEmptyFile = FALSE;
  7253. break;
  7254. }
  7255. }
  7256. }
  7257. else
  7258. isEmptyFile = TRUE;
  7259. fclose(fptr1);
  7260. if(isEmptyFile == TRUE)
  7261. {
  7262. memset(str, 0, ARRAY_SIZE(str));
  7263. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7264. system(str);
  7265. }
  7266. /*------- End of reading ---------------*/
  7267. }
  7268. } // while(int k=0; k < ChargeProfileCount; k++)
  7269. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  7270. end:
  7271. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  7272. {
  7273. if(connectorIdInt == 0)
  7274. {
  7275. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  7276. {
  7277. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  7278. }
  7279. }
  7280. else
  7281. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  7282. }
  7283. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  7284. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7285. return result;
  7286. }
  7287. void createFirmwareVersionByDataTransfer(void)
  7288. {
  7289. json_object *FirmwareDataTransfer = json_object_new_object();
  7290. // AC & DC model
  7291. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  7292. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  7293. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  7294. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  7295. // DC model
  7296. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O')
  7297. {
  7298. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  7299. {
  7300. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7301. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7302. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  7303. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  7304. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7305. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7306. }
  7307. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  7308. ((gunType[1] != GUN_TYPE_UNKNOWN) || (gunType[2] != GUN_TYPE_UNKNOWN) || (gunType[3] != GUN_TYPE_UNKNOWN)))
  7309. {
  7310. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  7311. }
  7312. }
  7313. else
  7314. {
  7315. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7316. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7317. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7318. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7319. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  7320. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  7321. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  7322. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  7323. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  7324. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  7325. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  7326. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  7327. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  7328. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  7329. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  7330. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  7331. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  7332. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  7333. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  7334. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  7335. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  7336. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  7337. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  7338. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  7339. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  7340. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  7341. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  7342. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  7343. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  7344. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  7345. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  7346. }
  7347. // 4G model
  7348. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  7349. {
  7350. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  7351. }
  7352. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  7353. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  7354. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  7355. json_object_put(FirmwareDataTransfer);
  7356. }
  7357. int handleDataTransferRequest(char *uuid, char *payload)
  7358. {
  7359. mtrace();
  7360. json_object *response = json_object_new_object();
  7361. int result = FAIL;
  7362. char tempvendorId[255]={0};
  7363. char tempmessageId[50]={0};
  7364. char tempdata[512]={0};
  7365. char message[2048]={0};
  7366. DEBUG_INFO("handleDataTransferRequest...\n");
  7367. if((uuid != NULL) && (payload != NULL))
  7368. {
  7369. json_object *DataTransfer;
  7370. DataTransfer = json_tokener_parse(payload);
  7371. if(!is_error(DataTransfer))
  7372. {
  7373. // Required data
  7374. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  7375. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  7376. // Optional data
  7377. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  7378. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  7379. if(json_object_object_get(DataTransfer, "data") != NULL)
  7380. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  7381. result = PASS;
  7382. }
  7383. json_object_put(DataTransfer);
  7384. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  7385. {
  7386. // Send all moudle firmware version on EVSE
  7387. createFirmwareVersionByDataTransfer();
  7388. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7389. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  7390. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7391. json_object_put(response);
  7392. }
  7393. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  7394. {
  7395. system("/usr/bin/run_tmate_restart.sh &");
  7396. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7397. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7398. json_object_put(response);
  7399. }
  7400. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  7401. {
  7402. json_object *data;
  7403. data = json_tokener_parse(tempdata);
  7404. if(!is_error(data))
  7405. {
  7406. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  7407. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  7408. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  7409. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  7410. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  7411. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  7412. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  7413. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  7414. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  7415. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  7416. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7417. }
  7418. else
  7419. {
  7420. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7421. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7422. }
  7423. json_object_put(data);
  7424. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7425. json_object_put(response);
  7426. }
  7427. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  7428. {
  7429. json_object *data;
  7430. data = json_tokener_parse(tempdata);
  7431. if(!is_error(data))
  7432. {
  7433. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  7434. if(json_object_object_get(data, "idToken") != NULL)
  7435. {
  7436. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  7437. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  7438. }
  7439. if(json_object_object_get(data, "price") != NULL)
  7440. {
  7441. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  7442. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  7443. }
  7444. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7445. }
  7446. else
  7447. {
  7448. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7449. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7450. }
  7451. json_object_put(data);
  7452. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7453. json_object_put(response);
  7454. }
  7455. else if(strstr(tempmessageId, "RunningCost") != NULL)
  7456. {
  7457. json_object *data;
  7458. data = json_tokener_parse(tempdata);
  7459. if(!is_error(data))
  7460. {
  7461. if(json_object_object_get(data, "txId") != NULL)
  7462. {
  7463. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7464. for(int idx = 0;idx<gunTotalNumber;idx++)
  7465. {
  7466. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7467. {
  7468. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  7469. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7470. if(json_object_object_get(data, "description") != NULL)
  7471. {
  7472. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7473. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7474. }
  7475. }
  7476. }
  7477. }
  7478. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7479. }
  7480. else
  7481. {
  7482. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7483. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7484. }
  7485. json_object_put(data);
  7486. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7487. json_object_put(response);
  7488. }
  7489. else if(strstr(tempmessageId, "FinalCost") != NULL)
  7490. {
  7491. json_object *data;
  7492. data = json_tokener_parse(tempdata);
  7493. if(!is_error(data))
  7494. {
  7495. if(json_object_object_get(data, "txId") != NULL)
  7496. {
  7497. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7498. for(int idx = 0;idx<gunTotalNumber;idx++)
  7499. {
  7500. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7501. {
  7502. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  7503. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7504. if(json_object_object_get(data, "description") != NULL)
  7505. {
  7506. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7507. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7508. }
  7509. }
  7510. }
  7511. }
  7512. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7513. }
  7514. else
  7515. {
  7516. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7517. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7518. }
  7519. json_object_put(data);
  7520. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7521. json_object_put(response);
  7522. }
  7523. else
  7524. {
  7525. // Can not find valid message id
  7526. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  7527. }
  7528. }
  7529. else
  7530. {
  7531. // Payload is null
  7532. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  7533. }
  7534. LWS_Send(message);
  7535. return result;
  7536. }
  7537. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  7538. {
  7539. mtrace();
  7540. int result = FAIL;
  7541. int connectorIdInt, durationInt;
  7542. char chargingRateUnitStr[4]={0};
  7543. char comfirmstr[20];
  7544. int confirmPeriods = 0;
  7545. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  7546. json_object *GetCompositeSchedule;
  7547. GetCompositeSchedule = json_tokener_parse(payload);
  7548. if(!is_error(GetCompositeSchedule))
  7549. {
  7550. // Required data
  7551. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  7552. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  7553. else
  7554. connectorIdInt = -1;
  7555. if(json_object_object_get(GetCompositeSchedule, "duration"))
  7556. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  7557. else
  7558. durationInt = 86400;
  7559. // Optional data
  7560. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  7561. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  7562. }
  7563. json_object_put(GetCompositeSchedule);
  7564. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  7565. if((connectorIdInt == 0) ||
  7566. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  7567. {
  7568. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  7569. struct StructChargingProfile tmpProfile[1];
  7570. if(strstr(chargingRateUnitStr, "W") != NULL)
  7571. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  7572. else
  7573. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  7574. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7575. {
  7576. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7577. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7578. }
  7579. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  7580. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  7581. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  7582. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7583. {
  7584. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7585. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7586. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  7587. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  7588. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  7589. {
  7590. confirmPeriods = idx;
  7591. break;
  7592. }
  7593. }
  7594. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  7595. {
  7596. confirmPeriods += 1;
  7597. }
  7598. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  7599. }
  7600. else
  7601. {
  7602. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  7603. }
  7604. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  7605. return result;
  7606. }
  7607. int handleGetConfigurationRequest(char *uuid, char *payload)
  7608. {
  7609. mtrace();
  7610. int result = FAIL;
  7611. int MaxKeySupported = 0;
  7612. int n_keys = 0;
  7613. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  7614. DEBUG_INFO("handleGetConfigurationRequest...\n");
  7615. json_object *GetConfiguration;
  7616. GetConfiguration = json_tokener_parse(payload);
  7617. if(!is_error(GetConfiguration))
  7618. {
  7619. // Optional data
  7620. if(json_object_object_get(GetConfiguration, "key") != NULL)
  7621. {
  7622. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  7623. {
  7624. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  7625. n_keys = idx + 1;
  7626. }
  7627. }
  7628. }
  7629. json_object_put(GetConfiguration);
  7630. UnknownKeynum = 0;
  7631. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  7632. MaxKeySupported = GetConfigurationMaxKeysNUM;
  7633. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  7634. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  7635. if(n_keys != 0)
  7636. {
  7637. for(int i=0;i<n_keys;i++)
  7638. {
  7639. getKeyValue(requestKey[i]);
  7640. }
  7641. }
  7642. else
  7643. {
  7644. DEBUG_INFO("There is no key in Message, get all configuration\n");
  7645. getKeyValue("");
  7646. }
  7647. processUnkownKey();
  7648. sendGetConfigurationConfirmation(uuid);
  7649. return result;
  7650. }
  7651. static char fnamePlusPath[100]={0};
  7652. static char fnamePWithNoPath[60]={0};
  7653. void checkUploadLog(void)
  7654. {
  7655. FILE *fp;
  7656. /* Open the command for reading. */
  7657. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  7658. if (fp == NULL) {
  7659. printf("Failed to run command\n" );
  7660. exit(1);
  7661. }
  7662. int ftppathlen = 0;
  7663. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  7664. int i = 0;
  7665. /* Read the output a line at a time - output it. */
  7666. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  7667. if(i==0)
  7668. {
  7669. ftppathlen = strlen(fnamePlusPath);
  7670. printf("%s\n", fnamePlusPath);
  7671. fnamePlusPath[ftppathlen]='\0';
  7672. break;
  7673. }
  7674. i= i+1;
  7675. }
  7676. /* close */
  7677. pclose(fp);
  7678. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  7679. {
  7680. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  7681. {
  7682. fnamePlusPath[k]='\0';
  7683. }
  7684. }
  7685. i=1;
  7686. //char fname[60]={0};
  7687. while(i < ftppathlen)
  7688. {
  7689. int len=ftppathlen-i;
  7690. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  7691. {
  7692. printf("compare '/' all right\n");
  7693. break;
  7694. }
  7695. i=i+1;
  7696. }
  7697. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  7698. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  7699. fnamePWithNoPath[i+1] = '\0';
  7700. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  7701. {
  7702. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  7703. {
  7704. fnamePWithNoPath[j]='\0';
  7705. }
  7706. }
  7707. FILE* fp1 = fopen(fnamePlusPath, "r");
  7708. if (fp1)
  7709. {
  7710. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  7711. // file exists
  7712. fclose(fp1);
  7713. }
  7714. else
  7715. {
  7716. // file doesn't exist
  7717. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  7718. }
  7719. }
  7720. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  7721. {
  7722. mtrace();
  7723. int result = FAIL;
  7724. time_t CurrentTime;
  7725. struct tm *tm;
  7726. pthread_t th_Status;
  7727. CurrentTime = time(NULL);
  7728. tm = localtime(&CurrentTime);
  7729. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  7730. 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);
  7731. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  7732. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  7733. return result;
  7734. }
  7735. void* GetDiagnosticsProcess(void* data)
  7736. {
  7737. pthread_detach(pthread_self());
  7738. mtrace();
  7739. int retriesInt=0, retryIntervalInt=0;
  7740. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  7741. char protocol[10]={0}, user[64]={0},password[64]={0},host[128]={0}, path[512]={0}, ftppath[512]={0},host1[128]={0},path1[512]={0};
  7742. int port=0;
  7743. int isSuccess = FALSE;
  7744. char cmdBuf[2048];
  7745. struct tm *tmNow;
  7746. time_t CurrentTime;
  7747. struct tm tmStart;
  7748. struct tm tmStop;
  7749. CurrentTime = time(NULL);
  7750. tmNow=localtime(&CurrentTime);
  7751. uint16_t targetYear, targetMonth;
  7752. json_object *GetDiagnostics;
  7753. DEBUG_INFO("GetDiagnosticsProcess...\n");
  7754. GetDiagnostics = json_tokener_parse(data);
  7755. if(!is_error(GetDiagnostics))
  7756. {
  7757. // Required data
  7758. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  7759. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  7760. // Optional data
  7761. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  7762. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  7763. else
  7764. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  7765. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  7766. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  7767. else
  7768. retryIntervalInt = 30;
  7769. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  7770. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  7771. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  7772. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  7773. }
  7774. json_object_put(GetDiagnostics);
  7775. // Pack log to compress file
  7776. 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) &&
  7777. (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))
  7778. {
  7779. // Pack system log
  7780. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  7781. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  7782. targetYear = tmStart.tm_year;
  7783. targetMonth = tmStart.tm_mon;
  7784. do
  7785. {
  7786. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7787. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7788. if(targetMonth+1>=13)
  7789. {
  7790. targetYear += 1;
  7791. targetMonth = 1;
  7792. }
  7793. else
  7794. {
  7795. targetMonth += 1;
  7796. }
  7797. }while((targetYear < (tmNow->tm_year+1900)) ||
  7798. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  7799. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  7800. system(cmdBuf);
  7801. // Pack charging & event log
  7802. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  7803. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  7804. targetYear = tmStart.tm_year;
  7805. targetMonth = tmStart.tm_mon;
  7806. do
  7807. {
  7808. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7809. if(targetMonth+1>=13)
  7810. {
  7811. targetYear += 1;
  7812. targetMonth = 1;
  7813. }
  7814. else
  7815. {
  7816. targetMonth += 1;
  7817. }
  7818. }while((targetYear < (tmNow->tm_year+1900)) ||
  7819. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  7820. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  7821. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  7822. system(cmdBuf);
  7823. // Combine log file
  7824. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  7825. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  7826. }
  7827. else
  7828. {
  7829. system("exec /root/logPackTools 'log' 6");
  7830. }
  7831. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  7832. system(cmdBuf);
  7833. checkUploadLog();
  7834. //****************location*******************/
  7835. if(strcmp(locationstr,"")==0)
  7836. {
  7837. DEBUG_INFO("location is <Empty>!\n");
  7838. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7839. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7840. goto end;
  7841. }
  7842. memset(protocol, 0, ARRAY_SIZE(protocol));
  7843. memset(user, 0, ARRAY_SIZE(user) );
  7844. memset(password, 0, ARRAY_SIZE(password));
  7845. memset(host, 0, ARRAY_SIZE(host));
  7846. memset(path, 0, ARRAY_SIZE(path));
  7847. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  7848. memset(host1, 0, ARRAY_SIZE(host1));
  7849. memset(path1, 0, ARRAY_SIZE(path1));
  7850. /*location: ftp://user:password@host:port/path*/
  7851. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  7852. if((access(fnamePlusPath,F_OK))!=-1)
  7853. {
  7854. DEBUG_INFO("fnamePlusPath exist.\n");
  7855. }
  7856. else
  7857. {
  7858. DEBUG_INFO("fnamePlusPath not exist!\n");
  7859. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7860. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7861. goto end;
  7862. }
  7863. if(strchr(locationstr,'@')==NULL)
  7864. {
  7865. sscanf(locationstr,
  7866. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  7867. protocol, host, &port, path);
  7868. strcpy(user,"anonymous");
  7869. strcpy(password,"");
  7870. }
  7871. else
  7872. {
  7873. //DEBUG_INFO("pch=%s\n", pch);
  7874. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  7875. protocol, user, password, host, &port, path);
  7876. }
  7877. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  7878. {
  7879. DEBUG_INFO("protocol is not ftp/http ! \n");
  7880. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7881. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7882. goto end;
  7883. }
  7884. if(strncmp(locationstr,"http", 4) == 0)
  7885. {
  7886. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  7887. sprintf(ftppath,"/%s", path);
  7888. do
  7889. {
  7890. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7891. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7892. sleep(3);
  7893. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  7894. if(!isSuccess)
  7895. {
  7896. DEBUG_INFO("Diagnostics fail.\n");
  7897. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7898. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7899. sleep(retryIntervalInt);
  7900. }
  7901. else
  7902. {
  7903. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7904. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7905. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7906. }
  7907. retriesInt--;
  7908. }while((isSuccess == 0)&&(retriesInt >= 0));
  7909. }
  7910. else
  7911. {
  7912. sscanf(host,"%[^/]%s",host1, path1);
  7913. if(strlen(path) > 0)
  7914. sprintf(ftppath,"/%s", path);
  7915. else
  7916. sprintf(ftppath,"/%s", path1);
  7917. int ftppathlen=strlen(ftppath);
  7918. int i=1;
  7919. char filenametemp[50];
  7920. while(i < ftppathlen)
  7921. {
  7922. int len=ftppathlen-i;
  7923. if(ftppath[len]== 47) // '/' ascll code: 47
  7924. {
  7925. DEBUG_INFO("find '/' all right\n");
  7926. break;
  7927. }
  7928. i=i+1;
  7929. }
  7930. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  7931. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  7932. filenametemp[i+1] = 0;
  7933. if(port == 0)
  7934. port = 21;
  7935. do
  7936. {
  7937. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7938. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7939. sleep(3);
  7940. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  7941. if(!isSuccess)
  7942. {
  7943. DEBUG_INFO("Diagnostics fail.\n");
  7944. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7945. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7946. sleep(retryIntervalInt);
  7947. }
  7948. else
  7949. {
  7950. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7951. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7952. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7953. }
  7954. retriesInt--;
  7955. }while((!isSuccess)&&(retriesInt >= 0));
  7956. }
  7957. end:
  7958. system("rm -f /mnt/*");
  7959. sleep(5);
  7960. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  7961. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7962. pthread_exit(NULL);
  7963. }
  7964. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  7965. {
  7966. mtrace();
  7967. int result = FAIL;
  7968. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  7969. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  7970. {
  7971. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  7972. localversion = -1;
  7973. }
  7974. else
  7975. {
  7976. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  7977. OCPP_getListVerion();
  7978. }
  7979. //from db.OCPP_getListVerion
  7980. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  7981. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  7982. sendGetLocalListVersionConfirmation(uuid,"");
  7983. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  7984. return result;
  7985. }
  7986. int handleRemoteStartRequest(char *uuid, char *payload)
  7987. {
  7988. mtrace();
  7989. int result = FAIL;
  7990. int connectorIdInt=0;
  7991. int tempIndex = 0;
  7992. int connectorIdIsNULL, chargingProfileIsNULL;
  7993. char comfirmstr[20]={0};
  7994. char cmdBuf[512];
  7995. json_object *RemoteStartTransaction;
  7996. FILE *fp;
  7997. DEBUG_INFO("handleRemoteStartRequest ...\n");
  7998. if(server_pending == TRUE)
  7999. {
  8000. return 0;
  8001. }
  8002. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  8003. RemoteStartTransaction = json_tokener_parse(payload);
  8004. if(!is_error(RemoteStartTransaction))
  8005. {
  8006. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  8007. {
  8008. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  8009. if(connectorIdInt <= gunTotalNumber)
  8010. {
  8011. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  8012. // Required data
  8013. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  8014. // Optional data
  8015. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  8016. {
  8017. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  8018. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  8019. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  8020. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  8021. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  8022. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  8023. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  8024. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  8025. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  8026. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  8027. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  8028. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  8029. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  8030. {
  8031. 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")));
  8032. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  8033. 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"));
  8034. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  8035. 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"));
  8036. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  8037. 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")));
  8038. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  8039. {
  8040. 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++)
  8041. {
  8042. 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"));
  8043. 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"));
  8044. 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)
  8045. 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"));
  8046. }
  8047. }
  8048. }
  8049. }
  8050. else
  8051. chargingProfileIsNULL = TRUE;
  8052. }
  8053. }
  8054. else
  8055. connectorIdIsNULL = TRUE;
  8056. }
  8057. else
  8058. connectorIdIsNULL = TRUE;
  8059. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  8060. {
  8061. DEBUG_WARN("Connector id is NULL\n.");
  8062. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8063. goto end;
  8064. }
  8065. /*
  8066. enum _SYSTEM_STATUS
  8067. {
  8068. S_BOOTING = 0,
  8069. S_IDLE, = 1
  8070. S_AUTHORIZING, = 2
  8071. S_REASSIGN_CHECK, = 3
  8072. S_REASSIGN, = 4
  8073. S_PRECHARGE, = 5
  8074. S_PREPARING_FOR_EV, = 6
  8075. S_PREPARING_FOR_EVSE, = 7
  8076. S_CHARGING, = 8
  8077. S_TERMINATING, = 9
  8078. S_COMPLETE, = 10
  8079. S_ALARM, = 11
  8080. S_FAULT = 12
  8081. }
  8082. */
  8083. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  8084. {
  8085. //check Transaction active
  8086. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8087. {
  8088. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8089. {
  8090. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8091. }
  8092. else
  8093. {
  8094. tempIndex = connectorIdInt -1;
  8095. }
  8096. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8097. {
  8098. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  8099. {
  8100. 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))
  8101. {
  8102. //Reserved
  8103. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8104. }
  8105. 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))
  8106. {
  8107. //Reserved
  8108. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8109. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8110. goto end;
  8111. }
  8112. else
  8113. {
  8114. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8115. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  8116. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  8117. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  8118. {
  8119. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  8120. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8121. goto end;
  8122. }
  8123. }//END FOR ELSE
  8124. }
  8125. }// END FOR CHAdeMO_QUANTITY
  8126. }
  8127. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8128. {
  8129. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8130. {
  8131. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8132. }
  8133. else
  8134. {
  8135. tempIndex = connectorIdInt -1;
  8136. }
  8137. for (int index = 0; index < CCS_QUANTITY; index++)
  8138. {
  8139. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8140. {
  8141. 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))
  8142. {
  8143. //Reserved
  8144. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8145. }
  8146. 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))
  8147. {
  8148. //Reserved
  8149. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8150. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8151. goto end;
  8152. }
  8153. else
  8154. {
  8155. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8156. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8157. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8158. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8159. {
  8160. DEBUG_WARN("CCS connector not allow start\n.");
  8161. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8162. goto end;
  8163. }
  8164. }// END FOR ELSE
  8165. }
  8166. }// END FOR CCS_QUANTITY
  8167. }
  8168. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8169. {
  8170. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8171. {
  8172. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8173. }
  8174. else
  8175. {
  8176. tempIndex = connectorIdInt -1;
  8177. }
  8178. for (int index = 0; index < GB_QUANTITY; index++)
  8179. {
  8180. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  8181. {
  8182. 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))
  8183. {
  8184. //Reserved
  8185. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8186. }
  8187. 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))
  8188. {
  8189. //Reserved
  8190. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8191. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8192. goto end;
  8193. }
  8194. else
  8195. {
  8196. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8197. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8198. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8199. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8200. {
  8201. DEBUG_WARN("GB connector not allow start\n.");
  8202. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8203. goto end;
  8204. }
  8205. }// END FOR ELSE
  8206. }
  8207. } // END FOR GB_QUANTITY
  8208. }
  8209. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8210. {
  8211. tempIndex = connectorIdInt -1;
  8212. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8213. {
  8214. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  8215. {
  8216. 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))
  8217. {
  8218. //Reserved
  8219. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8220. }
  8221. 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))
  8222. {
  8223. //Reserved
  8224. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8225. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8226. goto end;
  8227. }
  8228. else
  8229. {
  8230. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8231. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8232. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8233. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8234. {
  8235. DEBUG_WARN("GB connector not allow start\n.");
  8236. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8237. goto end;
  8238. }
  8239. }// END FOR ELSE
  8240. }
  8241. } // END FOR GB_QUANTITY
  8242. }
  8243. else
  8244. {
  8245. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8246. {
  8247. tempIndex = 2;
  8248. }
  8249. else
  8250. {
  8251. tempIndex = connectorIdInt -1;
  8252. }
  8253. for (int index = 0; index < AC_QUANTITY; index++)
  8254. {
  8255. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  8256. {
  8257. 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))
  8258. {
  8259. //Reserved
  8260. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8261. }
  8262. 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))
  8263. {
  8264. //Reserved
  8265. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8266. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8267. goto end;
  8268. }
  8269. else
  8270. {
  8271. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8272. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8273. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8274. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8275. {
  8276. DEBUG_WARN("AC connector not allow start\n.");
  8277. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8278. goto end;
  8279. }
  8280. }//END FOR ELSE
  8281. }
  8282. }// END FOR AC_QUANTITY
  8283. }
  8284. if(chargingProfileIsNULL == FALSE)
  8285. {
  8286. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8287. {
  8288. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  8289. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8290. //memset idTag
  8291. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  8292. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8293. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  8294. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8295. // Save profile to file
  8296. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8297. system(cmdBuf);
  8298. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8299. fp = fopen(cmdBuf, "w");
  8300. 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));
  8301. fclose(fp);
  8302. }
  8303. else
  8304. {
  8305. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  8306. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8307. }
  8308. }
  8309. else
  8310. {
  8311. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  8312. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8313. //memset idTag
  8314. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  8315. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8316. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  8317. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8318. }
  8319. }
  8320. else
  8321. {
  8322. DEBUG_WARN("Connector id over\n.");
  8323. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8324. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8325. }
  8326. end:
  8327. json_object_put(RemoteStartTransaction);
  8328. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  8329. {
  8330. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  8331. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8332. }
  8333. //OCPP send RemoteStartConfirmation by first.
  8334. sendRemoteStartConfirmation(uuid, comfirmstr);
  8335. return result;
  8336. }
  8337. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  8338. {
  8339. mtrace();
  8340. int result = FAIL;
  8341. int match = FALSE;
  8342. int GunNO = 0;
  8343. int tempIndex = 0;
  8344. int transactionIdInt=0;
  8345. int transactionIdIsNULL= TRUE;
  8346. char comfirmstr[20];
  8347. json_object *RemoteStopTransaction;
  8348. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  8349. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  8350. if(server_pending == TRUE)
  8351. {
  8352. return 0;
  8353. }
  8354. RemoteStopTransaction = json_tokener_parse(payload);
  8355. if(!is_error(RemoteStopTransaction))
  8356. {
  8357. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  8358. {
  8359. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  8360. transactionIdIsNULL = FALSE;
  8361. }
  8362. }
  8363. json_object_put(RemoteStopTransaction);
  8364. if(transactionIdIsNULL == FALSE)
  8365. {
  8366. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  8367. {
  8368. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  8369. {
  8370. //check Transaction active
  8371. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  8372. {
  8373. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8374. {
  8375. tempIndex = ((gun_index==2) ? 1: 0);
  8376. }
  8377. else
  8378. {
  8379. tempIndex = gun_index;
  8380. }
  8381. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8382. {
  8383. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8384. {
  8385. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8386. {
  8387. match = TRUE;
  8388. GunNO = gun_index;
  8389. }
  8390. }
  8391. }// END FOR CHAdeMO_QUANTITY
  8392. }
  8393. else if(gunType[gun_index] == GUN_TYPE_CCS)
  8394. {
  8395. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8396. {
  8397. tempIndex = ((gun_index==2) ? 1: 0);
  8398. }
  8399. else
  8400. {
  8401. tempIndex = gun_index;
  8402. }
  8403. for (int index = 0; index < CCS_QUANTITY; index++)
  8404. {
  8405. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8406. {
  8407. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8408. {
  8409. match = TRUE;
  8410. GunNO = gun_index;
  8411. }
  8412. }
  8413. }// END FOR CCS_QUANTITY
  8414. }
  8415. else if(gunType[gun_index] == GUN_TYPE_GBT)
  8416. {
  8417. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8418. {
  8419. tempIndex = ((gun_index==2) ? 1: 0);
  8420. }
  8421. else
  8422. {
  8423. tempIndex = gun_index;
  8424. }
  8425. for (int index = 0; index < GB_QUANTITY; index++)
  8426. {
  8427. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8428. {
  8429. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8430. {
  8431. match = TRUE;
  8432. GunNO = gun_index;
  8433. }
  8434. }
  8435. }// END FOR GB_QUANTITY
  8436. }
  8437. else if(gunType[gun_index] == GUN_TYPE_DO)
  8438. {
  8439. tempIndex = gun_index;
  8440. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8441. {
  8442. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8443. {
  8444. 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
  8445. {
  8446. match = TRUE;
  8447. GunNO = gun_index;
  8448. }
  8449. }
  8450. }// END FOR GB_QUANTITY
  8451. }
  8452. else
  8453. {
  8454. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8455. {
  8456. tempIndex = 2;
  8457. }
  8458. else
  8459. {
  8460. tempIndex = gun_index;
  8461. }
  8462. for (int index = 0; index < AC_QUANTITY; index++)
  8463. {
  8464. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8465. {
  8466. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8467. {
  8468. match = TRUE;
  8469. GunNO = gun_index;
  8470. }
  8471. }
  8472. }// END FOR CHAdeMO_QUANTITY
  8473. } // END FOR AC ELSE
  8474. }// CHECK IF ResponseTransactionId == transactionIdInt
  8475. }//END FOR
  8476. if( match == TRUE)
  8477. {
  8478. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  8479. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8480. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  8481. }
  8482. else
  8483. {
  8484. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8485. }
  8486. }
  8487. else
  8488. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8489. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  8490. return result;
  8491. }
  8492. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  8493. {
  8494. mtrace();
  8495. int result = FAIL;
  8496. int connectorIdInt=0, reservationIdInt=0;
  8497. int tempIndex = 0;
  8498. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  8499. char comfirmstr[20]={0};
  8500. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  8501. int c = 0;
  8502. char *loc;
  8503. //char *ptr;
  8504. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  8505. strcpy(sstrtemp, stringtrimspace(payload));
  8506. //***(1)connectorId ****/
  8507. c=0;
  8508. loc = strstr(sstrtemp, "connectorId");
  8509. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8510. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  8511. {
  8512. sstr[c] = loc[strlen("connectorId")+2+c];
  8513. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8514. c++;
  8515. }
  8516. sstr[c] = '\0';
  8517. connectorIdInt = atoi(sstr);
  8518. //***(2)expiryDate ****/
  8519. loc = strstr(sstrtemp, "expiryDate");
  8520. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8521. c = 0;
  8522. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  8523. {
  8524. sstr[c] = loc[3+strlen("expiryDate")+c];
  8525. c++;
  8526. }
  8527. sstr[c] = '\0';
  8528. strcpy(expiryDatestr, sstr);
  8529. //***(3)idTag ****/
  8530. loc = strstr(sstrtemp, "idTag");
  8531. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8532. c = 0;
  8533. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  8534. {
  8535. sstr[c] = loc[3+strlen("idTag")+c];
  8536. c++;
  8537. }
  8538. sstr[c] = '\0';
  8539. strcpy(idTagstr, sstr);
  8540. //***(4)parentIdTag ****/
  8541. loc = strstr(sstrtemp, "parentIdTag");
  8542. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8543. c = 0;
  8544. if(loc == NULL)
  8545. {
  8546. strcpy(parentIdTagstr, "");
  8547. }
  8548. else
  8549. {
  8550. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8551. {
  8552. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8553. c++;
  8554. }
  8555. sstr[c] = '\0';
  8556. strcpy(parentIdTagstr, sstr);
  8557. }
  8558. //***(5)reservationId ****/
  8559. c=0;
  8560. loc = strstr(sstrtemp, "reservationId");
  8561. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8562. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  8563. {
  8564. sstr[c] = loc[strlen("reservationId")+2+c];
  8565. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8566. c++;
  8567. }
  8568. sstr[c] = '\0';
  8569. reservationIdInt = atoi(sstr);
  8570. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8571. /*
  8572. enum SYSTEM_STATUS
  8573. {
  8574. SYS_MODE_BOOTING = 0,
  8575. SYS_MODE_IDLE = 1,
  8576. SYS_MODE_AUTHORIZING = 2,
  8577. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  8578. SYS_MODE_REASSIGN = 4,
  8579. SYS_MODE_PREPARING = 5,
  8580. SYS_MODE_PREPARE_FOR_EV = 6,
  8581. SYS_MODE_PREPARE_FOR_EVSE = 7,
  8582. SYS_MODE_CHARGING = 8,
  8583. SYS_MODE_TERMINATING = 9,
  8584. SYS_MODE_COMPLETE = 10,
  8585. SYS_MODE_ALARM = 11,
  8586. SYS_MODE_FAULT = 12,
  8587. SYS_MODE_RESERVATION = 13,
  8588. SYS_MODE_BOOKING = 14,
  8589. SYS_MODE_MAINTAIN = 15,
  8590. SYS_MODE_DEBUG = 16,
  8591. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  8592. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  8593. SYS_MODE_UPDATE = 19
  8594. };
  8595. */
  8596. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  8597. {
  8598. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8599. goto end;
  8600. }
  8601. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  8602. {
  8603. //check Transaction active
  8604. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8605. {
  8606. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8607. {
  8608. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8609. }
  8610. else
  8611. {
  8612. tempIndex = connectorIdInt -1;
  8613. }
  8614. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8615. {
  8616. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8617. {
  8618. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8619. {
  8620. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8621. {
  8622. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8623. {
  8624. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8625. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8626. }
  8627. 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'))
  8628. {
  8629. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8630. }
  8631. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8632. {
  8633. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8634. }
  8635. else
  8636. {
  8637. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8638. }
  8639. }
  8640. 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
  8641. {
  8642. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8643. }
  8644. }
  8645. else
  8646. {
  8647. //replace reservation
  8648. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8649. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8650. }
  8651. }
  8652. } // END FOR CHAdeMO_QUANTITY
  8653. }
  8654. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8655. {
  8656. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8657. {
  8658. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8659. }
  8660. else
  8661. {
  8662. tempIndex = connectorIdInt -1;
  8663. }
  8664. for (int index = 0; index < CCS_QUANTITY; index++)
  8665. {
  8666. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8667. {
  8668. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8669. {
  8670. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8671. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8672. {
  8673. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8674. {
  8675. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8676. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8677. }
  8678. 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'))
  8679. {
  8680. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8681. }
  8682. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  8683. {
  8684. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8685. }
  8686. else
  8687. {
  8688. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8689. }
  8690. }
  8691. 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
  8692. {
  8693. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8694. }
  8695. }
  8696. else
  8697. {
  8698. //replace reservation
  8699. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8700. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8701. }
  8702. }
  8703. } // END FOR CCS_QUANTITY
  8704. }
  8705. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8706. {
  8707. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8708. {
  8709. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8710. }
  8711. else
  8712. {
  8713. tempIndex = connectorIdInt -1;
  8714. }
  8715. for (int index = 0; index < GB_QUANTITY; index++)
  8716. {
  8717. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8718. {
  8719. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8720. {
  8721. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8722. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8723. {
  8724. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8725. {
  8726. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8727. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8728. }
  8729. 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'))
  8730. {
  8731. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8732. }
  8733. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8734. {
  8735. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8736. }
  8737. else
  8738. {
  8739. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8740. }
  8741. }
  8742. 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
  8743. {
  8744. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8745. }
  8746. }
  8747. else
  8748. {
  8749. //replace reservation
  8750. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8751. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8752. }
  8753. }
  8754. }// END FOR GB_QUANTITY
  8755. }
  8756. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8757. {
  8758. tempIndex = connectorIdInt -1;
  8759. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8760. {
  8761. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8762. {
  8763. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  8764. {
  8765. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8766. 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
  8767. {
  8768. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8769. {
  8770. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8771. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8772. }
  8773. 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'))
  8774. {
  8775. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8776. }
  8777. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8778. {
  8779. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8780. }
  8781. else
  8782. {
  8783. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8784. }
  8785. }
  8786. 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
  8787. {
  8788. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8789. }
  8790. }
  8791. else
  8792. {
  8793. //replace reservation
  8794. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8795. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8796. }
  8797. }
  8798. }// END FOR GB_QUANTITY
  8799. }
  8800. else
  8801. {
  8802. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8803. {
  8804. tempIndex = 2;
  8805. }
  8806. else
  8807. {
  8808. tempIndex = (connectorIdInt -1);
  8809. }
  8810. for (int index = 0; index < AC_QUANTITY; index++)
  8811. {
  8812. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8813. {
  8814. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8815. {
  8816. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8817. {
  8818. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8819. {
  8820. 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))
  8821. {
  8822. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8823. }
  8824. else
  8825. {
  8826. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8827. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8828. }
  8829. }
  8830. 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'))
  8831. {
  8832. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8833. }
  8834. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8835. {
  8836. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8837. }
  8838. else
  8839. {
  8840. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8841. }
  8842. }
  8843. 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
  8844. {
  8845. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8846. }
  8847. }
  8848. else
  8849. {
  8850. //replace reservation
  8851. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8852. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8853. }
  8854. }
  8855. } // END FOR AC_QUANTITY
  8856. }
  8857. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8858. }
  8859. else if(connectorIdInt == 0)
  8860. {
  8861. //check Transaction active
  8862. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8863. {
  8864. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8865. {
  8866. 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'))
  8867. {
  8868. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8869. goto end;
  8870. }
  8871. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8872. {
  8873. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8874. goto end;
  8875. }
  8876. 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
  8877. {
  8878. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8879. goto end;
  8880. }
  8881. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8882. {
  8883. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8884. goto end;
  8885. }
  8886. }
  8887. }// END FOR CHAdeMO_QUANTITY
  8888. for (int index = 0; index < CCS_QUANTITY; index++)
  8889. {
  8890. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8891. {
  8892. 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'))
  8893. {
  8894. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8895. goto end;
  8896. }
  8897. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  8898. {
  8899. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8900. goto end;
  8901. }
  8902. 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
  8903. {
  8904. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8905. goto end;
  8906. }
  8907. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8908. {
  8909. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8910. goto end;
  8911. }
  8912. }
  8913. } // END FOR CCS_QUANTITY
  8914. for (int index = 0; index < GB_QUANTITY; index++)
  8915. {
  8916. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8917. {
  8918. 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'))
  8919. {
  8920. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8921. goto end;
  8922. }
  8923. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8924. {
  8925. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8926. goto end;
  8927. }
  8928. 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
  8929. {
  8930. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8931. goto end;
  8932. }
  8933. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8934. {
  8935. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8936. goto end;
  8937. }
  8938. }
  8939. } // END FOR GB_QUANTITY
  8940. for (int index = 0; index < AC_QUANTITY; index++)
  8941. {
  8942. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8943. {
  8944. 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'))
  8945. {
  8946. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8947. goto end;
  8948. }
  8949. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8950. {
  8951. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8952. goto end;
  8953. }
  8954. 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
  8955. {
  8956. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8957. goto end;
  8958. }
  8959. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8960. {
  8961. 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))
  8962. {
  8963. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8964. goto end;
  8965. }
  8966. }
  8967. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8968. {
  8969. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8970. goto end;
  8971. }
  8972. }
  8973. }// END FOR AC_QUANTITY
  8974. //The connectorId is 0
  8975. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  8976. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8977. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  8978. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  8979. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  8980. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  8981. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  8982. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  8983. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  8984. result = TRUE;
  8985. return result;
  8986. }
  8987. else
  8988. {
  8989. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8990. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8991. }
  8992. if(strcmp(comfirmstr,"Accepted") == 0)
  8993. {
  8994. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  8995. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  8996. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  8997. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  8998. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  8999. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  9000. result = TRUE;
  9001. return result;
  9002. }
  9003. end:
  9004. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  9005. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  9006. return result;
  9007. }
  9008. int handleResetRequest(char *uuid, char *payload)
  9009. {
  9010. mtrace();
  9011. int result = FAIL;
  9012. char sstr[10]={0},sstrtemp[30]={ 0 };
  9013. char typestr[10]={0};
  9014. char comfirmstr[20]={0};
  9015. int c = 0;
  9016. char *loc;
  9017. DEBUG_INFO("handleResetRequest...\n");
  9018. strcpy(sstrtemp, stringtrimspace(payload));
  9019. loc = strstr(sstrtemp, "type");
  9020. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9021. c = 0;
  9022. while (loc[3+strlen("type")+c] != '\"')
  9023. {
  9024. sstr[c] = loc[3+strlen("type")+c];
  9025. c++;
  9026. }
  9027. sstr[c] = '\0';
  9028. strcpy(typestr,sstr);
  9029. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  9030. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  9031. {
  9032. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  9033. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  9034. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  9035. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  9036. }
  9037. else
  9038. {
  9039. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  9040. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  9041. result = PASS;
  9042. }
  9043. sendResetConfirmation(uuid, comfirmstr);
  9044. return result;
  9045. }
  9046. int handleSendLocalListRequest(char *uuid, char *payload)
  9047. {
  9048. mtrace();
  9049. int result = FAIL;
  9050. int listVersionInt;
  9051. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  9052. char listsearch[]="listVersion";
  9053. char updateTypesearch[]="updateType";
  9054. char localAuthorizationListsearch[]="localAuthorizationList";
  9055. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  9056. char CardList[500][160]={0};
  9057. char updateTypestr[15]={0};
  9058. char idTagstr[20]={0};
  9059. char parentIdTag[20]={0};
  9060. char expiryDate[30]={0};
  9061. char idTagstatus[16]={0};
  9062. int c = 0;
  9063. int i = 0;
  9064. char *delim1 = "}";
  9065. char * pch;
  9066. char *loc;
  9067. //char *ptr;
  9068. char comfirmstr[20];
  9069. //int n_localAuthorizations = 0;
  9070. int checkState_Faulted = FALSE;
  9071. DEBUG_INFO("handleSendLocalListRequest...\n");
  9072. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  9073. {
  9074. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9075. goto end;
  9076. }
  9077. //check Charge Point state
  9078. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9079. {
  9080. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9081. {
  9082. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9083. }
  9084. }
  9085. for (int index = 0; index < CCS_QUANTITY; index++)
  9086. {
  9087. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9088. {
  9089. checkState_Faulted = TRUE; //OCPP Status
  9090. }
  9091. }
  9092. for (int index = 0; index < GB_QUANTITY; index++)
  9093. {
  9094. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9095. {
  9096. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9097. }
  9098. }
  9099. //check Charge Point state
  9100. for (int index = 0; index < AC_QUANTITY; index++)
  9101. {
  9102. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9103. {
  9104. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9105. }
  9106. }
  9107. if(checkState_Faulted == TRUE)
  9108. {
  9109. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9110. goto end;
  9111. }
  9112. //Filter payload space
  9113. strcpy(sstrtemp, stringtrimspace(payload));
  9114. //listVersion
  9115. c = 0;
  9116. loc = strstr(sstrtemp, listsearch);
  9117. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  9118. {
  9119. sstr[c] = loc[strlen("listVersion")+2+c];
  9120. c++;
  9121. }
  9122. sstr[c] = '\0';
  9123. listVersionInt = atoi(sstr);
  9124. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  9125. //updateType
  9126. loc = strstr(sstrtemp, updateTypesearch);
  9127. c = 0;
  9128. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  9129. {
  9130. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  9131. c++;
  9132. }
  9133. sstr[c] = '\0';
  9134. strcpy(updateTypestr, sstr);
  9135. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  9136. //localAuthorizationList
  9137. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9138. loc = strstr(sstrtemp, localAuthorizationListsearch);
  9139. if(loc != NULL) // localAuthorizationList is not NULL
  9140. {
  9141. //Check UpdateType
  9142. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9143. {
  9144. //Local list full update
  9145. printf("Local list full update.\n");
  9146. OCPP_getListVerion();
  9147. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  9148. {
  9149. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9150. goto end;
  9151. }
  9152. OCPP_cleanLocalList();
  9153. }
  9154. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9155. {
  9156. //Local list different update
  9157. printf("Local list different update.\n");
  9158. OCPP_getListVerion();
  9159. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  9160. {
  9161. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  9162. goto end;
  9163. }
  9164. }
  9165. else
  9166. {
  9167. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9168. goto end;
  9169. }
  9170. c = 0;
  9171. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  9172. {
  9173. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  9174. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9175. c++;
  9176. }
  9177. sstr[c] = '\0';
  9178. //DEBUG_INFO("sstr=%s\n", sstr);
  9179. //parsing strings to words
  9180. i = 0;
  9181. pch = strtok(sstr,delim1);
  9182. while (pch != NULL)
  9183. {
  9184. strcpy(CardList[i], pch);
  9185. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  9186. pch = strtok (NULL, delim1);
  9187. i = i + 1;
  9188. }
  9189. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  9190. //local Authorizations List Numbers
  9191. //n_localAuthorizations = i;
  9192. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  9193. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  9194. c= 0;
  9195. while(c < i) // i is CardList Number
  9196. {
  9197. //Search "IdToken"
  9198. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9199. loc = strstr(CardList[c], "idTag");
  9200. int j = 0;
  9201. while (loc[3+strlen("idTag")+j] != '\"')
  9202. {
  9203. sstr[j] = loc[3+strlen("idTag")+j];
  9204. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9205. j++;
  9206. }
  9207. sstr[j] = '\0';
  9208. strcpy(idTagstr, sstr);
  9209. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  9210. //Search "expiryDate"
  9211. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9212. loc = strstr(CardList[c], "expiryDate");
  9213. j = 0;
  9214. if(loc != NULL)
  9215. {
  9216. while (loc[3+strlen("expiryDate")+j] != '\"')
  9217. {
  9218. sstr[j] = loc[3+strlen("expiryDate")+j];
  9219. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9220. j++;
  9221. }
  9222. sstr[j] = '\0';
  9223. strcpy(expiryDate, sstr);
  9224. }
  9225. else
  9226. {
  9227. strcpy(expiryDate, "");
  9228. }
  9229. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  9230. //Search "parentIdTag"
  9231. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9232. loc = strstr(CardList[c], "parentIdTag");
  9233. j = 0;
  9234. if(loc != NULL)
  9235. {
  9236. while (loc[3+strlen("parentIdTag")+j] != '\"')
  9237. {
  9238. sstr[j] = loc[3+strlen("parentIdTag")+j];
  9239. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9240. j++;
  9241. }
  9242. sstr[j] = '\0';
  9243. strcpy(parentIdTag, sstr);
  9244. }
  9245. else
  9246. {
  9247. strcpy(parentIdTag, "");
  9248. }
  9249. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  9250. //Search "status"
  9251. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9252. loc = strstr(CardList[c], "status");
  9253. j = 0;
  9254. while (loc[3+strlen("status")+j] != '\"')
  9255. {
  9256. sstr[j] = loc[3+strlen("status")+j];
  9257. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9258. j++;
  9259. }
  9260. sstr[j] = '\0';
  9261. strcpy(idTagstatus, sstr);
  9262. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  9263. OCPP_getIdTagFromLocalList(idTagstr);
  9264. //OCPP_getIdTagFromLocalList("test"); For Test
  9265. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  9266. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  9267. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9268. {
  9269. //Local list full update
  9270. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9271. // update list
  9272. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9273. //DEBUG_INFO("Local list full update. 1\n");
  9274. //OCPP_get_TableAuthlocalAllData();
  9275. //DEBUG_INFO("Local list full update. 2\n");
  9276. }
  9277. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9278. {
  9279. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9280. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  9281. }
  9282. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  9283. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  9284. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  9285. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  9286. c++;
  9287. }
  9288. }
  9289. else
  9290. {
  9291. //Check UpdateType
  9292. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9293. {
  9294. //Local list full update
  9295. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  9296. OCPP_cleanLocalList();
  9297. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9298. goto end;
  9299. }
  9300. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9301. {
  9302. //Local list different update
  9303. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  9304. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9305. goto end;
  9306. }
  9307. }
  9308. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9309. end:
  9310. sendSendLocalListConfirmation(uuid, comfirmstr);
  9311. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  9312. return result;
  9313. }
  9314. #define MAX 200
  9315. int handleSetChargingProfileRequest(char *uuid, char *payload)
  9316. {
  9317. mtrace();
  9318. int result = FAIL;
  9319. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  9320. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  9321. char chargingProfilePurposeStr[30]={0};
  9322. char chargingProfileKindStr[16]={0};
  9323. char recurrencyKindStr[10]={0};
  9324. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  9325. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  9326. int chargingSchedulePeriodCount = 0;
  9327. char comfirmstr[20]={0};
  9328. int meet= FALSE;
  9329. FILE *fptr1;
  9330. char filename[MAX]={0};
  9331. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  9332. char rmFileCmd[50]={0};
  9333. char tempchargingProfilePurposeStr[30]={0};
  9334. char word[1600]={0};
  9335. int n_chargingProfile = 0;
  9336. json_object *SetChargingProfile;
  9337. DEBUG_INFO("handleSetChargingProfileRequest\n");
  9338. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  9339. SetChargingProfile = json_tokener_parse(payload);
  9340. if(!is_error(SetChargingProfile))
  9341. {
  9342. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  9343. {
  9344. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  9345. if(connectorIdInt == 0)
  9346. {
  9347. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  9348. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  9349. }
  9350. else
  9351. {
  9352. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  9353. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  9354. }
  9355. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  9356. }
  9357. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  9358. {
  9359. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9360. {
  9361. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9362. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9363. {
  9364. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9365. }
  9366. else
  9367. {
  9368. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9369. }
  9370. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  9371. }
  9372. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9373. {
  9374. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  9375. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9376. {
  9377. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  9378. }
  9379. else
  9380. {
  9381. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  9382. }
  9383. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  9384. }
  9385. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9386. {
  9387. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9388. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9389. {
  9390. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9391. }
  9392. else
  9393. {
  9394. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9395. }
  9396. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  9397. }
  9398. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  9399. {
  9400. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  9401. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9402. {
  9403. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9404. }
  9405. else
  9406. {
  9407. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9408. }
  9409. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  9410. }
  9411. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  9412. {
  9413. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  9414. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9415. {
  9416. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  9417. }
  9418. else
  9419. {
  9420. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  9421. }
  9422. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  9423. }
  9424. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  9425. {
  9426. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  9427. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9428. {
  9429. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9430. }
  9431. else
  9432. {
  9433. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9434. }
  9435. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  9436. }
  9437. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  9438. {
  9439. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  9440. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9441. {
  9442. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  9443. }
  9444. else
  9445. {
  9446. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  9447. }
  9448. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  9449. }
  9450. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  9451. {
  9452. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  9453. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9454. {
  9455. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  9456. }
  9457. else
  9458. {
  9459. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  9460. }
  9461. //DEBUG_INFO("validToStr: %s\n", validToStr);
  9462. }
  9463. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  9464. {
  9465. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  9466. {
  9467. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  9468. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9469. {
  9470. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9471. }
  9472. else
  9473. {
  9474. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9475. }
  9476. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  9477. }
  9478. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  9479. {
  9480. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  9481. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9482. {
  9483. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9484. }
  9485. else
  9486. {
  9487. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9488. }
  9489. //DEBUG_INFO("durationInt: %d\n", durationInt);
  9490. }
  9491. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  9492. {
  9493. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  9494. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9495. {
  9496. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9497. }
  9498. else
  9499. {
  9500. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9501. }
  9502. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  9503. }
  9504. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  9505. {
  9506. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  9507. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9508. {
  9509. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9510. }
  9511. else
  9512. {
  9513. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9514. }
  9515. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  9516. }
  9517. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9518. {
  9519. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  9520. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  9521. if(chargingSchedulePeriodCount <= 10)
  9522. {
  9523. 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++)
  9524. {
  9525. 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)
  9526. {
  9527. 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"));
  9528. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9529. {
  9530. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9531. }
  9532. else
  9533. {
  9534. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9535. }
  9536. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  9537. }
  9538. 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)
  9539. {
  9540. 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"));
  9541. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9542. {
  9543. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9544. }
  9545. else
  9546. {
  9547. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9548. }
  9549. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  9550. }
  9551. 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)
  9552. {
  9553. 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"));
  9554. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9555. {
  9556. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9557. }
  9558. else
  9559. {
  9560. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9561. }
  9562. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  9563. }
  9564. }
  9565. }
  9566. }
  9567. }
  9568. }
  9569. }
  9570. json_object_put(SetChargingProfile);
  9571. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  9572. {
  9573. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9574. goto end;
  9575. }
  9576. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  9577. {
  9578. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  9579. if(connectorIdInt != 0)
  9580. {
  9581. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9582. goto end;
  9583. }
  9584. strcpy(filename, ChargePointMaxProfile_JSON );
  9585. fptr1 = fopen(filename, "r");
  9586. if (!fptr1)
  9587. {
  9588. //file not exist
  9589. DEBUG_INFO("Unable to open the input file!!\n");
  9590. fptr1 = fopen(filename, "w+");
  9591. }
  9592. else
  9593. {
  9594. //Check Charging Profile Count
  9595. while(fscanf(fptr1, "%s", word) != EOF)
  9596. {
  9597. //DEBUG_INFO("word=%s\n",word);
  9598. if(strstr(word, "chargingProfileId")!= NULL)
  9599. {
  9600. //DEBUG_INFO("test chargingProfileId \n");
  9601. n_chargingProfile = n_chargingProfile + 1;
  9602. //DEBUG_INFO("chargingProfileId Found\n");
  9603. }
  9604. }
  9605. }
  9606. fclose(fptr1);
  9607. }
  9608. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  9609. {
  9610. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  9611. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9612. {
  9613. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9614. goto end;
  9615. }
  9616. memset(filename, 0, ARRAY_SIZE(filename));
  9617. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9618. fptr1 = fopen(filename, "r");
  9619. if (!fptr1)
  9620. {
  9621. //file not exist
  9622. //DEBUG_INFO("Unable to open the input file!!\n");
  9623. fptr1 = fopen(filename, "w+");
  9624. }
  9625. else
  9626. {
  9627. //Check Charging Profile Count
  9628. while(fscanf(fptr1, "%s", word) != EOF)
  9629. {
  9630. //DEBUG_INFO("word=%s\n",word);
  9631. if(strstr(word, "chargingProfileId")!= NULL)
  9632. {
  9633. //DEBUG_INFO("test chargingProfileId \n");
  9634. n_chargingProfile = n_chargingProfile + 1;
  9635. //DEBUG_INFO("chargingProfileId Found\n");
  9636. }
  9637. }
  9638. }
  9639. fclose(fptr1);
  9640. }
  9641. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9642. {
  9643. //printf("set chargingProfile 1-4\n");
  9644. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  9645. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  9646. if(connectorIdInt == 0)
  9647. {
  9648. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9649. goto end;
  9650. }
  9651. int tempIndex = 0;
  9652. //check Transaction active
  9653. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9654. {
  9655. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9656. {
  9657. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9658. }
  9659. else
  9660. {
  9661. tempIndex = connectorIdInt -1;
  9662. }
  9663. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9664. {
  9665. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9666. {
  9667. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9668. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9669. {
  9670. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9671. {
  9672. meet = TRUE;
  9673. break;
  9674. }
  9675. }
  9676. }
  9677. }
  9678. }
  9679. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9680. {
  9681. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9682. {
  9683. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9684. }
  9685. else
  9686. {
  9687. tempIndex = connectorIdInt -1;
  9688. }
  9689. for (int index = 0; index < CCS_QUANTITY; index++)
  9690. {
  9691. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9692. {
  9693. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9694. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9695. {
  9696. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9697. {
  9698. meet = TRUE;
  9699. break;
  9700. }
  9701. }
  9702. }
  9703. }
  9704. }
  9705. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9706. {
  9707. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9708. {
  9709. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9710. }
  9711. else
  9712. {
  9713. tempIndex = connectorIdInt -1;
  9714. }
  9715. for (int index = 0; index < GB_QUANTITY; index++)
  9716. {
  9717. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9718. {
  9719. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9720. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9721. {
  9722. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9723. {
  9724. meet = TRUE;
  9725. break;
  9726. }
  9727. }
  9728. }
  9729. }
  9730. }
  9731. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9732. {
  9733. tempIndex = connectorIdInt -1;
  9734. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9735. {
  9736. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9737. {
  9738. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  9739. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9740. {
  9741. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9742. {
  9743. meet = TRUE;
  9744. break;
  9745. }
  9746. }
  9747. }
  9748. }
  9749. }
  9750. else
  9751. {
  9752. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9753. {
  9754. tempIndex = 2;
  9755. }
  9756. else
  9757. {
  9758. tempIndex = (connectorIdInt -1);
  9759. }
  9760. for (int index = 0; index < AC_QUANTITY; index++)
  9761. {
  9762. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9763. {
  9764. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9765. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9766. {
  9767. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9768. {
  9769. meet = TRUE;
  9770. break;
  9771. }
  9772. }
  9773. }
  9774. }
  9775. }
  9776. //check Transaction active
  9777. if(meet == FALSE)
  9778. {
  9779. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9780. goto end;
  9781. }
  9782. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9783. {
  9784. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9785. goto end;
  9786. }
  9787. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9788. fptr1 = fopen(filename, "r");
  9789. if (!fptr1)
  9790. {
  9791. //file not exist
  9792. DEBUG_INFO("Unable to open the input file!!\n");
  9793. fptr1 = fopen(filename, "w+");
  9794. }
  9795. else
  9796. {
  9797. //Check Charging Profile Count
  9798. while(fscanf(fptr1, "%s", word) != EOF)
  9799. {
  9800. //DEBUG_INFO("word=%s\n",word);
  9801. if(strstr(word, "chargingProfileId")!= NULL)
  9802. {
  9803. //DEBUG_INFO("test chargingProfileId \n");
  9804. n_chargingProfile = n_chargingProfile + 1;
  9805. //DEBUG_INFO("chargingProfileId Found\n");
  9806. }
  9807. }
  9808. }
  9809. fclose(fptr1);
  9810. }
  9811. // Check ChargeProfileMaxStackLevel
  9812. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  9813. {
  9814. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9815. goto end;
  9816. }
  9817. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9818. {
  9819. int i = 0;
  9820. char fnametemp[200]={0};
  9821. n_chargingProfile = 0;
  9822. //Check ChargePointMaxProfile.json exit
  9823. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9824. {
  9825. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  9826. //Check Charging Profile Count
  9827. while(fscanf(fptr1, "%s", word) != EOF)
  9828. {
  9829. //DEBUG_INFO("word=%s\n",word);
  9830. if(strstr(word, "chargingProfileId")!= NULL)
  9831. {
  9832. //DEBUG_INFO("test chargingProfileId \n");
  9833. n_chargingProfile = n_chargingProfile + 1;
  9834. i = i + 1;
  9835. //DEBUG_INFO("chargingProfileId Found\n");
  9836. }
  9837. memset(word, 0, ARRAY_SIZE(word));
  9838. }
  9839. fclose(fptr1);
  9840. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  9841. }
  9842. //Check TxDefaultProfile_0.json exit
  9843. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9844. {
  9845. i = 0;
  9846. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  9847. //Check Charging Profile Count
  9848. while(fscanf(fptr1, "%s", word) != EOF)
  9849. {
  9850. //DEBUG_INFO("word=%s\n",word);
  9851. if(strstr(word, "chargingProfileId")!= NULL)
  9852. {
  9853. //DEBUG_INFO("test chargingProfileId \n");
  9854. n_chargingProfile = n_chargingProfile + 1;
  9855. i = i + 1;
  9856. //DEBUG_INFO("chargingProfileId Found\n");
  9857. }
  9858. memset(word, 0, ARRAY_SIZE(word));
  9859. }
  9860. fclose(fptr1);
  9861. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  9862. }
  9863. //Check TxDefaultProfile_%d.json
  9864. for(int j=1; j <= gunTotalNumber; j++)
  9865. {
  9866. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9867. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9868. if((access(fnametemp,F_OK))!=-1)
  9869. {
  9870. i = 0;
  9871. fptr1 = fopen(fnametemp, "r");
  9872. //Check Charging Profile Count
  9873. while(fscanf(fptr1, "%s", word) != EOF)
  9874. {
  9875. //DEBUG_INFO("word=%s\n",word);
  9876. if(strstr(word, "chargingProfileId")!= NULL)
  9877. {
  9878. //DEBUG_INFO("test chargingProfileId \n");
  9879. n_chargingProfile = n_chargingProfile + 1;
  9880. i = i + 1;
  9881. //DEBUG_INFO("chargingProfileId Found\n");
  9882. }
  9883. memset(word, 0, ARRAY_SIZE(word));
  9884. }
  9885. fclose(fptr1);
  9886. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9887. }
  9888. }
  9889. //Check TxProfile_%d.json
  9890. for(int j=1; j <= gunTotalNumber; j++)
  9891. {
  9892. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9893. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9894. if((access(fnametemp,F_OK))!=-1)
  9895. {
  9896. i = 0;
  9897. fptr1 = fopen(fnametemp, "r");
  9898. //Check Charging Profile Count
  9899. while(fscanf(fptr1, "%s", word) != EOF)
  9900. {
  9901. //DEBUG_INFO("word=%s\n",word);
  9902. if(strstr(word, "chargingProfileId")!= NULL)
  9903. {
  9904. //DEBUG_INFO("test chargingProfileId \n");
  9905. n_chargingProfile = n_chargingProfile + 1;
  9906. i = i + 1;
  9907. //DEBUG_INFO("chargingProfileId Found\n");
  9908. }
  9909. memset(word, 0, ARRAY_SIZE(word));
  9910. }
  9911. fclose(fptr1);
  9912. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9913. }
  9914. }
  9915. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  9916. {
  9917. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9918. goto end;
  9919. }
  9920. }
  9921. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9922. //**********************************Write to File********************************************************/
  9923. FILE *infile;
  9924. FILE *outfile;
  9925. infile = fopen (filename, "r");
  9926. outfile = fopen (tempfile, "w");
  9927. int d =0;
  9928. d = fgetc(infile);
  9929. rewind(infile);
  9930. if(d == EOF)
  9931. {
  9932. // Profile is empty
  9933. fprintf(outfile,"%s\n",payload);
  9934. fclose(infile);
  9935. fclose(outfile);
  9936. sprintf(rmFileCmd,"rm -f %s",filename);
  9937. system(rmFileCmd);
  9938. rename(tempfile, filename);
  9939. }
  9940. else
  9941. {
  9942. // Profile is not empty
  9943. char buf[2048]={0};
  9944. int ChargingProfileAdded = FALSE;
  9945. while (fgets(buf, sizeof(buf), infile) != NULL)
  9946. {
  9947. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9948. json_object *tmpChargingProfile;
  9949. tmpChargingProfile = json_tokener_parse(buf);
  9950. if(!is_error(SetChargingProfile))
  9951. {
  9952. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  9953. {
  9954. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  9955. }
  9956. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  9957. {
  9958. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9959. {
  9960. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9961. }
  9962. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9963. {
  9964. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  9965. }
  9966. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9967. {
  9968. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9969. }
  9970. }
  9971. }
  9972. json_object_put(tmpChargingProfile);
  9973. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  9974. {
  9975. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9976. {
  9977. //DEBUG_INFO("update set chargingProfile to file -0\n");
  9978. if(ChargingProfileAdded == FALSE)
  9979. {
  9980. fprintf(outfile,"%s\n",payload);
  9981. ChargingProfileAdded = TRUE;
  9982. }
  9983. }
  9984. else
  9985. {
  9986. if(tempstackLevelInt < stackLevelInt)
  9987. {
  9988. if(ChargingProfileAdded == FALSE)
  9989. {
  9990. fprintf(outfile,"%s\n",buf);
  9991. fprintf(outfile,"%s\n",payload);
  9992. ChargingProfileAdded = TRUE;
  9993. }
  9994. else
  9995. {
  9996. fprintf(outfile,"%s\n",buf);
  9997. }
  9998. }
  9999. else
  10000. {
  10001. if(ChargingProfileAdded == FALSE)
  10002. {
  10003. fprintf(outfile,"%s\n",buf);
  10004. fprintf(outfile,"%s\n",payload);
  10005. ChargingProfileAdded = TRUE;
  10006. }
  10007. else
  10008. {
  10009. fprintf(outfile,"%s\n",buf);
  10010. }
  10011. }
  10012. }
  10013. }
  10014. else
  10015. {
  10016. if(tempchargingProfileIdInt < chargingProfileIdInt)
  10017. {
  10018. if(ChargingProfileAdded == FALSE)
  10019. {
  10020. fprintf(outfile,"%s\n",buf);
  10021. fprintf(outfile,"%s\n",payload);
  10022. ChargingProfileAdded = TRUE;
  10023. }
  10024. else
  10025. {
  10026. fprintf(outfile,"%s\n",buf);
  10027. }
  10028. }
  10029. else if(tempstackLevelInt < stackLevelInt)
  10030. {
  10031. if(ChargingProfileAdded == FALSE)
  10032. {
  10033. fprintf(outfile,"%s\n",buf);
  10034. fprintf(outfile,"%s\n",payload);
  10035. ChargingProfileAdded = TRUE;
  10036. }
  10037. else
  10038. {
  10039. fprintf(outfile,"%s\n",buf);
  10040. }
  10041. }
  10042. else
  10043. {
  10044. if(ChargingProfileAdded == FALSE)
  10045. {
  10046. fprintf(outfile,"%s\n",buf);
  10047. fprintf(outfile,"%s\n",payload);
  10048. ChargingProfileAdded = TRUE;
  10049. }
  10050. else
  10051. {
  10052. fprintf(outfile,"%s\n",buf);
  10053. }
  10054. }
  10055. }
  10056. } // end of while loop
  10057. fclose(infile);
  10058. fclose(outfile);
  10059. sprintf(rmFileCmd,"rm -f %s",filename);
  10060. system(rmFileCmd);
  10061. rename(tempfile, filename);
  10062. }
  10063. sleep(1);
  10064. result = TRUE;
  10065. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  10066. end:
  10067. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  10068. {
  10069. if(connectorIdInt == 0)
  10070. {
  10071. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  10072. {
  10073. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  10074. }
  10075. }
  10076. else
  10077. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  10078. }
  10079. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  10080. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10081. return result;
  10082. }
  10083. int handleTriggerMessageRequest(char *uuid, char *payload)
  10084. {
  10085. mtrace();
  10086. int result = FAIL;
  10087. int connectorIdIsNULL = FALSE;
  10088. int connectorIdInt =0;
  10089. char sstr[40]={0},sstrtemp[100]={ 0 };
  10090. char requestedMessagestr[40]={0};
  10091. char comfirmstr[20]={0};
  10092. int c = 0;
  10093. char *loc;
  10094. DEBUG_INFO("handleTriggerMessageRequest\n");
  10095. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  10096. strcpy(sstrtemp, stringtrimspace(payload));
  10097. c = 0;
  10098. loc = strstr(sstrtemp, "requestedMessage");
  10099. while (loc[3+strlen("requestedMessage")+c] != '\"')
  10100. {
  10101. sstr[c] = loc[3+strlen("requestedMessage")+c];
  10102. c++;
  10103. }
  10104. sstr[c] = '\0';
  10105. strcpy(requestedMessagestr, sstr);
  10106. c = 0;
  10107. loc = strstr(sstrtemp, "connectorId");
  10108. if(loc == NULL)
  10109. {
  10110. connectorIdIsNULL = TRUE;
  10111. }
  10112. else
  10113. {
  10114. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10115. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  10116. {
  10117. sstr[c] = loc[strlen("connectorId")+2+c];
  10118. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10119. c++;
  10120. }
  10121. sstr[c] = '\0';
  10122. connectorIdInt = atoi(sstr);
  10123. }
  10124. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  10125. {
  10126. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  10127. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  10128. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10129. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  10130. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  10131. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  10132. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  10133. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  10134. {
  10135. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10136. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10137. return TRUE;
  10138. }
  10139. else
  10140. {
  10141. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10142. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10143. }
  10144. }
  10145. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  10146. {
  10147. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  10148. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10149. return TRUE;
  10150. }
  10151. //==========================
  10152. // Trigger message
  10153. //==========================
  10154. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10155. {
  10156. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  10157. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  10158. {
  10159. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10160. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  10161. }
  10162. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10163. }
  10164. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  10165. {
  10166. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  10167. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10168. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10169. }
  10170. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  10171. {
  10172. //sendBootNotificationRequest();
  10173. server_sign = FALSE;
  10174. }
  10175. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  10176. {
  10177. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  10178. }
  10179. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  10180. {
  10181. if(connectorIdIsNULL == FALSE)
  10182. {
  10183. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  10184. {
  10185. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  10186. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  10187. }
  10188. }
  10189. else
  10190. {
  10191. for(int idx=0;idx< gunTotalNumber;idx++)
  10192. {
  10193. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10194. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10195. }
  10196. }
  10197. }
  10198. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  10199. {
  10200. if(connectorIdIsNULL == FALSE)
  10201. {
  10202. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  10203. {
  10204. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  10205. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  10206. }
  10207. }
  10208. else
  10209. {
  10210. for(int idx=0;idx< gunTotalNumber;idx++)
  10211. {
  10212. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  10213. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  10214. }
  10215. }
  10216. }
  10217. return result;
  10218. }
  10219. int handleUnlockConnectorRequest(char *uuid, char *payload)
  10220. {
  10221. mtrace();
  10222. int result = FAIL;
  10223. int connectorIdInt =0;
  10224. char comfirmstr[20]={0};
  10225. int tempIndex = 0;
  10226. json_object *UnlockConnector;
  10227. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  10228. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  10229. UnlockConnector = json_tokener_parse(payload);
  10230. if(!is_error(UnlockConnector))
  10231. {
  10232. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  10233. {
  10234. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  10235. }
  10236. }
  10237. json_object_put(UnlockConnector);
  10238. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  10239. if(gunTotalNumber == 0)
  10240. {
  10241. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10242. goto end;
  10243. }
  10244. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  10245. {
  10246. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10247. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10248. goto end;
  10249. }
  10250. else
  10251. {
  10252. //check Transaction active
  10253. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  10254. {
  10255. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10256. {
  10257. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10258. }
  10259. else
  10260. {
  10261. tempIndex = connectorIdInt -1;
  10262. }
  10263. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10264. {
  10265. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10266. {
  10267. //stop Transaction
  10268. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10269. }
  10270. }
  10271. }
  10272. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  10273. {
  10274. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10275. {
  10276. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10277. }
  10278. else
  10279. {
  10280. tempIndex = connectorIdInt -1;
  10281. }
  10282. for (int index = 0; index < CCS_QUANTITY; index++)
  10283. {
  10284. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10285. {
  10286. //stop Transaction
  10287. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10288. }
  10289. }
  10290. }
  10291. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  10292. {
  10293. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10294. {
  10295. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10296. }
  10297. else
  10298. {
  10299. tempIndex = connectorIdInt -1;
  10300. }
  10301. for (int index = 0; index < GB_QUANTITY; index++)
  10302. {
  10303. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  10304. {
  10305. //stop Transaction
  10306. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10307. }
  10308. }
  10309. }
  10310. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  10311. {
  10312. tempIndex = connectorIdInt -1;
  10313. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10314. {
  10315. 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)))
  10316. {
  10317. //stop Transaction
  10318. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10319. }
  10320. }
  10321. }
  10322. else
  10323. {
  10324. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10325. {
  10326. tempIndex = 2;
  10327. }
  10328. else
  10329. {
  10330. tempIndex = connectorIdInt-1;
  10331. }
  10332. for (int index = 0; index < AC_QUANTITY; index++)
  10333. {
  10334. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10335. {
  10336. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10337. }
  10338. }
  10339. }
  10340. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  10341. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  10342. result = TRUE;
  10343. return result;
  10344. }
  10345. end:
  10346. //json_object_put(obj); --- remove temporally
  10347. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  10348. return result;
  10349. }
  10350. static char UpdateFirmwarepayloadData[300]={0};
  10351. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  10352. {
  10353. mtrace();
  10354. int result = FAIL;
  10355. pthread_t t;
  10356. sendUpdateFirmwareConfirmation(uuid);
  10357. memset(UpdateFirmwarepayloadData, 0, 300);
  10358. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  10359. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  10360. ////pthread_join(t, NULL); //
  10361. //pthread_detach(t);
  10362. //sendUpdateFirmwareConfirmation(uuid);
  10363. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  10364. return result;
  10365. }
  10366. void *UpdateFirmwareProcess(void *data)
  10367. {
  10368. pthread_detach(pthread_self());
  10369. mtrace();
  10370. int retriesInt =0, retryIntervalInt=0;
  10371. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  10372. int port=0;
  10373. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  10374. int isSuccess = 0;
  10375. char ftpbuf[1024];
  10376. char temp[1024];
  10377. char * pch;
  10378. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  10379. json_object *UpdateFirmware;
  10380. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  10381. if(!is_error(UpdateFirmware))
  10382. {
  10383. // Required data
  10384. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  10385. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  10386. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  10387. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  10388. // Optional data
  10389. if(json_object_object_get(UpdateFirmware, "retries"))
  10390. {
  10391. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  10392. }
  10393. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  10394. {
  10395. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  10396. }
  10397. }
  10398. json_object_put(UpdateFirmware);
  10399. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10400. memset(path, 0, ARRAY_SIZE(path));
  10401. // Wait retrieveData
  10402. if(strlen(retrieveDatestr) > 10)
  10403. {
  10404. do
  10405. {
  10406. sleep(1);
  10407. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  10408. }
  10409. // Ready to download
  10410. system("rm -f /mnt/*");
  10411. if(strncmp(locationstr,"http", 4) == 0)
  10412. {
  10413. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10414. sprintf(ftppath,"/%s", path);
  10415. DEBUG_INFO("locationstr: %s\n", locationstr);
  10416. DEBUG_INFO("protocol: %s\n",protocol);
  10417. DEBUG_INFO("host: %s\n",host);
  10418. DEBUG_INFO("path: %s\n",path);
  10419. DEBUG_INFO("ftppath: %s\n",ftppath);
  10420. int ftppathlen=strlen(ftppath);
  10421. int i=1;
  10422. char filenametemp[50];
  10423. while(i < ftppathlen)
  10424. {
  10425. int len=ftppathlen-i;
  10426. if(ftppath[len]== 47) // '/' ascll code: 47
  10427. {
  10428. DEBUG_INFO("compare '/' all right\n");
  10429. break;
  10430. }
  10431. i=i+1;
  10432. }
  10433. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10434. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10435. filenametemp[i+1] = 0;
  10436. do
  10437. {
  10438. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  10439. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10440. sleep(1);
  10441. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  10442. if(!isSuccess)
  10443. {
  10444. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10445. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10446. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  10447. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10448. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10449. }
  10450. else
  10451. {
  10452. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10453. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10454. }
  10455. retriesInt--;
  10456. }while((isSuccess == 0)&&(retriesInt >= 0));
  10457. }
  10458. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  10459. {
  10460. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  10461. memset(temp, 0, ARRAY_SIZE(temp));
  10462. //DEBUG_INFO("locationstr=%s\n",locationstr);
  10463. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  10464. int ftppathlen=strlen(ftpbuf);
  10465. int i=1;
  10466. char filenametemp[50];
  10467. while(i < ftppathlen)
  10468. {
  10469. int len=ftppathlen-i;
  10470. if(ftpbuf[len]== 47) // '/' ascll code: 47
  10471. {
  10472. DEBUG_INFO(" compare '/' all right\n");
  10473. break;
  10474. }
  10475. i=i+1;
  10476. }
  10477. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10478. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  10479. filenametemp[i+1] = 0;
  10480. strncpy(temp, ftpbuf, ftppathlen-i+1);
  10481. pch=strchr(temp,'@');
  10482. if(pch==NULL)
  10483. {
  10484. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10485. protocol, host, &port, path);
  10486. strcpy(user,"anonymous");
  10487. strcpy(password,"");
  10488. }
  10489. else
  10490. {
  10491. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10492. protocol, user, password, host, &port, path);
  10493. }
  10494. sscanf(host,"%[^/]%s",host1, path1);
  10495. sprintf(ftppath,"%s", path1);
  10496. //DEBUG_INFO("protocol =%s\n",protocol);
  10497. //DEBUG_INFO("user =%s\n",user);
  10498. //DEBUG_INFO("password =%s\n",password);
  10499. //DEBUG_INFO("host1 =%s\n",host1);
  10500. //DEBUG_INFO("port =%d\n",port);
  10501. //DEBUG_INFO("path1 =%s\n",path1);
  10502. //DEBUG_INFO("ftppath=%s\n",ftppath);
  10503. //ftpFile(host, user, password, port, ftppath, fname);
  10504. //download firmware pthred
  10505. if(port == 0)
  10506. {
  10507. port = 21;
  10508. }
  10509. do
  10510. {
  10511. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  10512. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10513. sleep(1);
  10514. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  10515. if(!isSuccess)
  10516. {
  10517. //BulldogUtil.sleepMs(interval*1000);
  10518. DEBUG_INFO("Update firmware request and download file fail.\n");
  10519. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10520. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10521. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  10522. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10523. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10524. }
  10525. else
  10526. {
  10527. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10528. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10529. }
  10530. retriesInt--;
  10531. }while((!isSuccess)&&(retriesInt >= 0));
  10532. }
  10533. else
  10534. {
  10535. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10536. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10537. sleep(1);
  10538. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10539. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10540. }
  10541. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  10542. pthread_exit(NULL);
  10543. }
  10544. int handleCertificateSignedRequest(char *uuid, char *payload)
  10545. {
  10546. mtrace();
  10547. int result = PASS;
  10548. json_object *CertificateSigned;
  10549. DEBUG_INFO("handleCertificateSignedRequest...\n");
  10550. CertificateSigned = json_tokener_parse(payload);
  10551. if(!is_error(CertificateSigned))
  10552. {
  10553. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  10554. }
  10555. json_object_put(CertificateSigned);
  10556. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  10557. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  10558. fclose(fp);
  10559. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10560. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  10561. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  10562. sendCertificateSignedConfirmation(uuid);
  10563. return result;
  10564. }
  10565. int handleDeleteCertificateRequest(char *uuid, char *payload)
  10566. {
  10567. mtrace();
  10568. int result = PASS;
  10569. json_object *DeleteCertificate;
  10570. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  10571. DeleteCertificate = json_tokener_parse(payload);
  10572. if(!is_error(DeleteCertificate))
  10573. {
  10574. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  10575. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  10576. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  10577. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  10578. }
  10579. json_object_put(DeleteCertificate);
  10580. /*
  10581. * TODO: Delete certificateSigned process
  10582. */
  10583. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  10584. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  10585. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  10586. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  10587. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  10588. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  10589. sendDeleteCertificateConfirmation(uuid);
  10590. return result;
  10591. }
  10592. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  10593. {
  10594. mtrace();
  10595. int result = PASS;
  10596. json_object *ExtendedTriggerMessage;
  10597. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  10598. ExtendedTriggerMessage = json_tokener_parse(payload);
  10599. if(!is_error(ExtendedTriggerMessage))
  10600. {
  10601. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  10602. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  10603. {
  10604. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  10605. }
  10606. else
  10607. {
  10608. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  10609. }
  10610. }
  10611. json_object_put(ExtendedTriggerMessage);
  10612. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  10613. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  10614. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  10615. {
  10616. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  10617. }
  10618. else
  10619. {
  10620. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  10621. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  10622. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10623. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  10624. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  10625. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  10626. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  10627. {
  10628. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10629. }
  10630. else
  10631. {
  10632. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10633. }
  10634. }
  10635. sendExtendedTriggerMessageConfirmation(uuid);
  10636. //==========================
  10637. // Trigger message
  10638. //==========================
  10639. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  10640. {
  10641. //sendBootNotificationRequest();
  10642. server_sign = FALSE;
  10643. }
  10644. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  10645. {
  10646. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  10647. }
  10648. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10649. {
  10650. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  10651. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  10652. {
  10653. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10654. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  10655. }
  10656. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10657. }
  10658. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  10659. {
  10660. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  10661. }
  10662. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  10663. {
  10664. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  10665. {
  10666. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  10667. }
  10668. else
  10669. {
  10670. for(int idx=0;idx< gunTotalNumber;idx++)
  10671. {
  10672. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10673. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10674. }
  10675. }
  10676. }
  10677. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  10678. {
  10679. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  10680. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  10681. {
  10682. 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\" &");
  10683. }
  10684. }
  10685. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  10686. {
  10687. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  10688. {
  10689. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  10690. }
  10691. else
  10692. {
  10693. for(int idx=0;idx< gunTotalNumber;idx++)
  10694. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  10695. }
  10696. }
  10697. return result;
  10698. }
  10699. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  10700. {
  10701. mtrace();
  10702. int result = PASS;
  10703. json_object *GetInstalledCertificateIds;
  10704. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  10705. GetInstalledCertificateIds = json_tokener_parse(payload);
  10706. if(!is_error(GetInstalledCertificateIds))
  10707. {
  10708. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  10709. }
  10710. json_object_put(GetInstalledCertificateIds);
  10711. /*
  10712. * TODO: Return installed certificate process
  10713. */
  10714. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  10715. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  10716. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  10717. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  10718. sendGetInstalledCertificateIdsConfirmation(uuid);
  10719. return result;
  10720. }
  10721. int handleGetLogRequest(char *uuid, char *payload)
  10722. {
  10723. mtrace();
  10724. int result = PASS;
  10725. json_object *GetLog;
  10726. DEBUG_INFO("handleGetLogRequest...\n");
  10727. GetLog = json_tokener_parse(payload);
  10728. if(!is_error(GetLog))
  10729. {
  10730. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  10731. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  10732. if(json_object_object_get(GetLog, "retries") != NULL)
  10733. {
  10734. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  10735. }
  10736. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  10737. {
  10738. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  10739. }
  10740. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  10741. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  10742. {
  10743. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  10744. }
  10745. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  10746. {
  10747. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  10748. }
  10749. }
  10750. json_object_put(GetLog);
  10751. /*
  10752. * TODO: Upload log process
  10753. */
  10754. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  10755. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  10756. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  10757. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  10758. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  10759. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  10760. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  10761. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  10762. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  10763. sendGetLogConfirmation(uuid);
  10764. return result;
  10765. }
  10766. int handleInstallCertificateRequest(char *uuid, char *payload)
  10767. {
  10768. mtrace();
  10769. int result = PASS;
  10770. json_object *InstallCertificate;
  10771. DEBUG_INFO("handleInstallCertificateRequest...\n");
  10772. InstallCertificate = json_tokener_parse(payload);
  10773. if(!is_error(InstallCertificate))
  10774. {
  10775. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  10776. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  10777. /*
  10778. * TODO: Install certificate process
  10779. */
  10780. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  10781. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  10782. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  10783. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  10784. sendInstallCertificateConfirmation(uuid);
  10785. }
  10786. json_object_put(InstallCertificate);
  10787. return result;
  10788. }
  10789. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  10790. {
  10791. mtrace();
  10792. int result = PASS;
  10793. json_object *SignedUpdateFirmware;
  10794. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  10795. SignedUpdateFirmware = json_tokener_parse(payload);
  10796. if(!is_error(SignedUpdateFirmware))
  10797. {
  10798. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  10799. {
  10800. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  10801. }
  10802. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  10803. {
  10804. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  10805. }
  10806. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  10807. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  10808. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  10809. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  10810. {
  10811. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  10812. }
  10813. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  10814. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  10815. }
  10816. json_object_put(SignedUpdateFirmware);
  10817. /*
  10818. * TODO: Upgrade firmware process
  10819. */
  10820. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  10821. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  10822. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  10823. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  10824. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  10825. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  10826. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  10827. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  10828. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  10829. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  10830. sendInstallCertificateConfirmation(uuid);
  10831. return result;
  10832. }
  10833. int handleUnknownRequest(char *uuid, char *payload)
  10834. {
  10835. mtrace();
  10836. int result = PASS;
  10837. DEBUG_INFO("handleUnknownRequest...\n");
  10838. sendUnknownConfirmation(uuid);
  10839. result = PASS;
  10840. return result;
  10841. }
  10842. //==========================================
  10843. // Handle server response routine
  10844. //==========================================
  10845. void handleAuthorizeResponse(char *payload, int gun_index)
  10846. {
  10847. mtrace();
  10848. char expiryDatestr[30]={0};
  10849. char parentIdTagstr[20]={0};
  10850. char statusstr[20]={0};
  10851. int expiryDateISNULL=FALSE;
  10852. int parentIdTagISNULL=FALSE;
  10853. DEBUG_INFO("handleAuthorizeResponse...\n");
  10854. json_object *Authorize;
  10855. Authorize = json_tokener_parse(payload);
  10856. if(!is_error(Authorize))
  10857. {
  10858. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  10859. {
  10860. // Required data
  10861. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  10862. // Optional data
  10863. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  10864. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  10865. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  10866. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  10867. }
  10868. }
  10869. json_object_put(Authorize);
  10870. if(expiryDateISNULL == FALSE)
  10871. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  10872. if(parentIdTagISNULL == FALSE)
  10873. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  10874. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  10875. //Update idTag information to authorization cache if supproted
  10876. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  10877. {
  10878. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  10879. }
  10880. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  10881. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  10882. authorizeRetryTimes = 0;
  10883. }
  10884. void handleBootNotificationResponse(char *payload, int gun_index)
  10885. {
  10886. mtrace();
  10887. char statusStr[12]={0};
  10888. char currentTimeStr[30]={0};
  10889. int intervalInt = 0;
  10890. DEBUG_INFO("handleBootNotificationResponse...\n");
  10891. json_object *BootNotification;
  10892. BootNotification = json_tokener_parse(payload);
  10893. if(!is_error(BootNotification))
  10894. {
  10895. // Required data
  10896. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  10897. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  10898. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  10899. }
  10900. json_object_put(BootNotification);
  10901. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10902. BootNotificationInterval = intervalInt;
  10903. HeartBeatWaitTime = intervalInt;
  10904. //write back to ShmOCPP16Data->BootNotification
  10905. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  10906. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10907. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  10908. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  10909. {
  10910. server_sign = TRUE;
  10911. server_pending =FALSE;
  10912. }
  10913. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  10914. {
  10915. server_pending = TRUE;
  10916. }
  10917. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  10918. srand(time(NULL));
  10919. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  10920. SetOcppConnStatus(TRUE);
  10921. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  10922. }
  10923. void handleDataTransferResponse(char *payload, int gun_index)
  10924. {
  10925. char sstr[160]={0};//sstr[200]={ 0 };
  10926. int c = 0;
  10927. char *loc;
  10928. DEBUG_INFO("handleDataTransferResponse ...\n");
  10929. loc = strstr(payload, "status");
  10930. printf("loc=%s\n",loc);
  10931. c = 0;
  10932. while (loc[3+strlen("status")+c] != '\"')
  10933. {
  10934. sstr[c] = loc[3+strlen("status")+c];
  10935. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10936. c++;
  10937. }
  10938. sstr[c] = '\0';
  10939. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  10940. }
  10941. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  10942. {
  10943. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  10944. //struct json_object *obj;
  10945. // obj = json_tokener_parse(payload);
  10946. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  10947. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  10948. //No fields are defined.
  10949. }
  10950. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  10951. {
  10952. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  10953. //struct json_object *obj;
  10954. // obj = json_tokener_parse(payload);
  10955. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  10956. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  10957. //No fields are defined.
  10958. }
  10959. void handleHeartbeatResponse(char *payload, int gun_index)
  10960. {
  10961. mtrace();
  10962. DEBUG_INFO("handleHeartbeatResponse...\n");
  10963. json_object *Heartbeat;
  10964. Heartbeat = json_tokener_parse(payload);
  10965. if(!is_error(Heartbeat))
  10966. {
  10967. // Required data
  10968. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  10969. }
  10970. json_object_put(Heartbeat);
  10971. if(FirstHeartBeat == 0)
  10972. {
  10973. FirstHeartBeat = 1;
  10974. DEBUG_INFO("FirstHeartBeat \n");
  10975. }
  10976. HeartBeatWithNOResponse = 0;
  10977. clientTime.Heartbeat=time((time_t*)NULL);
  10978. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  10979. }
  10980. void handleMeterValuesResponse(char *payload, int gun_index)
  10981. {
  10982. mtrace();
  10983. DEBUG_INFO("handleMeterValuesResponse...\n");
  10984. }
  10985. void handleStartTransactionResponse(char *payload, int gun_index)
  10986. {
  10987. mtrace();
  10988. //int transactionIdInt = 0;
  10989. FILE *outfile;
  10990. char data[100]={0};
  10991. DEBUG_INFO("handleStartTransactionResponse...\n");
  10992. json_object *StartTransaction;
  10993. StartTransaction = json_tokener_parse(payload);
  10994. if(!is_error(StartTransaction))
  10995. {
  10996. // Required data
  10997. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  10998. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  10999. // Optional data
  11000. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  11001. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  11002. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11003. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  11004. }
  11005. json_object_put(StartTransaction);
  11006. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  11007. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  11008. //-----------Start : write to the Queue TransactionId file -----------------//
  11009. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  11010. {}
  11011. else
  11012. {
  11013. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  11014. if(log == NULL)
  11015. {
  11016. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  11017. return ;
  11018. }
  11019. else
  11020. {
  11021. fclose(log);
  11022. }
  11023. }
  11024. // open file for writing
  11025. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  11026. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  11027. {
  11028. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  11029. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  11030. fputs(data, outfile);
  11031. fclose (outfile);
  11032. }
  11033. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11034. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11035. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  11036. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  11037. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11038. }
  11039. void handleStatusNotificationResponse(char *payload, int gun_index)
  11040. {
  11041. mtrace();
  11042. DEBUG_INFO("handleStatusNotificationResponse...\n");
  11043. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  11044. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  11045. }
  11046. void handleStopTransactionnResponse(char *payload, int gun_index)
  11047. {
  11048. mtrace();
  11049. DEBUG_INFO("handleStopTransactionnResponse...\n");
  11050. json_object *StopTransaction;
  11051. StopTransaction = json_tokener_parse(payload);
  11052. if(!is_error(StopTransaction))
  11053. {
  11054. // Optional data
  11055. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  11056. {
  11057. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  11058. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  11059. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  11060. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11061. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  11062. }
  11063. }
  11064. json_object_put(StopTransaction);
  11065. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  11066. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  11067. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11068. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11069. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  11070. }
  11071. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  11072. {
  11073. mtrace();
  11074. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  11075. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  11076. }
  11077. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  11078. {
  11079. mtrace();
  11080. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  11081. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  11082. }
  11083. void handleSignCertificateResponse(char *payload, int gun_index)
  11084. {
  11085. mtrace();
  11086. DEBUG_INFO("handleSignCertificateResponse...\n");
  11087. json_object *SignCertificate;
  11088. SignCertificate = json_tokener_parse(payload);
  11089. if(!is_error(SignCertificate))
  11090. {
  11091. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  11092. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  11093. }
  11094. json_object_put(SignCertificate);
  11095. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  11096. }
  11097. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11098. {
  11099. mtrace();
  11100. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  11101. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  11102. }
  11103. //==========================================
  11104. // Handle Error routine
  11105. //==========================================
  11106. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  11107. {
  11108. mtrace();
  11109. #ifdef SystemLogMessage
  11110. DEBUG_INFO("errorCode: %s\n", errorCode);
  11111. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  11112. DEBUG_INFO("errorDetails: %s\n", payload);
  11113. #endif
  11114. }
  11115. //===============================================
  11116. // Common routine
  11117. //===============================================
  11118. int initialConfigurationTable(void)
  11119. {
  11120. //clock_t start_t, end_t, total_t;
  11121. FILE *fp;
  11122. FILE *outfile;
  11123. char str[512]={0};
  11124. char sstr[256]={0};
  11125. int c = 0;
  11126. char *loc;
  11127. int confVersion = 2;
  11128. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  11129. //start_t = clock();
  11130. //printf("Starting of the program, start_t = %ld\n", start_t);
  11131. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  11132. // Check configuration file size is correct
  11133. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  11134. {
  11135. struct stat st;
  11136. stat("/Storage/OCPP/OCPPConfiguration", &st);
  11137. if(st.st_size < 3100)
  11138. {
  11139. system("rm -f /Storage/OCPP/OCPPConfiguration");
  11140. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  11141. }
  11142. }
  11143. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  11144. {
  11145. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  11146. if(outfile == NULL)
  11147. {
  11148. DEBUG_INFO("Error opening file\n");
  11149. return FALSE;
  11150. }
  11151. /*Core Profile*/
  11152. //AllowOfflineTxForUnknownId
  11153. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11154. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11155. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  11156. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11157. //AuthorizationCacheEnabled
  11158. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11159. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11160. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11161. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11162. //AuthorizeRemoteTxRequests
  11163. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11164. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11165. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  11166. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11167. //BlinkRepeat
  11168. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11169. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11170. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11171. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11172. //ClockAlignedDataInterval
  11173. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11174. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11175. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11176. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11177. //ConnectionTimeOut
  11178. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11179. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11180. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11181. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11182. //GetConfigurationMaxKeys
  11183. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11184. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11185. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  11186. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11187. // HeartbeatInterval
  11188. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11189. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11190. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  11191. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11192. // LightIntensity
  11193. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11194. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11195. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11196. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11197. // LocalAuthorizeOffline
  11198. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  11199. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11200. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11201. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11202. // LocalPreAuthorize
  11203. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  11204. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11205. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11206. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11207. // MaxEnergyOnInvalidId
  11208. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11209. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  11210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  11211. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  11212. // MeterValuesAlignedData
  11213. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  11214. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  11215. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11216. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11217. else
  11218. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11219. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  11220. // MeterValuesAlignedDataMaxLength
  11221. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  11222. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  11223. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11224. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  11225. else
  11226. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "9" );
  11227. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  11228. // MeterValuesSampledData
  11229. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  11230. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  11231. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11232. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11233. else
  11234. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11235. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  11236. // MeterValuesSampledDataMaxLength
  11237. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  11238. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  11239. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11240. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  11241. else
  11242. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "9" );
  11243. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  11244. // MeterValueSampleInterval
  11245. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  11246. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  11247. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  11248. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  11249. // MinimumStatusDuration
  11250. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  11251. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  11252. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  11253. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  11254. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  11255. // NumberOfConnectors
  11256. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  11257. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  11258. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11259. {
  11260. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  11261. }
  11262. else
  11263. {
  11264. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  11265. }
  11266. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  11267. // ResetRetries
  11268. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  11269. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  11270. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  11271. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  11272. // ConnectorPhaseRotation
  11273. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  11274. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  11275. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  11276. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  11277. // ConnectorPhaseRotationMaxLength
  11278. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  11279. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  11280. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  11281. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  11282. // StopTransactionOnEVSideDisconnect
  11283. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  11284. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  11285. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  11286. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  11287. // StopTransactionOnInvalidId
  11288. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  11289. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  11290. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  11291. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  11292. // StopTxnAlignedData
  11293. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  11294. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  11295. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  11296. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  11297. // StopTxnAlignedDataMaxLength
  11298. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  11299. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  11300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11301. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11302. // StopTxnSampledData
  11303. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11304. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11305. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11306. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11307. else
  11308. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11309. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11310. // StopTxnSampledDataMaxLength
  11311. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11312. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11313. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11314. {
  11315. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  11316. }
  11317. else
  11318. {
  11319. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  11320. }
  11321. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11322. // SupportedFeatureProfiles
  11323. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11324. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11325. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11326. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  11327. // SupportedFeatureProfilesMaxLength
  11328. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  11329. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  11330. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  11331. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  11332. // TransactionMessageAttempts
  11333. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11334. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11335. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11336. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11337. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11338. // TransactionMessageRetryInterval
  11339. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11340. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11341. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11342. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11343. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11344. // UnlockConnectorOnEVSideDisconnect
  11345. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11346. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11347. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11348. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11349. // WebSocketPingInterval
  11350. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11351. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11352. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11353. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11354. // QueueOffLineStartTransactionMessage
  11355. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  11356. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  11357. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  11358. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  11359. // AuthorizationKey
  11360. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  11361. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  11362. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "" );
  11363. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  11364. // SecurityProfile
  11365. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  11366. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  11367. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "0" );
  11368. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  11369. // DefaultPrice
  11370. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  11371. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  11372. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  11373. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  11374. // CustomDisplayCostAndPrice
  11375. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  11376. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  11377. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  11378. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  11379. // CustomIdleFeeAfterStop
  11380. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  11381. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  11382. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  11383. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  11384. // Configuration Version
  11385. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  11386. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  11387. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  11388. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  11389. //* Local Auth List Management Profile*/
  11390. #if 0
  11391. //For OCTT Test Case
  11392. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11393. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  11394. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11395. #endif
  11396. #if 1
  11397. //LocalAuthListEnabled
  11398. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11399. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  11400. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11401. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11402. #endif
  11403. //LocalAuthListMaxLength
  11404. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  11405. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  11406. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  11407. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  11408. //SendLocalListMaxLength
  11409. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  11410. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11411. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  11412. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11413. //ReserveConnectorZeroSupported
  11414. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11415. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11416. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11417. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11418. //* Smart Charging Profile */
  11419. //ChargeProfileMaxStackLevel
  11420. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11421. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11422. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11423. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11424. // ChargingScheduleAllowedChargingRateUnit
  11425. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11426. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11427. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  11428. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11429. // ChargingScheduleMaxPeriods
  11430. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11431. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11432. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11433. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11434. // ConnectorSwitch3to1PhaseSupported
  11435. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11436. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11437. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  11438. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11439. // MaxChargingProfilesInstalled
  11440. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11441. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11442. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  11443. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11444. fclose(outfile);
  11445. }
  11446. else
  11447. {
  11448. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  11449. char keystr[60]={0};
  11450. char readonlystr[10]={0};
  11451. char valuestr[256]={0};
  11452. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  11453. if(fp == NULL) {
  11454. DEBUG_INFO("Error opening file");
  11455. return FALSE;
  11456. }
  11457. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  11458. {
  11459. //DEBUG_INFO("Get Configuration \n");
  11460. if(strlen(str) > 0)
  11461. {
  11462. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  11463. //*************************key*********************************/
  11464. if(strstr(str, "key") != NULL)
  11465. {
  11466. loc = strstr(str, "key");
  11467. c = 0;
  11468. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11469. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  11470. {
  11471. sstr[c] = loc[strlen("key")+3+c];
  11472. c++;
  11473. }
  11474. sstr[c] = '\0';
  11475. strcpy(keystr,sstr);
  11476. }
  11477. //*************************readonly*********************************/
  11478. if(strstr(str, "readonly") != NULL)
  11479. {
  11480. loc = strstr(str, "readonly");
  11481. c = 0;
  11482. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11483. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  11484. {
  11485. sstr[c] = loc[strlen("readonly")+2+c];
  11486. c++;
  11487. }
  11488. sstr[c] = '\0';
  11489. strcpy(readonlystr,sstr);
  11490. }
  11491. //*************************value*********************************/
  11492. if(strstr(str, "value") != NULL)
  11493. {
  11494. loc = strstr(str, "value");
  11495. c = 0;
  11496. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11497. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  11498. {
  11499. sstr[c] = loc[strlen("value")+3+c];
  11500. c++;
  11501. }
  11502. sstr[c] = '\0';
  11503. strcpy(valuestr,sstr);
  11504. }
  11505. // DEBUG_INFO("keystr=%s\n",keystr);
  11506. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  11507. // DEBUG_INFO("valuestr=%s\n",valuestr);
  11508. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  11509. {
  11510. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11511. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11512. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  11513. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  11514. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  11515. }
  11516. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  11517. {
  11518. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11519. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11520. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  11521. }
  11522. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  11523. {
  11524. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11525. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  11526. }
  11527. if(strcmp(keystr, "BlinkRepeat") == 0)
  11528. {
  11529. //Charger.BlinkRepeat = Integer.parseInt(value);
  11530. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11531. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  11532. }
  11533. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  11534. {
  11535. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11536. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  11537. }
  11538. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  11539. {
  11540. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11541. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  11542. }
  11543. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  11544. {
  11545. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11546. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  11547. }
  11548. if(strcmp(keystr, "HeartbeatInterval") == 0)
  11549. {
  11550. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11551. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  11552. HeartBeatWaitTime = atoi(valuestr);
  11553. }
  11554. if(strcmp(keystr, "LightIntensity") == 0)
  11555. {
  11556. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11557. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  11558. }
  11559. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  11560. {
  11561. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11562. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  11563. }
  11564. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  11565. {
  11566. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11567. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  11568. }
  11569. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  11570. {
  11571. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11572. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  11573. }
  11574. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  11575. {
  11576. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11577. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  11578. }
  11579. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  11580. {
  11581. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11582. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  11583. }
  11584. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  11585. {
  11586. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11587. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  11588. }
  11589. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  11590. {
  11591. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11592. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  11593. }
  11594. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  11595. {
  11596. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11597. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  11598. }
  11599. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  11600. {
  11601. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11602. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  11603. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  11604. }
  11605. if(strcmp(keystr, "NumberOfConnectors") == 0)
  11606. {
  11607. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11608. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  11609. }
  11610. if(strcmp(keystr, "ResetRetries") == 0)
  11611. {
  11612. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11613. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  11614. }
  11615. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  11616. {
  11617. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11618. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  11619. }
  11620. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  11621. {
  11622. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11623. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  11624. }
  11625. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  11626. {
  11627. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11628. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  11629. }
  11630. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  11631. {
  11632. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11633. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  11634. }
  11635. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  11636. {
  11637. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11638. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  11639. }
  11640. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  11641. {
  11642. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11643. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11644. }
  11645. if(strcmp(keystr, "StopTxnSampledData") == 0)
  11646. {
  11647. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11648. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  11649. }
  11650. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  11651. {
  11652. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11653. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11654. }
  11655. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  11656. {
  11657. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11658. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  11659. }
  11660. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  11661. {
  11662. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11663. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  11664. }
  11665. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  11666. {
  11667. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11668. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  11669. TransactionMessageAttemptsValue = atoi(valuestr);
  11670. }
  11671. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  11672. {
  11673. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11674. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  11675. TransactionMessageRetryIntervalValue = atoi(valuestr);
  11676. }
  11677. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  11678. {
  11679. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11680. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  11681. }
  11682. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  11683. {
  11684. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11685. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  11686. }
  11687. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  11688. {
  11689. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11690. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  11691. }
  11692. if(strcmp(keystr, "AuthorizationKey") == 0)
  11693. {
  11694. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11695. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  11696. }
  11697. if(strcmp(keystr, "SecurityProfile") == 0)
  11698. {
  11699. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11700. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  11701. }
  11702. if(strcmp(keystr, "DefaultPrice") == 0)
  11703. {
  11704. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11705. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  11706. }
  11707. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  11708. {
  11709. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11710. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  11711. }
  11712. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  11713. {
  11714. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11715. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  11716. }
  11717. if(strcmp(keystr, "ConfigurationVersion") == 0)
  11718. {
  11719. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11720. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  11721. }
  11722. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  11723. {
  11724. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11725. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  11726. }
  11727. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  11728. {
  11729. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11730. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  11731. }
  11732. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  11733. {
  11734. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11735. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  11736. }
  11737. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  11738. {
  11739. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11740. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  11741. }
  11742. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  11743. {
  11744. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11745. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  11746. }
  11747. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  11748. {
  11749. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11750. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  11751. }
  11752. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  11753. {
  11754. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11755. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  11756. }
  11757. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  11758. {
  11759. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11760. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  11761. }
  11762. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  11763. {
  11764. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11765. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  11766. }
  11767. }
  11768. }
  11769. fclose(fp);
  11770. }
  11771. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  11772. {
  11773. return PASS;
  11774. }
  11775. else
  11776. {
  11777. return FAIL;
  11778. }
  11779. }
  11780. void StoreConfigurationTable(void)
  11781. {
  11782. FILE *outfile;
  11783. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  11784. if(outfile == NULL)
  11785. {
  11786. DEBUG_INFO("Error opening file");
  11787. return ;
  11788. }
  11789. /*Core Profile*/
  11790. //AllowOfflineTxForUnknownId
  11791. /*
  11792. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11793. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  11794. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  11796. */
  11797. //DEBUG_INFO("data=%s\n",data);
  11798. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11799. //AuthorizationCacheEnabled
  11800. /*
  11801. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11804. */
  11805. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11806. //AuthorizeRemoteTxRequests
  11807. /*
  11808. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11810. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  11811. */
  11812. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11813. //BlinkRepeat
  11814. /*
  11815. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11816. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11818. */
  11819. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11820. //ClockAlignedDataInterval
  11821. /*
  11822. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11825. */
  11826. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11827. //ConnectionTimeOut
  11828. /*
  11829. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11830. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11831. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11832. */
  11833. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11834. //GetConfigurationMaxKeys
  11835. /*
  11836. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11837. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11838. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  11839. */
  11840. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11841. // HeartbeatInterval
  11842. /*
  11843. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11845. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  11846. */
  11847. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11848. // LightIntensity
  11849. /*
  11850. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11852. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11853. */
  11854. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11855. // LocalAuthorizeOffline
  11856. /*
  11857. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  11858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11859. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11860. */
  11861. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11862. // LocalPreAuthorize
  11863. /*
  11864. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  11865. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11867. */
  11868. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11869. // MaxEnergyOnInvalidId
  11870. /*
  11871. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11872. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  11873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  11874. */
  11875. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  11876. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  11877. // MeterValuesAlignedData
  11878. /*
  11879. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  11880. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  11881. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  11882. */
  11883. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  11884. // MeterValuesAlignedDataMaxLength
  11885. /*
  11886. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  11887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  11888. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  11889. */
  11890. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  11891. // MeterValuesSampledData
  11892. /*
  11893. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  11894. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  11895. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  11896. */
  11897. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  11898. // MeterValuesSampledDataMaxLength
  11899. /*
  11900. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  11901. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  11902. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  11903. */
  11904. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  11905. // MeterValueSampleInterval
  11906. /*
  11907. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  11908. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  11909. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  11910. */
  11911. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  11912. // MinimumStatusDuration
  11913. /*
  11914. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  11915. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  11916. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  11917. */
  11918. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  11919. // NumberOfConnectors
  11920. /*
  11921. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  11922. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  11923. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11924. {
  11925. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  11926. }
  11927. else
  11928. {
  11929. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  11930. }
  11931. */
  11932. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  11933. // ResetRetries
  11934. /*
  11935. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  11936. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  11937. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  11938. */
  11939. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  11940. // ConnectorPhaseRotation
  11941. /*
  11942. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  11943. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  11944. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  11945. */
  11946. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  11947. // ConnectorPhaseRotationMaxLength
  11948. /*
  11949. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  11950. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  11951. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  11952. */
  11953. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  11954. // StopTransactionOnEVSideDisconnect
  11955. /*
  11956. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  11957. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  11958. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  11959. */
  11960. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  11961. // StopTransactionOnInvalidId
  11962. /*
  11963. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  11964. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  11965. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  11966. */
  11967. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  11968. // StopTxnAlignedData
  11969. /*
  11970. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  11971. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  11972. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  11973. */
  11974. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  11975. // StopTxnAlignedDataMaxLength
  11976. /*
  11977. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  11978. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  11979. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11980. */
  11981. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11982. // StopTxnSampledData
  11983. /*
  11984. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11985. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11986. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  11987. */
  11988. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11989. // StopTxnSampledDataMaxLength
  11990. /*
  11991. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11992. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11993. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  11994. */
  11995. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11996. // SupportedFeatureProfiles
  11997. /*
  11998. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11999. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12000. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12001. */
  12002. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12003. // SupportedFeatureProfilesMaxLength
  12004. /*
  12005. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12006. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12007. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12008. */
  12009. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12010. // TransactionMessageAttempts
  12011. /*
  12012. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12013. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12014. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12015. */
  12016. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12017. // TransactionMessageRetryInterval
  12018. /*
  12019. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12020. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12021. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12022. */
  12023. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12024. // UnlockConnectorOnEVSideDisconnect
  12025. /*
  12026. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12027. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12028. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12029. */
  12030. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12031. // WebSocketPingInterval
  12032. /*
  12033. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12034. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12035. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12036. */
  12037. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12038. // QueueOffLineStartTransactionMessage
  12039. /*
  12040. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  12041. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  12042. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  12043. */
  12044. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  12045. // AuthorizationKey
  12046. /*
  12047. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12048. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12049. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  12050. */
  12051. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12052. // SecurityProfile
  12053. /*
  12054. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12055. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12056. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  12057. */
  12058. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12059. // DefaultPrice
  12060. /*
  12061. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12062. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12063. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12064. */
  12065. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12066. // CustomDisplayCostAndPrice
  12067. /*
  12068. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12070. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12071. */
  12072. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12073. // CustomIdleFeeAfterStop
  12074. /*
  12075. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12077. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12078. */
  12079. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12080. // ConfigurationVersion
  12081. /*
  12082. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  12083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  12085. */
  12086. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12087. //* Local Auth List Management Profile*/
  12088. //LocalAuthListEnabled
  12089. /*
  12090. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12091. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12092. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12093. */
  12094. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12095. //LocalAuthListMaxLength
  12096. /*
  12097. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  12100. */
  12101. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12102. //SendLocalListMaxLength
  12103. /*
  12104. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12105. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12106. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  12107. */
  12108. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12109. //ReserveConnectorZeroSupported
  12110. /*
  12111. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12114. */
  12115. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12116. //* Smart Charging Profile */
  12117. //ChargeProfileMaxStackLevel
  12118. /*
  12119. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12120. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12121. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12122. */
  12123. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12124. // ChargingScheduleAllowedChargingRateUnit
  12125. /*
  12126. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12127. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12128. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  12129. */
  12130. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12131. // ChargingScheduleMaxPeriods
  12132. /*
  12133. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12134. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12135. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12136. */
  12137. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12138. // ConnectorSwitch3to1PhaseSupported
  12139. /*
  12140. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12141. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12142. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  12143. */
  12144. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12145. // MaxChargingProfilesInstalled
  12146. /*
  12147. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12148. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12149. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12150. */
  12151. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12152. fclose(outfile);
  12153. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12154. }
  12155. void getKeyValue(char *keyReq)
  12156. {
  12157. int isEmpty = FALSE;
  12158. int isKnowKey = FALSE;
  12159. DEBUG_INFO("keyReq = %s\n", keyReq);
  12160. if((keyReq == NULL) || (strlen(keyReq) == 0))
  12161. isEmpty = TRUE;
  12162. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  12163. {
  12164. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  12165. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  12166. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  12167. {
  12168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  12169. }
  12170. else
  12171. {
  12172. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  12173. }
  12174. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  12175. isKnowKey = TRUE;
  12176. }
  12177. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  12178. {
  12179. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  12180. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  12181. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  12182. {
  12183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  12184. }
  12185. else
  12186. {
  12187. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  12188. }
  12189. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  12190. isKnowKey = TRUE;
  12191. }
  12192. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  12193. {
  12194. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  12195. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  12196. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  12197. {
  12198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  12199. }
  12200. else
  12201. {
  12202. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  12203. }
  12204. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  12205. isKnowKey = TRUE;
  12206. }
  12207. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  12208. {
  12209. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  12210. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  12211. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  12212. {
  12213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  12214. }
  12215. else
  12216. {
  12217. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  12218. }
  12219. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  12220. isKnowKey = TRUE;
  12221. }
  12222. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  12223. {
  12224. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  12225. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  12226. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  12227. {
  12228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  12229. }
  12230. else
  12231. {
  12232. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  12233. }
  12234. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  12235. isKnowKey = TRUE;
  12236. }
  12237. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  12238. {
  12239. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  12240. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  12241. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  12242. {
  12243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  12244. }
  12245. else
  12246. {
  12247. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  12248. }
  12249. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  12250. isKnowKey = TRUE;
  12251. }
  12252. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  12253. {
  12254. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  12255. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  12256. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  12257. {
  12258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  12259. }
  12260. else
  12261. {
  12262. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  12263. }
  12264. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  12265. isKnowKey = TRUE;
  12266. }
  12267. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  12268. {
  12269. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  12270. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  12271. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  12272. {
  12273. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  12274. }
  12275. else
  12276. {
  12277. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  12278. }
  12279. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  12280. isKnowKey = TRUE;
  12281. }
  12282. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  12283. {
  12284. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  12285. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  12286. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  12287. {
  12288. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  12289. }
  12290. else
  12291. {
  12292. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  12293. }
  12294. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  12295. isKnowKey = TRUE;
  12296. }
  12297. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  12298. {
  12299. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  12300. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  12301. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  12302. {
  12303. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  12304. }
  12305. else
  12306. {
  12307. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  12308. }
  12309. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  12310. isKnowKey = TRUE;
  12311. }
  12312. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  12313. {
  12314. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  12315. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  12316. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12317. {
  12318. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  12319. }
  12320. else
  12321. {
  12322. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  12323. }
  12324. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  12325. isKnowKey = TRUE;
  12326. }
  12327. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  12328. {
  12329. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  12330. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  12331. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  12332. {
  12333. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  12334. }
  12335. else
  12336. {
  12337. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  12338. }
  12339. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  12340. isKnowKey = TRUE;
  12341. }
  12342. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  12343. {
  12344. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  12345. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  12346. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12347. {
  12348. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  12349. }
  12350. else
  12351. {
  12352. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  12353. }
  12354. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  12355. isKnowKey = TRUE;
  12356. }
  12357. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  12358. {
  12359. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  12360. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  12361. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12362. {
  12363. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12364. }
  12365. else
  12366. {
  12367. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12368. }
  12369. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  12370. isKnowKey = TRUE;
  12371. }
  12372. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  12373. {
  12374. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  12375. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  12376. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12377. {
  12378. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  12379. }
  12380. else
  12381. {
  12382. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  12383. }
  12384. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  12385. isKnowKey = TRUE;
  12386. }
  12387. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  12388. {
  12389. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  12390. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  12391. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12392. {
  12393. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12394. }
  12395. else
  12396. {
  12397. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12398. }
  12399. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  12400. isKnowKey = TRUE;
  12401. }
  12402. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  12403. {
  12404. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  12405. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  12406. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12407. {
  12408. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  12409. }
  12410. else
  12411. {
  12412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  12413. }
  12414. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  12415. isKnowKey = TRUE;
  12416. }
  12417. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  12418. {
  12419. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  12420. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  12421. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12422. {
  12423. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  12424. }
  12425. else
  12426. {
  12427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  12428. }
  12429. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  12430. isKnowKey = TRUE;
  12431. }
  12432. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  12433. {
  12434. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  12435. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  12436. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12437. {
  12438. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  12439. }
  12440. else
  12441. {
  12442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  12443. }
  12444. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  12445. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  12446. isKnowKey = TRUE;
  12447. }
  12448. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  12449. {
  12450. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  12451. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  12452. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12453. {
  12454. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  12455. }
  12456. else
  12457. {
  12458. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  12459. }
  12460. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  12461. isKnowKey = TRUE;
  12462. }
  12463. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  12464. {
  12465. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  12466. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  12467. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12468. {
  12469. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  12470. }
  12471. else
  12472. {
  12473. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  12474. }
  12475. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  12476. isKnowKey = TRUE;
  12477. }
  12478. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  12479. {
  12480. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  12481. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  12482. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12483. {
  12484. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12485. }
  12486. else
  12487. {
  12488. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12489. }
  12490. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  12491. isKnowKey = TRUE;
  12492. }
  12493. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  12494. {
  12495. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  12496. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  12497. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12498. {
  12499. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  12500. }
  12501. else
  12502. {
  12503. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  12504. }
  12505. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  12506. isKnowKey = TRUE;
  12507. }
  12508. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  12509. {
  12510. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  12511. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  12512. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12513. {
  12514. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  12515. }
  12516. else
  12517. {
  12518. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  12519. }
  12520. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  12521. isKnowKey = TRUE;
  12522. }
  12523. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  12524. {
  12525. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  12526. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  12527. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12528. {
  12529. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  12530. }
  12531. else
  12532. {
  12533. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  12534. }
  12535. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  12536. isKnowKey = TRUE;
  12537. }
  12538. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  12539. {
  12540. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  12541. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  12542. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12543. {
  12544. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12545. }
  12546. else
  12547. {
  12548. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12549. }
  12550. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  12551. isKnowKey = TRUE;
  12552. }
  12553. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  12554. {
  12555. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  12556. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  12557. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12558. {
  12559. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  12560. }
  12561. else
  12562. {
  12563. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  12564. }
  12565. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  12566. isKnowKey = TRUE;
  12567. }
  12568. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  12569. {
  12570. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  12571. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  12572. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12573. {
  12574. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12575. }
  12576. else
  12577. {
  12578. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12579. }
  12580. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  12581. isKnowKey = TRUE;
  12582. }
  12583. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  12584. {
  12585. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  12586. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  12587. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12588. {
  12589. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  12590. }
  12591. else
  12592. {
  12593. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  12594. }
  12595. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  12596. isKnowKey = TRUE;
  12597. }
  12598. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  12599. {
  12600. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  12601. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  12602. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12603. {
  12604. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12605. }
  12606. else
  12607. {
  12608. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12609. }
  12610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  12611. isKnowKey = TRUE;
  12612. }
  12613. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  12614. {
  12615. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  12616. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  12617. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12618. {
  12619. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  12620. }
  12621. else
  12622. {
  12623. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  12624. }
  12625. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  12626. isKnowKey = TRUE;
  12627. }
  12628. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  12629. {
  12630. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  12631. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  12632. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12633. {
  12634. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  12635. }
  12636. else
  12637. {
  12638. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  12639. }
  12640. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  12641. isKnowKey = TRUE;
  12642. }
  12643. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  12644. {
  12645. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  12646. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  12647. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12648. {
  12649. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  12650. }
  12651. else
  12652. {
  12653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  12654. }
  12655. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  12656. isKnowKey = TRUE;
  12657. }
  12658. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  12659. {
  12660. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  12661. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  12662. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12663. {
  12664. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  12665. }
  12666. else
  12667. {
  12668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  12669. }
  12670. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  12671. isKnowKey = TRUE;
  12672. }
  12673. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  12674. {
  12675. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  12676. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  12677. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12678. {
  12679. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  12680. }
  12681. else
  12682. {
  12683. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  12684. }
  12685. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  12686. isKnowKey = TRUE;
  12687. }
  12688. /*
  12689. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  12690. {
  12691. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  12692. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  12693. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  12694. {
  12695. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  12696. }
  12697. else
  12698. {
  12699. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  12700. }
  12701. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  12702. isKnowKey = TRUE;
  12703. }*/
  12704. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  12705. {
  12706. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  12707. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  12708. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  12709. {
  12710. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  12711. }
  12712. else
  12713. {
  12714. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  12715. }
  12716. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  12717. isKnowKey = TRUE;
  12718. }
  12719. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  12720. {
  12721. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  12722. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  12723. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  12724. {
  12725. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  12726. }
  12727. else
  12728. {
  12729. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  12730. }
  12731. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  12732. isKnowKey = TRUE;
  12733. }
  12734. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  12735. {
  12736. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  12737. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  12738. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  12739. {
  12740. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  12741. }
  12742. else
  12743. {
  12744. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  12745. }
  12746. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  12747. isKnowKey = TRUE;
  12748. }
  12749. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  12750. {
  12751. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  12752. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  12753. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  12754. {
  12755. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  12756. }
  12757. else
  12758. {
  12759. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  12760. }
  12761. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  12762. isKnowKey = TRUE;
  12763. }
  12764. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  12765. {
  12766. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  12767. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  12768. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  12769. {
  12770. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  12771. }
  12772. else
  12773. {
  12774. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  12775. }
  12776. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  12777. isKnowKey = TRUE;
  12778. }
  12779. #if 1
  12780. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  12781. {
  12782. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  12783. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  12784. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12785. {
  12786. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  12787. }
  12788. else
  12789. {
  12790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  12791. }
  12792. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  12793. isKnowKey = TRUE;
  12794. }
  12795. #endif
  12796. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  12797. {
  12798. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  12799. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  12800. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12801. {
  12802. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12803. }
  12804. else
  12805. {
  12806. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12807. }
  12808. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  12809. isKnowKey = TRUE;
  12810. }
  12811. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  12812. {
  12813. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  12814. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  12815. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12816. {
  12817. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12818. }
  12819. else
  12820. {
  12821. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12822. }
  12823. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  12824. isKnowKey = TRUE;
  12825. }
  12826. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  12827. {
  12828. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  12829. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  12830. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12831. {
  12832. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  12833. }
  12834. else
  12835. {
  12836. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  12837. }
  12838. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12839. isKnowKey = TRUE;
  12840. }
  12841. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  12842. {
  12843. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  12844. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  12845. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12846. {
  12847. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  12848. }
  12849. else
  12850. {
  12851. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  12852. }
  12853. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12854. isKnowKey = TRUE;
  12855. }
  12856. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  12857. {
  12858. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  12859. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  12860. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12861. {
  12862. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  12863. }
  12864. else
  12865. {
  12866. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  12867. }
  12868. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12869. isKnowKey = TRUE;
  12870. }
  12871. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  12872. {
  12873. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  12874. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  12875. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12876. {
  12877. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  12878. }
  12879. else
  12880. {
  12881. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  12882. }
  12883. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12884. isKnowKey = TRUE;
  12885. }
  12886. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  12887. {
  12888. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  12889. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  12890. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12891. {
  12892. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  12893. }
  12894. else
  12895. {
  12896. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  12897. }
  12898. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12899. isKnowKey = TRUE;
  12900. }
  12901. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  12902. {
  12903. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  12904. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  12905. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12906. {
  12907. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  12908. }
  12909. else
  12910. {
  12911. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  12912. }
  12913. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12914. isKnowKey = TRUE;
  12915. }
  12916. //=========================================================
  12917. if(!isEmpty && !isKnowKey)
  12918. {
  12919. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  12920. strcpy(unknownkey[UnknownKeynum], keyReq);
  12921. UnknownKeynum = UnknownKeynum + 1;
  12922. }
  12923. }
  12924. void processUnkownKey(void)
  12925. {
  12926. DEBUG_INFO("processUnkownKey...\n");
  12927. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  12928. for(int index=0; index < UnknownKeynum; index++)
  12929. {
  12930. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  12931. {
  12932. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  12933. }
  12934. }
  12935. }
  12936. int setKeyValue(char *key, char *value)
  12937. {
  12938. int isSuccess = NotSupported;
  12939. int check_ascii=0;
  12940. char str[256]={0};
  12941. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  12942. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  12943. {
  12944. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  12945. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  12946. {
  12947. strcpy(str, (const char*)value);
  12948. for(int i = 0; str[i]; i++){
  12949. str[i] = tolower(str[i]);
  12950. }
  12951. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12952. isSuccess = ConfigurationStatus_Accepted;
  12953. }
  12954. else
  12955. {
  12956. isSuccess = ConfigurationStatus_Rejected;
  12957. }
  12958. }
  12959. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  12960. {
  12961. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  12962. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  12963. {
  12964. strcpy(str, (const char*)value);
  12965. for(int i = 0; str[i]; i++){
  12966. str[i] = tolower(str[i]);
  12967. }
  12968. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12969. isSuccess = ConfigurationStatus_Accepted;
  12970. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  12971. }
  12972. else
  12973. {
  12974. isSuccess = ConfigurationStatus_Rejected;
  12975. }
  12976. }
  12977. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  12978. {
  12979. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  12980. {
  12981. strcpy(str, (const char*)value);
  12982. for(int i = 0; str[i]; i++)
  12983. {
  12984. str[i] = tolower(str[i]);
  12985. }
  12986. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  12987. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12988. isSuccess = ConfigurationStatus_Accepted;
  12989. }
  12990. else
  12991. {
  12992. isSuccess = ConfigurationStatus_Rejected;
  12993. }
  12994. }
  12995. if(strcmp(key, "BlinkRepeat") == 0)
  12996. {
  12997. //Charger.BlinkRepeat = Integer.parseInt(value);
  12998. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  12999. {
  13000. check_ascii = value[0];
  13001. if( (check_ascii < 48) || (check_ascii > 57) )
  13002. {
  13003. isSuccess = ConfigurationStatus_Rejected;
  13004. }
  13005. else
  13006. {
  13007. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  13008. isSuccess = ConfigurationStatus_Accepted;
  13009. }
  13010. }
  13011. else
  13012. {
  13013. isSuccess = ConfigurationStatus_Rejected;
  13014. }
  13015. }
  13016. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  13017. {
  13018. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  13019. {
  13020. check_ascii = value[0];
  13021. if( (check_ascii < 48) || (check_ascii > 57) )
  13022. {
  13023. isSuccess = ConfigurationStatus_Rejected;
  13024. }
  13025. else
  13026. {
  13027. if((atoi(value) == 0) || (atoi(value) >= 10))
  13028. {
  13029. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  13030. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  13031. isSuccess = ConfigurationStatus_Accepted;
  13032. }
  13033. else
  13034. isSuccess = ConfigurationStatus_Rejected;
  13035. }
  13036. }
  13037. else
  13038. {
  13039. isSuccess = ConfigurationStatus_Rejected;
  13040. }
  13041. }
  13042. if(strcmp(key, "ConnectionTimeOut") == 0 )
  13043. {
  13044. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13045. {
  13046. check_ascii = value[0];
  13047. if( (check_ascii < 48) || (check_ascii > 57) )
  13048. {
  13049. isSuccess = ConfigurationStatus_Rejected;
  13050. }
  13051. else
  13052. {
  13053. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  13054. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  13055. isSuccess = ConfigurationStatus_Accepted;
  13056. }
  13057. }
  13058. else
  13059. {
  13060. isSuccess = ConfigurationStatus_Rejected;
  13061. }
  13062. }
  13063. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  13064. {
  13065. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13066. {
  13067. check_ascii = value[0];
  13068. if( (check_ascii < 48) || (check_ascii > 57) )
  13069. {
  13070. isSuccess = ConfigurationStatus_Rejected;
  13071. }
  13072. else
  13073. {
  13074. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13075. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  13076. isSuccess = ConfigurationStatus_Accepted;
  13077. }
  13078. }
  13079. else
  13080. {
  13081. isSuccess = ConfigurationStatus_Rejected;
  13082. }
  13083. }
  13084. if(strcmp(key, "HeartbeatInterval") == 0)
  13085. {
  13086. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13087. {
  13088. check_ascii = value[0];
  13089. if( (check_ascii < 48) || (check_ascii > 57) )
  13090. {
  13091. isSuccess = ConfigurationStatus_Rejected;
  13092. }
  13093. else
  13094. {
  13095. if((atoi(value) == 0) || (atoi(value) >= 10))
  13096. {
  13097. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13098. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  13099. HeartBeatWaitTime = atoi(value);
  13100. isSuccess = ConfigurationStatus_Accepted;
  13101. }
  13102. else
  13103. {
  13104. isSuccess = ConfigurationStatus_Rejected;
  13105. }
  13106. }
  13107. }
  13108. else
  13109. {
  13110. isSuccess = ConfigurationStatus_Rejected;
  13111. }
  13112. }
  13113. if(strcmp(key, "LightIntensity") == 0)
  13114. {
  13115. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13116. {
  13117. check_ascii = value[0];
  13118. if( (check_ascii < 48) || (check_ascii > 57) )
  13119. {
  13120. isSuccess = ConfigurationStatus_Rejected;
  13121. }
  13122. else
  13123. {
  13124. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  13125. isSuccess = ConfigurationStatus_Accepted;
  13126. }
  13127. }
  13128. else
  13129. {
  13130. isSuccess = ConfigurationStatus_Rejected;
  13131. }
  13132. }
  13133. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  13134. {
  13135. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13136. {
  13137. strcpy(str, (const char*)value);
  13138. for(int i = 0; str[i]; i++)
  13139. {
  13140. str[i] = tolower(str[i]);
  13141. }
  13142. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13143. isSuccess = ConfigurationStatus_Accepted;
  13144. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13145. }
  13146. else
  13147. {
  13148. isSuccess = ConfigurationStatus_Rejected;
  13149. }
  13150. }
  13151. if(strcmp(key, "LocalPreAuthorize") == 0)
  13152. {
  13153. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13154. {
  13155. strcpy(str, (const char*)value);
  13156. for(int i = 0; str[i]; i++)
  13157. {
  13158. str[i] = tolower(str[i]);
  13159. }
  13160. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13161. isSuccess = ConfigurationStatus_Accepted;
  13162. }
  13163. else
  13164. {
  13165. isSuccess = ConfigurationStatus_Rejected;
  13166. }
  13167. }
  13168. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  13169. {
  13170. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13171. {
  13172. check_ascii = value[0];
  13173. if( (check_ascii < 48) || (check_ascii > 57) )
  13174. {
  13175. isSuccess = ConfigurationStatus_Rejected;
  13176. }
  13177. else
  13178. {
  13179. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  13180. isSuccess = ConfigurationStatus_Accepted;
  13181. }
  13182. }
  13183. else
  13184. {
  13185. isSuccess = ConfigurationStatus_Rejected;
  13186. }
  13187. }
  13188. if(strcmp(key, "MeterValuesAlignedData") == 0)
  13189. {
  13190. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13191. {
  13192. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  13193. isSuccess = ConfigurationStatus_Accepted;
  13194. }
  13195. else
  13196. {
  13197. isSuccess = ConfigurationStatus_Rejected;
  13198. }
  13199. }
  13200. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  13201. {
  13202. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13203. {
  13204. check_ascii = value[0];
  13205. if( (check_ascii < 48) || (check_ascii > 57) )
  13206. {
  13207. isSuccess = ConfigurationStatus_Rejected;
  13208. }
  13209. else
  13210. {
  13211. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13212. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  13213. isSuccess = ConfigurationStatus_Accepted;
  13214. }
  13215. }
  13216. else
  13217. {
  13218. isSuccess = ConfigurationStatus_Rejected;
  13219. }
  13220. }
  13221. if(strcmp(key, "MeterValuesSampledData") == 0 )
  13222. {
  13223. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13224. {
  13225. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  13226. isSuccess = ConfigurationStatus_Accepted;
  13227. }
  13228. else
  13229. {
  13230. isSuccess = ConfigurationStatus_Rejected;
  13231. }
  13232. }
  13233. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  13234. {
  13235. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13236. {
  13237. check_ascii = value[0];
  13238. if( (check_ascii < 48) || (check_ascii > 57) )
  13239. {
  13240. isSuccess = ConfigurationStatus_Rejected;
  13241. }
  13242. else
  13243. {
  13244. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13245. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  13246. isSuccess = ConfigurationStatus_Accepted;
  13247. }
  13248. }
  13249. else
  13250. {
  13251. isSuccess = ConfigurationStatus_Rejected;
  13252. }
  13253. }
  13254. if(strcmp(key, "MeterValueSampleInterval") == 0)
  13255. {
  13256. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13257. {
  13258. check_ascii = value[0];
  13259. if( (check_ascii < 48) || (check_ascii > 57) )
  13260. {
  13261. isSuccess = ConfigurationStatus_Rejected;
  13262. }
  13263. else
  13264. {
  13265. if((atoi(value) == 0) || (atoi(value) >= 10))
  13266. {
  13267. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13268. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  13269. isSuccess = ConfigurationStatus_Accepted;
  13270. }
  13271. else
  13272. {
  13273. isSuccess = ConfigurationStatus_Rejected;
  13274. }
  13275. }
  13276. }
  13277. else
  13278. {
  13279. isSuccess = ConfigurationStatus_Rejected;
  13280. }
  13281. }
  13282. if(strcmp(key, "MinimumStatusDuration") == 0)
  13283. {
  13284. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13285. {
  13286. check_ascii = value[0];
  13287. if( (check_ascii < 48) || (check_ascii > 57) )
  13288. {
  13289. isSuccess = ConfigurationStatus_Rejected;
  13290. }
  13291. else
  13292. {
  13293. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  13294. {
  13295. isSuccess = ConfigurationStatus_Rejected;
  13296. }
  13297. else
  13298. {
  13299. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  13300. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  13301. server_cycle_Status = atoi(value); //StatusNotification Cycle
  13302. isSuccess = ConfigurationStatus_Accepted;
  13303. }
  13304. }
  13305. }
  13306. else
  13307. {
  13308. isSuccess = ConfigurationStatus_Rejected;
  13309. }
  13310. }
  13311. if(strcmp(key, "NumberOfConnectors") == 0)
  13312. {
  13313. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13314. {
  13315. check_ascii = value[0];
  13316. if( (check_ascii < 48) || (check_ascii > 57) )
  13317. {
  13318. isSuccess = ConfigurationStatus_Rejected;
  13319. }
  13320. else
  13321. {
  13322. //Charger.ResetRetries = Integer.parseInt(value);
  13323. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  13324. isSuccess = ConfigurationStatus_Accepted;
  13325. }
  13326. }
  13327. else
  13328. {
  13329. isSuccess = ConfigurationStatus_Rejected;
  13330. }
  13331. }
  13332. if(strcmp(key, "ResetRetries") == 0)
  13333. {
  13334. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13335. {
  13336. check_ascii = value[0];
  13337. if( (check_ascii < 48) || (check_ascii > 57) )
  13338. {
  13339. isSuccess = ConfigurationStatus_Rejected;
  13340. }
  13341. else
  13342. {
  13343. //Charger.ResetRetries = Integer.parseInt(value);
  13344. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  13345. isSuccess = ConfigurationStatus_Accepted;
  13346. }
  13347. }
  13348. else
  13349. {
  13350. isSuccess = ConfigurationStatus_Rejected;
  13351. }
  13352. }
  13353. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  13354. {
  13355. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13356. {
  13357. strcpy(str, (const char*)value);
  13358. for(int i = 0; str[i]; i++)
  13359. {
  13360. str[i] = tolower(str[i]);
  13361. }
  13362. if(strcmp(str, "notapplicable")== 0)
  13363. {
  13364. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  13365. isSuccess = ConfigurationStatus_Accepted;
  13366. }
  13367. else if(strcmp(str, "unknown")== 0)
  13368. {
  13369. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  13370. isSuccess = ConfigurationStatus_Accepted;
  13371. }
  13372. else if(strcmp(str, "rst")== 0)
  13373. {
  13374. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  13375. isSuccess = ConfigurationStatus_Accepted;
  13376. }
  13377. else if(strcmp(str, "rts")== 0)
  13378. {
  13379. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  13380. isSuccess = ConfigurationStatus_Accepted;
  13381. }
  13382. else if(strcmp(str, "srt")== 0)
  13383. {
  13384. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  13385. isSuccess = ConfigurationStatus_Accepted;
  13386. }
  13387. else if(strcmp(str, "str")== 0)
  13388. {
  13389. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  13390. isSuccess = ConfigurationStatus_Accepted;
  13391. }
  13392. else if(strcmp(str, "trs")== 0)
  13393. {
  13394. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  13395. isSuccess = ConfigurationStatus_Accepted;
  13396. }
  13397. else if(strcmp(str, "tsr")== 0)
  13398. {
  13399. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  13400. isSuccess = ConfigurationStatus_Accepted;
  13401. }
  13402. else
  13403. {
  13404. isSuccess = ConfigurationStatus_Rejected;
  13405. }
  13406. }
  13407. else
  13408. {
  13409. isSuccess = ConfigurationStatus_Rejected;
  13410. }
  13411. }
  13412. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  13413. {
  13414. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13415. {
  13416. check_ascii = value[0];
  13417. if( (check_ascii < 48) || (check_ascii > 57) )
  13418. {
  13419. isSuccess = ConfigurationStatus_Rejected;
  13420. }
  13421. else
  13422. {
  13423. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  13424. isSuccess = ConfigurationStatus_Accepted;
  13425. }
  13426. }
  13427. else
  13428. {
  13429. isSuccess = ConfigurationStatus_Rejected;
  13430. }
  13431. }
  13432. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  13433. {
  13434. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13435. {
  13436. strcpy(str, (const char*)value);
  13437. for(int i = 0; str[i]; i++)
  13438. {
  13439. str[i] = tolower(str[i]);
  13440. }
  13441. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  13442. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13443. isSuccess = ConfigurationStatus_Accepted;
  13444. }
  13445. else
  13446. {
  13447. isSuccess = ConfigurationStatus_Rejected;
  13448. }
  13449. }
  13450. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  13451. {
  13452. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13453. {
  13454. strcpy(str, (const char*)value);
  13455. for(int i = 0; str[i]; i++)
  13456. {
  13457. str[i] = tolower(str[i]);
  13458. }
  13459. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  13460. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13461. isSuccess = ConfigurationStatus_Accepted;
  13462. }
  13463. else
  13464. {
  13465. isSuccess = ConfigurationStatus_Rejected;
  13466. }
  13467. }
  13468. if(strcmp(key, "StopTxnAlignedData") == 0)
  13469. {
  13470. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13471. {
  13472. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  13473. isSuccess = ConfigurationStatus_Accepted;
  13474. }
  13475. else
  13476. {
  13477. isSuccess = ConfigurationStatus_Rejected;
  13478. }
  13479. }
  13480. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  13481. {
  13482. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13483. {
  13484. check_ascii = value[0];
  13485. if( (check_ascii < 48) || (check_ascii > 57) )
  13486. {
  13487. isSuccess = ConfigurationStatus_Rejected;
  13488. }
  13489. else
  13490. {
  13491. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  13492. isSuccess = ConfigurationStatus_Accepted;
  13493. }
  13494. }
  13495. else
  13496. {
  13497. isSuccess = ConfigurationStatus_Rejected;
  13498. }
  13499. }
  13500. if(strcmp(key, "StopTxnSampledData") == 0)
  13501. {
  13502. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13503. {
  13504. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  13505. isSuccess = ConfigurationStatus_Accepted;
  13506. }
  13507. else
  13508. {
  13509. isSuccess = ConfigurationStatus_Rejected;
  13510. }
  13511. }
  13512. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  13513. {
  13514. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13515. {
  13516. check_ascii = value[0];
  13517. if( (check_ascii < 48) || (check_ascii > 57) )
  13518. {
  13519. isSuccess = ConfigurationStatus_Rejected;
  13520. }
  13521. else
  13522. {
  13523. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  13524. isSuccess = ConfigurationStatus_Accepted;
  13525. }
  13526. }
  13527. else
  13528. {
  13529. isSuccess = ConfigurationStatus_Rejected;
  13530. }
  13531. }
  13532. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  13533. {
  13534. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13535. {
  13536. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  13537. isSuccess = ConfigurationStatus_Accepted;
  13538. }
  13539. else
  13540. {
  13541. isSuccess = ConfigurationStatus_Rejected;
  13542. }
  13543. }
  13544. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  13545. {
  13546. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13547. {
  13548. check_ascii = value[0];
  13549. if( (check_ascii < 48) || (check_ascii > 57) )
  13550. {
  13551. isSuccess = ConfigurationStatus_Rejected;
  13552. }
  13553. else
  13554. {
  13555. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  13556. isSuccess = ConfigurationStatus_Accepted;
  13557. }
  13558. }
  13559. else
  13560. {
  13561. isSuccess = ConfigurationStatus_Rejected;
  13562. }
  13563. }
  13564. if(strcmp(key, "TransactionMessageAttempts") == 0)
  13565. {
  13566. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13567. {
  13568. check_ascii = value[0];
  13569. if( (check_ascii < 48) || (check_ascii > 57) )
  13570. {
  13571. isSuccess = ConfigurationStatus_Rejected;
  13572. }
  13573. else
  13574. {
  13575. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  13576. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  13577. TransactionMessageAttemptsValue = atoi(value);
  13578. isSuccess = ConfigurationStatus_Accepted;
  13579. }
  13580. }
  13581. else
  13582. {
  13583. isSuccess = ConfigurationStatus_Rejected;
  13584. }
  13585. }
  13586. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  13587. {
  13588. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13589. {
  13590. check_ascii = value[0];
  13591. if( (check_ascii < 48) || (check_ascii > 57) )
  13592. {
  13593. isSuccess = ConfigurationStatus_Rejected;
  13594. }
  13595. else
  13596. {
  13597. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  13598. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  13599. TransactionMessageRetryIntervalValue = atoi(value);
  13600. isSuccess = ConfigurationStatus_Accepted;
  13601. }
  13602. }
  13603. else
  13604. {
  13605. isSuccess = ConfigurationStatus_Rejected;
  13606. }
  13607. }
  13608. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  13609. {
  13610. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13611. {
  13612. strcpy(str, (const char*)value);
  13613. for(int i = 0; str[i]; i++)
  13614. {
  13615. str[i] = tolower(str[i]);
  13616. }
  13617. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  13618. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13619. isSuccess = ConfigurationStatus_Accepted;
  13620. }
  13621. else
  13622. {
  13623. isSuccess = ConfigurationStatus_Rejected;
  13624. }
  13625. }
  13626. if(strcmp(key, "WebSocketPingInterval") == 0)
  13627. {
  13628. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13629. {
  13630. check_ascii = value[0];
  13631. if( (check_ascii < 48) || (check_ascii > 57) )
  13632. {
  13633. isSuccess = ConfigurationStatus_Rejected;
  13634. }
  13635. else
  13636. {
  13637. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  13638. isSuccess = ConfigurationStatus_Accepted;
  13639. }
  13640. }
  13641. else
  13642. {
  13643. isSuccess = ConfigurationStatus_Rejected;
  13644. }
  13645. }
  13646. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  13647. {
  13648. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  13649. {
  13650. strcpy(str, (const char*)value);
  13651. for(int i = 0; str[i]; i++)
  13652. {
  13653. str[i] = tolower(str[i]);
  13654. }
  13655. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13656. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13657. isSuccess = ConfigurationStatus_Accepted;
  13658. }
  13659. else
  13660. {
  13661. isSuccess = ConfigurationStatus_Rejected;
  13662. }
  13663. }
  13664. if(strcmp(key, "AuthorizationKey") == 0)
  13665. {
  13666. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  13667. {
  13668. strcpy(str, (const char*)value);
  13669. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  13670. isSuccess = ConfigurationStatus_Accepted;
  13671. }
  13672. else
  13673. {
  13674. isSuccess = ConfigurationStatus_Rejected;
  13675. }
  13676. }
  13677. if(strcmp(key, "SecurityProfile") == 0)
  13678. {
  13679. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  13680. {
  13681. check_ascii = value[0];
  13682. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  13683. {
  13684. isSuccess = ConfigurationStatus_Rejected;
  13685. }
  13686. else if(check_ascii == 0x33)
  13687. {
  13688. isSuccess = NotSupported;
  13689. }
  13690. else
  13691. {
  13692. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  13693. {
  13694. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  13695. isSuccess = ConfigurationStatus_Accepted;
  13696. }
  13697. else
  13698. isSuccess = ConfigurationStatus_Rejected;
  13699. }
  13700. }
  13701. else
  13702. {
  13703. isSuccess = ConfigurationStatus_Rejected;
  13704. }
  13705. }
  13706. if(strcmp(key, "DefaultPrice") == 0)
  13707. {
  13708. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  13709. {
  13710. strcpy(str, (const char*)value);
  13711. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  13712. isSuccess = ConfigurationStatus_Accepted;
  13713. }
  13714. else
  13715. {
  13716. isSuccess = ConfigurationStatus_Rejected;
  13717. }
  13718. }
  13719. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  13720. {
  13721. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  13722. {
  13723. strcpy(str, (const char*)value);
  13724. for(int i = 0; str[i]; i++)
  13725. {
  13726. str[i] = tolower(str[i]);
  13727. }
  13728. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13729. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13730. isSuccess = ConfigurationStatus_Accepted;
  13731. }
  13732. else
  13733. {
  13734. isSuccess = ConfigurationStatus_Rejected;
  13735. }
  13736. }
  13737. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  13738. {
  13739. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  13740. {
  13741. strcpy(str, (const char*)value);
  13742. for(int i = 0; str[i]; i++)
  13743. {
  13744. str[i] = tolower(str[i]);
  13745. }
  13746. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13747. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13748. isSuccess = ConfigurationStatus_Accepted;
  13749. }
  13750. else
  13751. {
  13752. isSuccess = ConfigurationStatus_Rejected;
  13753. }
  13754. }
  13755. #if 0
  13756. //For OCPP Test Case
  13757. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  13758. {
  13759. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13760. {
  13761. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  13762. isSuccess = ConfigurationStatus_Accepted;
  13763. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13764. }
  13765. else
  13766. {
  13767. isSuccess = ConfigurationStatus_Rejected;
  13768. }
  13769. }
  13770. #endif
  13771. #if 1
  13772. if(strcmp(key, "LocalAuthListEnabled") == 0)
  13773. {
  13774. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13775. {
  13776. strcpy(str, (const char*)value);
  13777. for(int i = 0; str[i]; i++)
  13778. {
  13779. str[i] = tolower(str[i]);
  13780. }
  13781. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13782. isSuccess = ConfigurationStatus_Accepted;
  13783. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13784. }
  13785. else
  13786. {
  13787. isSuccess = ConfigurationStatus_Rejected;
  13788. }
  13789. }
  13790. #endif
  13791. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  13792. {
  13793. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  13794. {
  13795. check_ascii = value[0];
  13796. if( (check_ascii < 48) || (check_ascii > 57) )
  13797. {
  13798. isSuccess = ConfigurationStatus_Rejected;
  13799. }
  13800. else
  13801. {
  13802. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  13803. isSuccess = ConfigurationStatus_Accepted;
  13804. }
  13805. }
  13806. else
  13807. {
  13808. isSuccess = ConfigurationStatus_Rejected;
  13809. }
  13810. }
  13811. if(strcmp(key, "SendLocalListMaxLength") == 0)
  13812. {
  13813. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  13814. {
  13815. check_ascii = value[0];
  13816. if( (check_ascii < 48) || (check_ascii > 57) )
  13817. {
  13818. isSuccess = ConfigurationStatus_Rejected;
  13819. }
  13820. else
  13821. {
  13822. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  13823. isSuccess = ConfigurationStatus_Accepted;
  13824. }
  13825. }
  13826. else
  13827. {
  13828. isSuccess = ConfigurationStatus_Rejected;
  13829. }
  13830. }
  13831. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  13832. {
  13833. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  13834. {
  13835. strcpy(str, (const char*)value);
  13836. for(int i = 0; str[i]; i++)
  13837. {
  13838. str[i] = tolower(str[i]);
  13839. }
  13840. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13841. isSuccess = ConfigurationStatus_Accepted;
  13842. }
  13843. else
  13844. {
  13845. isSuccess = ConfigurationStatus_Rejected;
  13846. }
  13847. }
  13848. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  13849. {
  13850. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  13851. {
  13852. check_ascii = value[0];
  13853. if( (check_ascii < 48) || (check_ascii > 57) )
  13854. {
  13855. isSuccess = ConfigurationStatus_Rejected;
  13856. }
  13857. else
  13858. {
  13859. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  13860. isSuccess = ConfigurationStatus_Accepted;
  13861. }
  13862. }
  13863. else
  13864. {
  13865. isSuccess = ConfigurationStatus_Rejected;
  13866. }
  13867. }
  13868. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  13869. {
  13870. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  13871. {
  13872. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  13873. isSuccess = ConfigurationStatus_Accepted;
  13874. }
  13875. else
  13876. {
  13877. isSuccess = ConfigurationStatus_Rejected;
  13878. }
  13879. }
  13880. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  13881. {
  13882. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  13883. {
  13884. check_ascii = value[0];
  13885. if( (check_ascii < 48) || (check_ascii > 57) )
  13886. {
  13887. isSuccess = ConfigurationStatus_Rejected;
  13888. }
  13889. else
  13890. {
  13891. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  13892. isSuccess = ConfigurationStatus_Accepted;
  13893. }
  13894. }
  13895. else
  13896. {
  13897. isSuccess = ConfigurationStatus_Rejected;
  13898. }
  13899. }
  13900. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  13901. {
  13902. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  13903. {
  13904. strcpy(str, (const char*)value);
  13905. for(int i = 0; str[i]; i++)
  13906. {
  13907. str[i] = tolower(str[i]);
  13908. }
  13909. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13910. isSuccess = ConfigurationStatus_Accepted;
  13911. }
  13912. else
  13913. {
  13914. isSuccess = ConfigurationStatus_Rejected;
  13915. }
  13916. }
  13917. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  13918. {
  13919. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  13920. {
  13921. check_ascii = value[0];
  13922. if( (check_ascii < 48) || (check_ascii > 57) )
  13923. {
  13924. isSuccess = ConfigurationStatus_Rejected;
  13925. }
  13926. else
  13927. {
  13928. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  13929. isSuccess = ConfigurationStatus_Accepted;
  13930. }
  13931. }
  13932. else
  13933. {
  13934. isSuccess = ConfigurationStatus_Rejected;
  13935. }
  13936. }
  13937. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13938. return isSuccess;
  13939. }
  13940. int TransactionMessageAttemptsGet(void)
  13941. {
  13942. return TransactionMessageAttemptsValue;
  13943. }
  13944. int FirstHeartBeatResponse(void)
  13945. {
  13946. return FirstHeartBeat;
  13947. }
  13948. int TransactionMessageRetryIntervalGet(void)
  13949. {
  13950. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13951. }
  13952. int ReadHttpStatus(int sock)
  13953. {
  13954. //char c;
  13955. char buff[1024]="",*ptr=buff+1;
  13956. int bytes_received, status;
  13957. DEBUG_INFO("Begin Response ..\n");
  13958. while((bytes_received = recv(sock, ptr, 1, 0))){
  13959. if(bytes_received==-1){
  13960. perror("ReadHttpStatus");
  13961. exit(1);
  13962. }
  13963. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  13964. ptr++;
  13965. }
  13966. *ptr=0;
  13967. ptr=buff+1;
  13968. sscanf(ptr,"%*s %d ", &status);
  13969. DEBUG_INFO("%s\n",ptr);
  13970. DEBUG_INFO("status=%d\n",status);
  13971. DEBUG_INFO("End Response ..\n");
  13972. return (bytes_received>0)?status:0;
  13973. }
  13974. //the only filed that it parsed is 'Content-Length'
  13975. int ParseHeader(int sock)
  13976. {
  13977. //char c;
  13978. char buff[1024]="",*ptr=buff+4;
  13979. int bytes_received;
  13980. DEBUG_INFO("Begin HEADER ..\n");
  13981. while((bytes_received = recv(sock, ptr, 1, 0))){
  13982. if(bytes_received==-1){
  13983. perror("Parse Header");
  13984. exit(1);
  13985. }
  13986. if(
  13987. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  13988. (ptr[-1]=='\r') && (*ptr=='\n' )
  13989. ) break;
  13990. ptr++;
  13991. }
  13992. *ptr=0;
  13993. ptr=buff+4;
  13994. //printf("%s",ptr);
  13995. if(bytes_received){
  13996. ptr=strstr(ptr,"Content-Length:");
  13997. if(ptr){
  13998. sscanf(ptr,"%*s %d",&bytes_received);
  13999. }else
  14000. bytes_received=-1; //unknown size
  14001. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  14002. }
  14003. DEBUG_INFO("End HEADER ..\n");
  14004. return bytes_received ;
  14005. }
  14006. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  14007. {
  14008. int result = TRUE;
  14009. char rmFileCmd[100]={0};
  14010. char FilePath[100]={0};
  14011. char ftpbuf[200];
  14012. int systemresult;
  14013. //DEBUG_INFO("filename=%s\n",filename);
  14014. //DEBUG_INFO("url=%s\n",url);
  14015. sprintf(FilePath,"/mnt/%s",filename);
  14016. system("ping 8.8.8.8 &");
  14017. if((access(FilePath,F_OK))!=-1)
  14018. {
  14019. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14020. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14021. system(rmFileCmd);
  14022. }
  14023. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14024. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14025. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14026. systemresult = system(ftpbuf);
  14027. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14028. if(systemresult != 0)
  14029. {
  14030. DEBUG_INFO("http DownLoad error!\n");
  14031. result = FALSE;
  14032. }
  14033. system("pkill ping");
  14034. return result;
  14035. }
  14036. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  14037. {
  14038. int result = TRUE;
  14039. char rmFileCmd[100]={0};
  14040. char FilePath[100]={0};
  14041. char ftpbuf[200];
  14042. int systemresult;
  14043. //char temp[100];
  14044. sprintf(FilePath,"/mnt/%s",filename);
  14045. system("ping 8.8.8.8 &");
  14046. if((access(FilePath,F_OK))!=-1)
  14047. {
  14048. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14049. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14050. system(rmFileCmd);
  14051. }
  14052. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14053. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14054. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  14055. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14056. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14057. systemresult = system(ftpbuf);
  14058. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14059. if(systemresult != 0)
  14060. {
  14061. printf("wget error!\n");
  14062. result = FALSE;
  14063. }
  14064. system("pkill ping");
  14065. return result;
  14066. }
  14067. int httpUploadFile(char *location, char *path, char *filename,char *url)
  14068. {
  14069. char rmFileCmd[100]={0};
  14070. char FilePath[100]={0};
  14071. char buf[512];
  14072. int systemresult = 0;
  14073. //DEBUG_INFO("filename=%s\n",filename);
  14074. //DEBUG_INFO("url=%s\n",url);
  14075. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  14076. if((access(FilePath,F_OK))!=-1)
  14077. {
  14078. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14079. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14080. system(rmFileCmd);
  14081. }
  14082. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  14083. if(fp == NULL)
  14084. {
  14085. DEBUG_INFO("log is NULL\n");
  14086. return FALSE;
  14087. }
  14088. else
  14089. {
  14090. fprintf(fp, "%s\n", url);
  14091. fprintf(fp, "%s\n", filename);
  14092. fclose(fp);
  14093. }
  14094. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  14095. if(phpFP == NULL)
  14096. {
  14097. DEBUG_INFO("PHP upload fail.\n");
  14098. return FALSE;
  14099. }
  14100. else
  14101. {
  14102. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  14103. {
  14104. if(strstr(buf, "result") != NULL)
  14105. {
  14106. sscanf(buf, "result: %d", &systemresult);
  14107. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  14108. }
  14109. }
  14110. pclose(phpFP);
  14111. }
  14112. if(systemresult != 1)
  14113. {
  14114. DEBUG_INFO("HTTP upload error!\n");
  14115. return FALSE;
  14116. }
  14117. return TRUE;
  14118. }
  14119. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  14120. {
  14121. struct hostent* server;
  14122. char *IPbuffer;
  14123. char ftpbuf[200];
  14124. int systemresult;
  14125. // To retrieve host information
  14126. server = gethostbyname(location);
  14127. // To convert an Internet network
  14128. // address into ASCII string
  14129. IPbuffer = inet_ntoa(*((struct in_addr*)
  14130. server->h_addr_list[0]));
  14131. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14132. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  14133. /* format : ftpput -u username -p passwd IP target source*/
  14134. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  14135. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14136. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14137. systemresult = system(ftpbuf);
  14138. DEBUG_INFO("systemresult=%d\n",systemresult);
  14139. if(systemresult != 0)
  14140. {
  14141. DEBUG_INFO("ftpput error!\n");
  14142. return FALSE;
  14143. }
  14144. return TRUE;
  14145. }
  14146. int GetOcppServerURL()
  14147. {
  14148. int result = FALSE;
  14149. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  14150. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  14151. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  14152. struct yuarel url;
  14153. char urlStr[512];
  14154. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  14155. {
  14156. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  14157. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14158. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  14159. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  14160. if(yuarel_parse(&url, urlStr) != -1)
  14161. {
  14162. sprintf(OcppProtocol, "%s", url.scheme);
  14163. sprintf(OcppHost, "%s", url.host);
  14164. if(url.path == NULL)
  14165. OcppTempPath[0] = '\0';
  14166. else
  14167. {
  14168. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  14169. {
  14170. sprintf(OcppTempPath, "%s/", url.path);
  14171. }
  14172. else
  14173. {
  14174. sprintf(OcppTempPath, "%s", url.path);
  14175. }
  14176. }
  14177. if(url.port == 0)
  14178. {
  14179. if(strcmp(OcppProtocol, "wss") == 0)
  14180. OcppPort = 443;
  14181. else
  14182. OcppPort = 80;
  14183. }
  14184. else
  14185. OcppPort = url.port;
  14186. result = TRUE;
  14187. }
  14188. }
  14189. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  14190. {
  14191. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  14192. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14193. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  14194. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  14195. if(yuarel_parse(&url, urlStr) != -1)
  14196. {
  14197. sprintf(OcppProtocol, "%s", url.scheme);
  14198. sprintf(OcppHost, "%s", url.host);
  14199. if(url.path == NULL)
  14200. OcppTempPath[0] = '\0';
  14201. else
  14202. sprintf(OcppTempPath, "%s", url.path);
  14203. if(url.port == 0)
  14204. {
  14205. if(strcmp(OcppProtocol, "wss") == 0)
  14206. OcppPort = 443;
  14207. else
  14208. OcppPort = 80;
  14209. }
  14210. else
  14211. OcppPort = url.port;
  14212. result = TRUE;
  14213. }
  14214. }
  14215. else
  14216. {
  14217. strcpy(OcppHost,"");
  14218. }
  14219. return result;
  14220. }
  14221. int GetOcppPath()
  14222. {
  14223. int result = FALSE;
  14224. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  14225. {
  14226. if(OcppTempPath == NULL)
  14227. {
  14228. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  14229. }
  14230. else
  14231. {
  14232. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  14233. }
  14234. result = TRUE;
  14235. goto End;
  14236. }
  14237. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  14238. {
  14239. if(OcppTempPath == NULL)
  14240. {
  14241. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  14242. }
  14243. else
  14244. {
  14245. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  14246. }
  14247. result = TRUE;
  14248. goto End;
  14249. }
  14250. else
  14251. {
  14252. strcpy(OcppPath,"");
  14253. }
  14254. End:
  14255. return result;
  14256. }
  14257. int GetOcppPort()
  14258. {
  14259. return OcppPort;
  14260. }
  14261. int GetOcppConnStatus(void)
  14262. {
  14263. return ShmOCPP16Data->OcppConnStatus;
  14264. }
  14265. void SetOcppConnStatus(uint8_t status)
  14266. {
  14267. ShmOCPP16Data->OcppConnStatus = status;
  14268. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  14269. }
  14270. int GetHeartBeatWithNOResponse(void)
  14271. {
  14272. return HeartBeatWithNOResponse;
  14273. }
  14274. void SetHeartBeatWithNOResponse(void)
  14275. {
  14276. HeartBeatWithNOResponse = 0;
  14277. }
  14278. void GetStartTransactionIdTag(int gun_index)
  14279. {
  14280. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  14281. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  14282. }
  14283. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  14284. {
  14285. char ch;
  14286. FILE *fptr1;
  14287. int temptransactionId;
  14288. char str[100]={0};
  14289. temptransactionId = 0;
  14290. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  14291. {
  14292. DEBUG_INFO("IdTag is empty.\n");
  14293. return temptransactionId;
  14294. }
  14295. /*------ Read the file ----------------*/
  14296. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  14297. if (!fptr1)
  14298. {
  14299. DEBUG_INFO("QueueTransactionId file open error.\n");
  14300. //printf(" File not found or unable to open the input file!!\n");
  14301. return temptransactionId;
  14302. }
  14303. ch=fgetc(fptr1);
  14304. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  14305. rewind(fptr1);
  14306. if(ch!=EOF)
  14307. {
  14308. // printf("%c",ch);
  14309. while (fgets(str, 100, fptr1) != NULL)
  14310. {
  14311. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14312. if(str[0]=='\0')
  14313. {
  14314. break;
  14315. }
  14316. char *revbuf[8] = {0}; // Variable store string split
  14317. int num = 0;// Quantity after string split
  14318. DEBUG_INFO("Transaction queue data= %s\n", str);
  14319. splitstring(str,",",revbuf,&num); // String split
  14320. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  14321. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  14322. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  14323. DEBUG_INFO("------------------------------\n");
  14324. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  14325. {
  14326. if(isStopTransaction)
  14327. {
  14328. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  14329. {
  14330. temptransactionId = atoi(revbuf[2]);
  14331. //break;
  14332. }
  14333. }
  14334. else
  14335. {
  14336. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  14337. {
  14338. temptransactionId = atoi(revbuf[2]);
  14339. //break;
  14340. }
  14341. }
  14342. }
  14343. }
  14344. }
  14345. else
  14346. DEBUG_INFO("EOF\n");
  14347. fclose(fptr1);
  14348. /*------- End of reading ---------------*/
  14349. return temptransactionId;
  14350. }
  14351. void SetTransactionIdZero(int transactionId)
  14352. {
  14353. char ch;
  14354. FILE *fptr1, *fptr2;
  14355. int temptransactionId = 0;
  14356. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  14357. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  14358. if (!fptr1)
  14359. {
  14360. //printf(" File not found or unable to open the input file!!\n");
  14361. return ;
  14362. }
  14363. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  14364. if (!fptr2)
  14365. {
  14366. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  14367. fclose(fptr1);
  14368. return ;
  14369. }
  14370. ch=fgetc(fptr1);
  14371. rewind(fptr1);
  14372. if(ch!=EOF)
  14373. {
  14374. // copy all contents to the temporary file except the specific line
  14375. while (fgets(str, 100, fptr1) != NULL)
  14376. {
  14377. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14378. if(str[0]=='\0')
  14379. {
  14380. break;
  14381. }
  14382. char *revbuf[8] = {0};
  14383. int num = 0;
  14384. strcpy(strtemp, str);
  14385. splitstring(str,",",revbuf,&num);
  14386. if(revbuf[2][0] != '\0')
  14387. {
  14388. temptransactionId = atoi(revbuf[2]);
  14389. if(transactionId != temptransactionId)
  14390. {
  14391. fprintf(fptr2, "%s\n", strtemp);
  14392. }
  14393. }
  14394. }
  14395. }
  14396. fclose(fptr1);
  14397. fclose(fptr2);
  14398. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  14399. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  14400. /*------ Read the file ----------------*/
  14401. }
  14402. int InternetDisconnect(void)
  14403. {
  14404. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  14405. }
  14406. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  14407. void storeTempStopTransaction(int gun_index)
  14408. {
  14409. char guid[37]={0};
  14410. int tempIndex = 0;
  14411. char TempStopTransaction[256];
  14412. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  14413. DEBUG_INFO("storeTempStopTransaction...\n");
  14414. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  14415. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  14416. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  14417. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14418. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14419. {
  14420. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14421. {
  14422. tempIndex = ((gun_index==2) ? 1: 0);
  14423. }
  14424. else
  14425. {
  14426. tempIndex = gun_index;
  14427. }
  14428. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14429. {
  14430. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14431. {
  14432. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  14433. }
  14434. }// END OF CHAdeMO_QUANTITY
  14435. }
  14436. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14437. {
  14438. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14439. {
  14440. tempIndex = ((gun_index==2) ? 1: 0);
  14441. }
  14442. else
  14443. {
  14444. tempIndex = gun_index;
  14445. }
  14446. for (int index = 0; index < CCS_QUANTITY; index++)
  14447. {
  14448. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14449. {
  14450. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  14451. }
  14452. }// END OF CCS_QUANTITY
  14453. }
  14454. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14455. {
  14456. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14457. {
  14458. tempIndex = ((gun_index==2) ? 1: 0);
  14459. }
  14460. else
  14461. {
  14462. tempIndex = gun_index;
  14463. }
  14464. for (int index = 0; index < GB_QUANTITY; index++)
  14465. {
  14466. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14467. {
  14468. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  14469. }
  14470. }// END OF GB_QUANTITY
  14471. }
  14472. else if(gunType[gun_index] == GUN_TYPE_DO)
  14473. {
  14474. tempIndex = gun_index;
  14475. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14476. {
  14477. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14478. {
  14479. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  14480. }
  14481. }
  14482. }
  14483. else
  14484. {
  14485. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14486. {
  14487. tempIndex = 2;
  14488. }
  14489. else
  14490. {
  14491. tempIndex = gun_index;
  14492. }
  14493. for (int index = 0; index < AC_QUANTITY; index++)
  14494. {
  14495. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14496. {
  14497. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  14498. }
  14499. }// END OF AC_QUANTITY
  14500. }
  14501. //Stop Transaction Time
  14502. struct timeval tmnow;
  14503. struct tm *tm;
  14504. char buf[28];//, usec_buf[6];
  14505. gettimeofday(&tmnow, NULL);
  14506. time_t t;
  14507. t = time(NULL);
  14508. /*UTC time and date*/
  14509. tm = gmtime(&t);
  14510. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  14511. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  14512. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  14513. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  14514. random_uuid(guid);
  14515. /***********************************transactionData******************************************************/
  14516. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  14517. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  14518. //=================================
  14519. //1. Transaction_Begin
  14520. //=================================
  14521. //============================== Energy.Active.Import.Interval ===========================================
  14522. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  14523. {
  14524. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  14525. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  14526. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  14527. 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*/]);
  14528. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14529. 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))
  14530. {
  14531. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  14532. }
  14533. else
  14534. {
  14535. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  14536. }
  14537. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  14538. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14539. }
  14540. //=================================
  14541. //2. Transaction_End
  14542. //=================================
  14543. //2.1====================================== Current.Import L1 ==============================================
  14544. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  14545. {
  14546. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  14547. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14548. {
  14549. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14550. {
  14551. tempIndex = ((gun_index==2) ? 1: 0);
  14552. }
  14553. else
  14554. {
  14555. tempIndex = gun_index;
  14556. }
  14557. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14558. {
  14559. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14560. {
  14561. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14562. }
  14563. }// End of for CHAdeMO_QUANTITY
  14564. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14565. }
  14566. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14567. {
  14568. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14569. {
  14570. tempIndex = ((gun_index==2) ? 1: 0);
  14571. }
  14572. else
  14573. {
  14574. tempIndex = gun_index;
  14575. }
  14576. for (int index = 0; index < CCS_QUANTITY; index++)
  14577. {
  14578. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14579. {
  14580. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14581. }
  14582. }// End of for CCS_QUANTITY
  14583. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14584. }
  14585. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14586. {
  14587. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14588. {
  14589. tempIndex = ((gun_index==2) ? 1: 0);
  14590. }
  14591. else
  14592. {
  14593. tempIndex = gun_index;
  14594. }
  14595. for (int index = 0; index < GB_QUANTITY; index++)
  14596. {
  14597. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14598. {
  14599. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14600. }
  14601. }// End of for GB_QUANTITY
  14602. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14603. }
  14604. else if(gunType[gun_index] == GUN_TYPE_DO)
  14605. {
  14606. tempIndex = gun_index;
  14607. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14608. {
  14609. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14610. {
  14611. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14612. }
  14613. }
  14614. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14615. }
  14616. else
  14617. {
  14618. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14619. {
  14620. tempIndex = 2;
  14621. }
  14622. else
  14623. {
  14624. tempIndex = gun_index;
  14625. }
  14626. for (int index = 0; index < AC_QUANTITY; index++)
  14627. {
  14628. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14629. {
  14630. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  14631. }
  14632. }// End of for AC_QUANTITY
  14633. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  14634. }
  14635. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14636. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  14637. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  14638. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  14639. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  14640. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14641. }
  14642. //2.2===================================== Energy.Active.Import.Interval ==========================================
  14643. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  14644. {
  14645. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14646. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14647. {
  14648. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14649. {
  14650. tempIndex = ((gun_index==2) ? 1: 0);
  14651. }
  14652. else
  14653. {
  14654. tempIndex = gun_index;
  14655. }
  14656. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14657. {
  14658. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14659. {
  14660. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14661. }
  14662. }// END OF CHAdeMO_QUANTITY
  14663. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14664. }
  14665. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14666. {
  14667. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14668. {
  14669. tempIndex = ((gun_index==2) ? 1: 0);
  14670. }
  14671. else
  14672. {
  14673. tempIndex = gun_index;
  14674. }
  14675. for (int index = 0; index < CCS_QUANTITY; index++)
  14676. {
  14677. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14678. {
  14679. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14680. }
  14681. }// END OF CCS_QUANTITY
  14682. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14683. }
  14684. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14685. {
  14686. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14687. {
  14688. tempIndex = ((gun_index==2) ? 1: 0);
  14689. }
  14690. else
  14691. {
  14692. tempIndex = gun_index;
  14693. }
  14694. for (int index = 0; index < GB_QUANTITY; index++)
  14695. {
  14696. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14697. {
  14698. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14699. }
  14700. }// END OF GB_QUANTITY
  14701. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14702. }
  14703. else if(gunType[gun_index] == GUN_TYPE_DO)
  14704. {
  14705. tempIndex = gun_index;
  14706. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14707. {
  14708. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14709. {
  14710. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14711. }
  14712. }
  14713. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14714. }
  14715. else
  14716. {
  14717. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14718. {
  14719. tempIndex = 2;
  14720. }
  14721. else
  14722. {
  14723. tempIndex = gun_index;
  14724. }
  14725. for (int index = 0; index < AC_QUANTITY; index++)
  14726. {
  14727. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14728. {
  14729. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14730. }
  14731. }// END OF AC_QUANTITY
  14732. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14733. }
  14734. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14735. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  14736. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  14737. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14738. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  14739. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14740. }
  14741. //2.3====================================== Power.Active.Import =========================================
  14742. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  14743. {
  14744. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14745. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14746. {
  14747. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14748. {
  14749. tempIndex = ((gun_index==2) ? 1: 0);
  14750. }
  14751. else
  14752. {
  14753. tempIndex = gun_index;
  14754. }
  14755. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14756. {
  14757. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14758. {
  14759. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14760. }
  14761. } // End for CHAdeMO_QUANTITY
  14762. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14763. }
  14764. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14765. {
  14766. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14767. {
  14768. tempIndex = ((gun_index==2) ? 1: 0);
  14769. }
  14770. else
  14771. {
  14772. tempIndex = gun_index;
  14773. }
  14774. for (int index = 0; index < CCS_QUANTITY; index++)
  14775. {
  14776. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14777. {
  14778. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14779. }
  14780. } // END for CCS_QUANTITY
  14781. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14782. }
  14783. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14784. {
  14785. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14786. {
  14787. tempIndex = ((gun_index==2) ? 1: 0);
  14788. }
  14789. else
  14790. {
  14791. tempIndex = gun_index;
  14792. }
  14793. for (int index = 0; index < GB_QUANTITY; index++)
  14794. {
  14795. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14796. {
  14797. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14798. }
  14799. }// END for GB_QUANTITY
  14800. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14801. }
  14802. else if(gunType[gun_index] == GUN_TYPE_DO)
  14803. {
  14804. tempIndex = gun_index;
  14805. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14806. {
  14807. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14808. {
  14809. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14810. }
  14811. }
  14812. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14813. }
  14814. else
  14815. {
  14816. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14817. {
  14818. tempIndex = 2;
  14819. }
  14820. else
  14821. {
  14822. tempIndex = gun_index;
  14823. }
  14824. for (int index = 0; index < AC_QUANTITY; index++)
  14825. {
  14826. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14827. {
  14828. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14829. }
  14830. } // END for AC_QUANTITY
  14831. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14832. }
  14833. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14834. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  14835. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  14836. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14837. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  14838. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  14839. }
  14840. //2.4====================================== Voltage L1 ====================================================
  14841. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  14842. {
  14843. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14844. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14845. {
  14846. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14847. {
  14848. tempIndex = ((gun_index==2) ? 1: 0);
  14849. }
  14850. else
  14851. {
  14852. tempIndex = gun_index;
  14853. }
  14854. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14855. {
  14856. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14857. {
  14858. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14859. }
  14860. } // END OF FOR CHAdeMO_QUANTITY
  14861. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14862. }
  14863. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14864. {
  14865. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14866. {
  14867. tempIndex = ((gun_index==2) ? 1: 0);
  14868. }
  14869. else
  14870. {
  14871. tempIndex = gun_index;
  14872. }
  14873. for (int index = 0; index < CCS_QUANTITY; index++)
  14874. {
  14875. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14876. {
  14877. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14878. }
  14879. } // END OF FOR CCS_QUANTITY
  14880. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14881. }
  14882. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14883. {
  14884. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14885. {
  14886. tempIndex = ((gun_index==2) ? 1: 0);
  14887. }
  14888. else
  14889. {
  14890. tempIndex = gun_index;
  14891. }
  14892. for (int index = 0; index < GB_QUANTITY; index++)
  14893. {
  14894. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14895. {
  14896. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14897. }
  14898. } // END OF FOR GB_QUANTITY
  14899. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14900. }
  14901. else if(gunType[gun_index] == GUN_TYPE_DO)
  14902. {
  14903. tempIndex = gun_index;
  14904. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14905. {
  14906. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14907. {
  14908. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14909. }
  14910. }
  14911. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14912. }
  14913. else
  14914. {
  14915. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14916. {
  14917. tempIndex = 2;
  14918. }
  14919. else
  14920. {
  14921. tempIndex = gun_index;
  14922. }
  14923. for (int index = 0; index < AC_QUANTITY; index++)
  14924. {
  14925. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14926. {
  14927. 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
  14928. }
  14929. } // END OF FOR AC_QUANTITY
  14930. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  14931. }
  14932. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14933. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  14934. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  14935. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  14936. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  14937. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14938. }
  14939. //2.5============================================== End SoC =========================================================
  14940. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  14941. {
  14942. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14943. 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))
  14944. {
  14945. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  14946. {
  14947. tempIndex = ((gun_index==2) ? 1: 0);
  14948. }
  14949. else
  14950. {
  14951. tempIndex = gun_index;
  14952. }
  14953. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14954. {
  14955. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14956. {
  14957. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14958. {
  14959. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  14960. }
  14961. }
  14962. }
  14963. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14964. {
  14965. for (int index = 0; index < CCS_QUANTITY; index++)
  14966. {
  14967. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14968. {
  14969. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  14970. }
  14971. }
  14972. }
  14973. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14974. {
  14975. for (int index = 0; index < GB_QUANTITY; index++)
  14976. {
  14977. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14978. {
  14979. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  14980. }
  14981. }
  14982. }
  14983. else if(gunType[gun_index] == GUN_TYPE_DO)
  14984. {
  14985. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14986. {
  14987. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14988. {
  14989. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  14990. }
  14991. }
  14992. }
  14993. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14994. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  14995. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  14996. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  14997. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  14998. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  14999. } // END FOR DC CASE
  15000. }
  15001. //2.6====================================== Current.Import L2 ==============================================
  15002. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15003. {
  15004. // AC 3 phase L2 current
  15005. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15006. {
  15007. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15008. {
  15009. tempIndex = 2;
  15010. }
  15011. else
  15012. {
  15013. tempIndex = gun_index;
  15014. }
  15015. for (int index = 0; index < AC_QUANTITY; index++)
  15016. {
  15017. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15018. {
  15019. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  15020. }
  15021. }// End of for AC_QUANTITY
  15022. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  15023. }
  15024. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15025. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  15026. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  15027. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  15028. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15029. }
  15030. //2.7====================================== Current.Import L3 ==============================================
  15031. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15032. {
  15033. // AC 3 phase L3 current
  15034. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15035. {
  15036. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15037. {
  15038. tempIndex = 2;
  15039. }
  15040. else
  15041. {
  15042. tempIndex = gun_index;
  15043. }
  15044. for (int index = 0; index < AC_QUANTITY; index++)
  15045. {
  15046. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15047. {
  15048. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  15049. }
  15050. }// End of for AC_QUANTITY
  15051. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  15052. }
  15053. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15054. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  15055. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  15056. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  15057. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15058. }
  15059. //2.9====================================== Voltage L2 ====================================================
  15060. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15061. {
  15062. // AC 3 phase L2 volatge
  15063. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15064. {
  15065. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15066. {
  15067. tempIndex = 2;
  15068. }
  15069. else
  15070. {
  15071. tempIndex = gun_index;
  15072. }
  15073. for (int index = 0; index < AC_QUANTITY; index++)
  15074. {
  15075. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15076. {
  15077. 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
  15078. }
  15079. } // END OF FOR AC_QUANTITY
  15080. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  15081. }
  15082. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15083. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  15084. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  15085. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  15086. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15087. }
  15088. //2.10====================================== Voltage L3 ====================================================
  15089. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15090. {
  15091. // AC 3 phase L3 volatge
  15092. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15093. {
  15094. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15095. {
  15096. tempIndex = 2;
  15097. }
  15098. else
  15099. {
  15100. tempIndex = gun_index;
  15101. }
  15102. for (int index = 0; index < AC_QUANTITY; index++)
  15103. {
  15104. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15105. {
  15106. 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
  15107. }
  15108. } // END OF FOR AC_QUANTITY
  15109. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  15110. }
  15111. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15112. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  15113. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  15114. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  15115. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15116. }
  15117. //====================== Start SoC ================================
  15118. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  15119. {
  15120. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15121. 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))
  15122. {
  15123. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15124. {
  15125. tempIndex = ((gun_index==2) ? 1: 0);
  15126. }
  15127. else
  15128. {
  15129. tempIndex = gun_index;
  15130. }
  15131. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15132. {
  15133. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15134. {
  15135. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15136. {
  15137. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  15138. }
  15139. }
  15140. }
  15141. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15142. {
  15143. for (int index = 0; index < CCS_QUANTITY; index++)
  15144. {
  15145. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15146. {
  15147. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  15148. }
  15149. }
  15150. }
  15151. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15152. {
  15153. for (int index = 0; index < GB_QUANTITY; index++)
  15154. {
  15155. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15156. {
  15157. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  15158. }
  15159. }
  15160. }
  15161. else if(gunType[gun_index] == GUN_TYPE_DO)
  15162. {
  15163. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15164. {
  15165. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15166. {
  15167. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  15168. }
  15169. }
  15170. }
  15171. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15172. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  15173. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15174. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  15175. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  15176. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15177. } // END FOR DC CASE
  15178. }
  15179. //======================================== Message create ==============================================
  15180. json_object *StopTransaction = json_object_new_object();
  15181. json_object *transactionDatas = json_object_new_array();
  15182. json_object *sampledValues = json_object_new_array();
  15183. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  15184. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  15185. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  15186. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  15187. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  15188. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  15189. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  15190. {
  15191. json_object *transactionData = json_object_new_object();
  15192. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  15193. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  15194. {
  15195. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  15196. {
  15197. json_object *sampledValue = json_object_new_object();
  15198. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  15199. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  15200. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  15201. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  15202. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  15203. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  15204. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  15205. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  15206. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  15207. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  15208. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  15209. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  15210. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  15211. json_object_array_add(sampledValues, sampledValue);
  15212. }
  15213. }
  15214. json_object_object_add(transactionData, "sampledValue", sampledValues);
  15215. json_object_array_add(transactionDatas, transactionData);
  15216. }
  15217. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  15218. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  15219. ,MESSAGE_TYPE_CALL
  15220. ,guid
  15221. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  15222. json_object_put(StopTransaction);
  15223. // Check File "TempStopTransaction" Exist
  15224. if((access(TempStopTransaction,F_OK))!=-1)
  15225. {
  15226. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  15227. fclose(fopen(TempStopTransaction, "w"));
  15228. }
  15229. else
  15230. {
  15231. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  15232. FILE *log = fopen(TempStopTransaction, "w+");
  15233. if(log == NULL)
  15234. {
  15235. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  15236. return ;
  15237. }
  15238. else
  15239. {
  15240. fclose(log);
  15241. }
  15242. }
  15243. //Add TempStopTransaction | Update TempStopTransaction
  15244. // open file for writing
  15245. FILE *outfile;
  15246. outfile = fopen (TempStopTransaction, "a");
  15247. //DEBUG_INFO("data = %s\n", queuedata);
  15248. fputs(queuedata, outfile);
  15249. fputs("\n", outfile);
  15250. fclose (outfile);
  15251. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15252. }
  15253. void checkTempStopTransaction(int gun_index)
  15254. {
  15255. FILE *fptr1;
  15256. char ch;
  15257. char str[QUEUE_MESSAGE_LENGTH]={0};
  15258. char guid[37]={0};
  15259. char tempdata[65]={0};
  15260. char connectorStr[2]={0};
  15261. char TempStopTransaction[256];
  15262. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  15263. fptr1 = fopen(TempStopTransaction, "r");
  15264. //TempStopTransaction格式: 槍號,StopTransaction封包
  15265. if (!fptr1)
  15266. {
  15267. //printf(" File not found or unable to open the input file!!\n");
  15268. return ;
  15269. }
  15270. ch=fgetc(fptr1);
  15271. //printf(" Now the content of the file %s is : \n",fname);
  15272. rewind(fptr1);
  15273. if(ch!=EOF)
  15274. {
  15275. // copy all contents to the temporary file except the specific line
  15276. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  15277. {
  15278. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15279. if(str[0]=='\0')
  15280. {
  15281. break;
  15282. }
  15283. //TempStopTransaction格式: 槍號,StopTransaction封包
  15284. strncpy(connectorStr, str, 1);
  15285. if(atoi(connectorStr) != (gun_index+1))
  15286. {
  15287. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  15288. fclose(fptr1);
  15289. return ;
  15290. }
  15291. //random_uuid(guid);
  15292. strncpy(guid, str+6, 36); //copy guid
  15293. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  15294. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  15295. {
  15296. //DEBUG_INFO("StopTransaction mapitem pass\n");
  15297. }
  15298. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  15299. OCPP_insert_transaction_msg(NO, str);
  15300. memset(str,0,ARRAY_SIZE(str));
  15301. }
  15302. }
  15303. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  15304. fclose(fptr1);
  15305. remove(TempStopTransaction); // remove the original file
  15306. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15307. }
  15308. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  15309. {
  15310. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  15311. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  15312. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  15313. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  15314. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  15315. }
  15316. int GetWebSocketPingInterval(void)
  15317. {
  15318. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15319. }
  15320. int GetServerSign(void)
  15321. {
  15322. return server_sign;
  15323. }
  15324. uint8_t GetOcppSecurityProfile()
  15325. {
  15326. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15327. }
  15328. void GetOcppChargerBoxId(uint8_t *data)
  15329. {
  15330. sprintf((char*)data, "%s", ShmOCPP16Data->ChargeBoxId);
  15331. }
  15332. void GetOcppSecurityPassword(uint8_t *data)
  15333. {
  15334. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15335. }
  15336. void SetOcppVersion(uint8_t *version)
  15337. {
  15338. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  15339. DEBUG_INFO("ocpp version: %s\n", version);
  15340. if(strstr((char*)version, "ocpp1.6") != NULL)
  15341. {
  15342. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  15343. }
  15344. else if(strstr((char*)version, "ocpp2.0") != NULL)
  15345. {
  15346. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  15347. system("pkill OcppBackend");
  15348. }
  15349. }
  15350. void SetServerSign(int value)
  15351. {
  15352. server_sign = value;
  15353. }
  15354. int GetBootNotificationInterval(void)
  15355. {
  15356. return BootNotificationInterval;
  15357. }
  15358. int GetInternetConn(void)
  15359. {
  15360. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  15361. }
  15362. int GetBackendConnectionTimeout(void)
  15363. {
  15364. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  15365. }
  15366. int isConnectorInitMode(int gun_index)
  15367. {
  15368. int tempIndex = 0;
  15369. int result = TRUE;
  15370. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15371. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15372. {
  15373. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15374. {
  15375. tempIndex = ((gun_index==2) ? 1: 0);
  15376. }
  15377. else
  15378. {
  15379. tempIndex = gun_index;
  15380. }
  15381. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15382. {
  15383. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  15384. {
  15385. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15386. } //end of the same index
  15387. }//end of for CHAdeMO_QUANTITY
  15388. }
  15389. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15390. {
  15391. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15392. {
  15393. tempIndex = ((gun_index==2) ? 1: 0);
  15394. }
  15395. else
  15396. {
  15397. tempIndex = gun_index;
  15398. }
  15399. for (int index = 0; index < CCS_QUANTITY; index++)
  15400. {
  15401. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15402. {
  15403. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15404. } //end of the same index
  15405. } // end of for CCS_QUANTITY
  15406. }
  15407. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15408. {
  15409. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15410. {
  15411. tempIndex = ((gun_index==2) ? 1: 0);
  15412. }
  15413. else
  15414. {
  15415. tempIndex = gun_index;
  15416. }
  15417. for (int index = 0; index < GB_QUANTITY; index++)
  15418. {
  15419. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15420. {
  15421. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15422. } //end of the same index
  15423. } // end of for GB_QUANTITY
  15424. }
  15425. else if(gunType[gun_index] == GUN_TYPE_DO)
  15426. {
  15427. tempIndex = gun_index;
  15428. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15429. {
  15430. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15431. {
  15432. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15433. } //end of the same index
  15434. }
  15435. }
  15436. else
  15437. {
  15438. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15439. {
  15440. tempIndex = 2;
  15441. }
  15442. else
  15443. {
  15444. tempIndex = gun_index;
  15445. }
  15446. for (int index = 0; index < AC_QUANTITY; index++)
  15447. {
  15448. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15449. {
  15450. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15451. }//end of the same index
  15452. }//end of for AC_QUANTITY
  15453. }
  15454. return result;
  15455. }
  15456. void refreshProcDogTimer()
  15457. {
  15458. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  15459. }
  15460. void InitialSystemValue(void)
  15461. {
  15462. int connectorIndex = 0;
  15463. //int valueASCII = 0;
  15464. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15465. gunTotalNumber=0;
  15466. SystemInitial = 0;
  15467. localversion=0;
  15468. BootNotificationInterval = 0;
  15469. authorizeRetryTimes = 0;
  15470. GunStatusInterval = 10;
  15471. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15472. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15473. //Hear Beat
  15474. HeartBeatWithNOResponse = 0;
  15475. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  15476. FirstHeartBeat = 0;
  15477. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  15478. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  15479. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  15480. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  15481. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  15482. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  15483. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  15484. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  15485. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  15486. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  15487. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  15488. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  15489. memset(gunType, 0, ARRAY_SIZE(gunType));
  15490. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  15491. {
  15492. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O')
  15493. {
  15494. // DO series
  15495. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  15496. {
  15497. SystemInitial = SystemInitial + 1;
  15498. gunTotalNumber = gunTotalNumber + 1;
  15499. gunType[connectorIndex] = GUN_TYPE_DO;
  15500. connectorIndex = connectorIndex + 1;
  15501. }
  15502. }
  15503. else
  15504. {
  15505. // DM, DW, DS series
  15506. //check connector / socket type (index: 8, 9, 10)
  15507. for(int index=7; index <10 ; index++)
  15508. {
  15509. if(index != 8)
  15510. {
  15511. // DC Connector
  15512. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  15513. {
  15514. SystemInitial = SystemInitial + 1;
  15515. gunTotalNumber = gunTotalNumber + 1;
  15516. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  15517. connectorIndex = connectorIndex + 1;
  15518. }
  15519. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  15520. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  15521. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  15522. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  15523. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  15524. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  15525. {
  15526. SystemInitial = SystemInitial + 1;
  15527. gunTotalNumber = gunTotalNumber + 1;
  15528. gunType[connectorIndex] = GUN_TYPE_CCS;
  15529. connectorIndex = connectorIndex + 1;
  15530. }
  15531. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  15532. {
  15533. SystemInitial = SystemInitial + 1;
  15534. gunTotalNumber = gunTotalNumber + 1;
  15535. gunType[connectorIndex] = GUN_TYPE_GBT;
  15536. connectorIndex = connectorIndex + 1;
  15537. }
  15538. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  15539. {
  15540. SystemInitial = SystemInitial + 1;
  15541. gunTotalNumber = gunTotalNumber + 1;
  15542. gunType[connectorIndex] = GUN_TYPE_DO;
  15543. connectorIndex = connectorIndex + 1;
  15544. }
  15545. }
  15546. else
  15547. {
  15548. // AC Connector
  15549. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15550. {
  15551. SystemInitial = SystemInitial + 1;
  15552. gunTotalNumber = gunTotalNumber + 1;
  15553. gunType[connectorIndex] = GUN_TYPE_AC;
  15554. connectorIndex = connectorIndex + 1;
  15555. }
  15556. }
  15557. }
  15558. }
  15559. //DEBUG_INFO("DC ...\n");
  15560. }
  15561. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  15562. {
  15563. //check connector / socket type (index: 8, 9, 10)
  15564. for(int index=7; index <10 ; index++)
  15565. {
  15566. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15567. {
  15568. SystemInitial = SystemInitial + 1;
  15569. gunTotalNumber = gunTotalNumber + 1;
  15570. gunType[connectorIndex] = GUN_TYPE_AC;
  15571. connectorIndex = connectorIndex + 1;
  15572. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  15573. }
  15574. }
  15575. }
  15576. //Status && ConnectorPlugIn Setting
  15577. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15578. {
  15579. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  15580. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  15581. }
  15582. for (int index = 0; index < CCS_QUANTITY; index++)
  15583. {
  15584. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  15585. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  15586. }
  15587. for (int index = 0; index < GB_QUANTITY; index++)
  15588. {
  15589. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  15590. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  15591. }
  15592. for (int index = 0; index < AC_QUANTITY; index++)
  15593. {
  15594. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  15595. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  15596. }
  15597. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15598. {
  15599. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  15600. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  15601. }
  15602. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  15603. {
  15604. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  15605. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  15606. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  15607. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  15608. }
  15609. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  15610. clientTime.Heartbeat=time((time_t*)NULL);
  15611. sleep(1);
  15612. }
  15613. void LWS_Send(char *str)
  15614. {
  15615. //=====================================================
  15616. // Check InternetConn 0: disconnected, 1: connected
  15617. //====================================================
  15618. if(GetOcppConnStatus() == 0)
  15619. {
  15620. DEBUG_INFO("offline now !!!\n");
  15621. return;
  15622. }
  15623. // Only disable isWebsocketSendable operation initiated by charger
  15624. if((strstr((char*)str, "\"Authorize\"") != NULL)
  15625. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  15626. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  15627. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  15628. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  15629. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  15630. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  15631. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  15632. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  15633. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  15634. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  15635. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  15636. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  15637. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  15638. {
  15639. isWebsocketSendable = 0;
  15640. }
  15641. pthread_mutex_lock(&lock_send);
  15642. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  15643. sprintf((char *)SendBuffer, "%s", str);
  15644. SendBufLen = strlen(str);
  15645. pthread_mutex_unlock(&lock_send);
  15646. lws_callback_on_writable(wsi_client);
  15647. //lws_service(context, 0);
  15648. //sleep(1);
  15649. }
  15650. void LWS_SendNow(char *str)
  15651. {
  15652. //=====================================================
  15653. // Check InternetConn 0: disconnected, 1: connected
  15654. //====================================================
  15655. if(GetOcppConnStatus() == 0)
  15656. {
  15657. DEBUG_INFO("offline now !!!\n");
  15658. return;
  15659. }
  15660. // Only disable isWebsocketSendable operation initiated by charger
  15661. if((strstr((char*)str, "\"Authorize\"") != NULL)
  15662. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  15663. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  15664. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  15665. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  15666. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  15667. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  15668. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  15669. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  15670. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  15671. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  15672. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  15673. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  15674. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  15675. {
  15676. isWebsocketSendable = 0;
  15677. }
  15678. pthread_mutex_lock(&lock_send);
  15679. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  15680. sprintf((char *)SendBuffer, "%s", str);
  15681. SendBufLen = strlen(str);
  15682. pthread_mutex_unlock(&lock_send);
  15683. lws_callback_on_writable(wsi_client);
  15684. lws_service(context, 0);
  15685. //sleep(1);
  15686. }