MessageHandler.c 716 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. //ConfigurationMaxKeys
  12. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  13. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  14. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  15. //=================================
  16. // StatusNotification cycle
  17. //=================================
  18. static int server_cycle_Status = 120;
  19. //===============================
  20. // Configuration: unknownkey
  21. //===============================
  22. static char unknownkey[10][20] = {0};
  23. static int UnknownKeynum = 0;
  24. //===============================
  25. // Gun Total Numbers
  26. //===============================
  27. static int gunTotalNumber = 0;
  28. static uint8_t gunType[4] = {0};
  29. //===============================
  30. // Local List Version
  31. //===============================
  32. static int localversion=0;
  33. static char idTagAuthorization[32] = {0};
  34. //===============================
  35. // OCPP sign variable
  36. //===============================
  37. static int server_sign = FALSE;
  38. int server_pending = FALSE;
  39. static int BootNotificationInterval = 0;
  40. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  41. //===============================
  42. // OCPP auth variable
  43. //===============================
  44. static int authorizeRetryTimes = 0; //number of Retry times
  45. //===============================
  46. // OCPP other variables
  47. //===============================
  48. static int HeartBeatWaitTime = 10;
  49. static int FirstHeartBeat = 0;
  50. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  51. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  52. static char CurrentChargingProfileScheduleStr[30] = {0};
  53. //========================================
  54. // OCPP status/previous related variables
  55. //========================================
  56. static int GunStatusInterval = 10;
  57. static uint8_t statusModeChage[CONNECTOR_QUANTITY] = {FALSE};
  58. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  59. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  60. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  61. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  62. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  63. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  64. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  65. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  66. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  67. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  68. static int TransactionMessageAttemptsValue = 0;
  69. static int TransactionMessageRetryIntervalValue = 0;
  70. static int TempMeterValueInterval = 0;
  71. static struct OCPPAuthLocalElemet
  72. {
  73. int listVersionInt;
  74. char idTagstr[20];
  75. char parentIdTag[20];
  76. char expiryDate[30];
  77. char idTagstatus[16];
  78. }idTagQuery;
  79. //=============================================
  80. // OCPP HeartBeat Response Not Receive Counts
  81. //============================================
  82. static int HeartBeatWithNOResponse = 0;
  83. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  84. extern sqlite3 *db;
  85. int TransactionMessageAttemptsGet(void);
  86. int TransactionMessageRetryIntervalGet(void);
  87. int GetOcppConnStatus(void);
  88. void SetOcppConnStatus(uint8_t status);
  89. int setKeyValue(char *key, char *value);
  90. void OCPP_get_TableAuthlocalAllData(void);
  91. void processUnkownKey(void);
  92. struct StructOCPPMeterValue
  93. {
  94. unsigned char TimeStamp[28];
  95. struct StructSampledValue SampledValue[10];
  96. };
  97. struct ClientTime
  98. {
  99. unsigned int Heartbeat;
  100. unsigned int StatusNotification[CONNECTOR_QUANTITY];
  101. unsigned int StartTransaction;
  102. unsigned int StopTransaction;
  103. unsigned int MeterValues[CONNECTOR_QUANTITY];
  104. }clientTime;
  105. typedef union
  106. {
  107. //Operations Initiated by Central System
  108. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  109. struct
  110. {
  111. //CsMsgValue[0]
  112. unsigned char StatusNotificationReq:1; //bit 0,
  113. unsigned char StatusNotificationConf:1; //bit 1,
  114. unsigned char TriggerMeterValue:1; //bit 2,
  115. unsigned char :5; //bit 5~7
  116. }bits[CONNECTOR_QUANTITY];
  117. }CpinitiateMsg;
  118. CpinitiateMsg cpinitateMsg;
  119. //GetConfiguration Array
  120. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  121. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  122. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  123. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  124. #if 0
  125. static char *ChargePointErrorCodeStr[] = {
  126. MACROSTR(ConnectorLockFailure),
  127. MACROSTR(EVCommunicationError),
  128. MACROSTR(GroundFailure),
  129. MACROSTR(HighTemperature),
  130. MACROSTR(InternalError),
  131. MACROSTR(LocalListConflict),
  132. MACROSTR(NoError),
  133. MACROSTR(OtherError),
  134. MACROSTR(OverCurrentFailure),
  135. MACROSTR(OverVoltage),
  136. MACROSTR(PowerMeterFailure),
  137. MACROSTR(PowerSwitchFailure),
  138. MACROSTR(ReaderFailure),
  139. MACROSTR(ResetFailure),
  140. MACROSTR(UnderVoltage),
  141. MACROSTR(WeakSignal)
  142. };
  143. #endif
  144. static char * ChargePointStatusStr[] = {
  145. MACROSTR(Available),
  146. MACROSTR(Preparing),
  147. MACROSTR(Charging),
  148. MACROSTR(SuspendedEVSE),
  149. MACROSTR(SuspendedEV),
  150. MACROSTR(Finishing),
  151. MACROSTR(Reserved),
  152. MACROSTR(Unavailable),
  153. MACROSTR(Faulted)
  154. };
  155. static char *RegistrationStatusStr[] = {
  156. MACROSTR(Accepted),
  157. MACROSTR(Pending),
  158. MACROSTR(Rejected)
  159. };
  160. static char *AvailabilityTypeStr[] = {
  161. MACROSTR(Inoperative),
  162. MACROSTR(Operative)
  163. };
  164. static char *AvailabilityStatusStr[] = {
  165. MACROSTR(Accepted),
  166. MACROSTR(Rejected),
  167. MACROSTR(Scheduled)
  168. };
  169. static char *ConfigurationStatusStr[] = {
  170. MACROSTR(Accepted),
  171. MACROSTR(Rejected),
  172. MACROSTR(RebootRequired),
  173. MACROSTR(NotSupported)
  174. };
  175. static char *ClearCacheStatusStr[] = {
  176. MACROSTR(Accepted),
  177. MACROSTR(Rejected)
  178. };
  179. static char *ChargingProfilePurposeTypeStr[] = {
  180. MACROSTR(ChargePointMaxProfile),
  181. MACROSTR(TxDefaultProfile),
  182. MACROSTR(TxProfile)
  183. };
  184. static char *ChargingProfileStatusStr[] = {
  185. MACROSTR(Accepted),
  186. MACROSTR(Rejected),
  187. MACROSTR(NotSupported)
  188. };
  189. static char *ClearChargingProfileStatusStr[] = {
  190. MACROSTR(Accepted),
  191. MACROSTR(Unknown)
  192. };
  193. static char *GetCompositeScheduleStatusStr[] = {
  194. MACROSTR(Accepted),
  195. MACROSTR(Rejected)
  196. };
  197. static char *UpdateTypeStr[] = {
  198. MACROSTR(Differential),
  199. MACROSTR(Full)
  200. };
  201. static char *UpdateStatusStr[] = {
  202. MACROSTR(Accepted),
  203. MACROSTR(Failed),
  204. MACROSTR(NotSupported),
  205. MACROSTR(VersionMismatch)
  206. };
  207. static char *RemoteStartStopStatusStr[] = {
  208. MACROSTR(Accepted),
  209. MACROSTR(Rejected)
  210. };
  211. static char *ReservationStatusStr[] = {
  212. MACROSTR(Accepted),
  213. MACROSTR(Faulted),
  214. MACROSTR(Occupied),
  215. MACROSTR(Rejected),
  216. MACROSTR(Unavailable)
  217. };
  218. static char *ResetTypeStr[] = {
  219. MACROSTR(Hard),
  220. MACROSTR(Soft)
  221. };
  222. static char *ResetStatusStr[] = {
  223. MACROSTR(Accepted),
  224. MACROSTR(Rejected)
  225. };
  226. static char * DiagnosticsStatusStr[] = {
  227. MACROSTR(Idle),
  228. MACROSTR(Uploaded),
  229. MACROSTR(UploadFailed),
  230. MACROSTR(Uploading)
  231. };
  232. static char * FirmwareStatusStr[] = {
  233. MACROSTR(Downloaded),
  234. MACROSTR(DownloadFailed),
  235. MACROSTR(Downloading),
  236. MACROSTR(Idle),
  237. MACROSTR(InstallationFailed),
  238. MACROSTR(Installing),
  239. MACROSTR(Installed)
  240. };
  241. static char * MessageTriggerStr[] = {
  242. MACROSTR(BootNotification),
  243. MACROSTR(DiagnosticsStatusNotification),
  244. MACROSTR(FirmwareStatusNotification),
  245. MACROSTR(Heartbeat),
  246. MACROSTR(MeterValues),
  247. MACROSTR(StatusNotification)
  248. };
  249. static char * TriggerMessageStatusStr[] = {
  250. MACROSTR(Accepted),
  251. MACROSTR(Rejected),
  252. MACROSTR(NotImplemented)
  253. };
  254. static char * UnlockStatusStr[] = {
  255. MACROSTR(Unlocked),
  256. MACROSTR(UnlockFailed),
  257. MACROSTR(NotSupported)
  258. };
  259. #if 0
  260. static char * StopTransactionReasonStr[] = {
  261. MACROSTR(EmergencyStop),
  262. MACROSTR(EVDisconnected),
  263. MACROSTR(HardReset),
  264. MACROSTR(Local),
  265. MACROSTR(Other),
  266. MACROSTR(PowerLoss),
  267. MACROSTR(Reboot),
  268. MACROSTR(Remote),
  269. MACROSTR(SoftReset),
  270. MACROSTR(UnlockCommand),
  271. MACROSTR(DeAuthorized)
  272. };
  273. #endif
  274. static char * CancelReservationStatusStr[] = {
  275. MACROSTR(Accepted),
  276. MACROSTR(Rejected)
  277. };
  278. static char * ReadingContextStr[] = {
  279. MACROSTR(Interruption.Begin),
  280. MACROSTR(Interruption.End),
  281. MACROSTR(Other),
  282. MACROSTR(Sample.Clock),
  283. MACROSTR(Sample.Periodic),
  284. MACROSTR(Transaction.Begin),
  285. MACROSTR(Transaction.End),
  286. MACROSTR(Trigger)
  287. };
  288. static char * ValueFormatStr[] = {
  289. MACROSTR(Raw),
  290. MACROSTR(SignedData)
  291. };
  292. static char * MeasurandStr[] = {
  293. MACROSTR(Current.Export),
  294. MACROSTR(Current.Import),
  295. MACROSTR(Current.Offered),
  296. MACROSTR(Energy.Active.Export.Register),
  297. MACROSTR(Energy.Active.Import.Register),
  298. MACROSTR(Energy.Reactive.Export.Register),
  299. MACROSTR(Energy.Reactive.Import.Register),
  300. MACROSTR(Energy.Active.Export.Interval),
  301. MACROSTR(Energy.Active.Import.Interval),
  302. MACROSTR(Energy.Reactive.Export.Interval),
  303. MACROSTR(Energy.Reactive.Import.Interval),
  304. MACROSTR(Frequency),
  305. MACROSTR(Power.Active.Export),
  306. MACROSTR(Power.Active.Import),
  307. MACROSTR(Power.Factor),
  308. MACROSTR(Power.Offered),
  309. MACROSTR(Power.Reactive.ExportMACROSTR),
  310. MACROSTR(Power.Reactive.Import),
  311. MACROSTR(RPM),
  312. MACROSTR(SoC),
  313. MACROSTR(Temperature),
  314. MACROSTR(Voltage)
  315. };
  316. static char * LocationStr[] = {
  317. MACROSTR(Body),
  318. MACROSTR(Cable),
  319. MACROSTR(EV),
  320. MACROSTR(Inlet),
  321. MACROSTR(Outlet)
  322. };
  323. static char * PhaseStr[] = {
  324. MACROSTR(L1),
  325. MACROSTR(L2),
  326. MACROSTR(L3),
  327. MACROSTR(N),
  328. MACROSTR(L1-N),
  329. MACROSTR(L2-N),
  330. MACROSTR(L3-N),
  331. MACROSTR(L1-L2),
  332. MACROSTR(L2-L3),
  333. MACROSTR(L3-L1)
  334. };
  335. static char * UnitOfMeasureStr[] = {
  336. MACROSTR(Wh),
  337. MACROSTR(kWh),
  338. MACROSTR(varh),
  339. MACROSTR(kvarh),
  340. MACROSTR(W),
  341. MACROSTR(kW),
  342. MACROSTR(VA),
  343. MACROSTR(kVA),
  344. MACROSTR(var),
  345. MACROSTR(kvar),
  346. MACROSTR(A),
  347. MACROSTR(V),
  348. MACROSTR(Celsius),
  349. MACROSTR(Fahrenheit),
  350. MACROSTR(K),
  351. MACROSTR(Percent)
  352. };
  353. //==========================================
  354. // Check time passed since today
  355. //==========================================
  356. long long DiffTimebWithNow(struct timeb ST)
  357. {
  358. //return milli-second
  359. struct timeb ET;
  360. long long StartTime,StopTime;
  361. ftime(&ET);
  362. StartTime=(long long)ST.time;
  363. StopTime=(long long)ET.time;
  364. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  365. }
  366. int getTimePassSinceToday()
  367. {
  368. int result = -1;
  369. static time_t lastTime;
  370. time_t t;
  371. struct tm *tmStartToday;
  372. struct timeb tbStartToday;
  373. t=time(NULL);
  374. if(difftime(t, lastTime)>0)
  375. {
  376. tmStartToday=localtime(&t);
  377. tmStartToday->tm_hour = 0;
  378. tmStartToday->tm_min = 0;
  379. tmStartToday->tm_sec = 0;
  380. tbStartToday.time = mktime(tmStartToday);
  381. tbStartToday.millitm = 0;
  382. result = DiffTimebWithNow(tbStartToday)/1000;
  383. lastTime = t;
  384. }
  385. return result;
  386. }
  387. void getNowDatetime(uint8_t *data)
  388. {
  389. time_t t = time(NULL);
  390. struct tm tm = *localtime(&t);
  391. sprintf((char*)data, "%04d-%02d-%02dT%02d:%02d:%02dZ", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
  392. }
  393. //==========================================
  394. // GetCompositeSchedule logic related function
  395. //==========================================
  396. int DiffTimebSec(struct timeb ST, struct timeb ET)
  397. {
  398. //return milli-second
  399. unsigned int StartTime,StopTime;
  400. StartTime=(unsigned int)ST.time;
  401. StopTime=(unsigned int)ET.time;
  402. return (StopTime-StartTime);
  403. }
  404. int DiffTimebWithNowSec(struct timeb ST)
  405. {
  406. //return milli-second
  407. struct timeb ET;
  408. unsigned int StartTime,StopTime;
  409. ftime(&ET);
  410. StartTime=(unsigned int)ST.time;
  411. StopTime=(unsigned int)ET.time;
  412. return (StopTime-StartTime);
  413. }
  414. int getStartStop(uint8_t *start, uint8_t *stop)
  415. {
  416. int result = -1;
  417. struct tm tmStart;
  418. struct timeb tbStart;
  419. struct tm tmStop;
  420. struct timeb tbStop;
  421. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  422. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  423. {
  424. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  425. //DEBUG_INFO("Stop: %d-%d-%d %d:%d:%d\n", tmStop.tm_year, tmStop.tm_mon, tmStop.tm_mday, tmStop.tm_hour, tmStop.tm_min, tmStop.tm_sec);
  426. tmStart.tm_year -= 1900;
  427. tmStart.tm_mon -= 1;
  428. tbStart.time = mktime(&tmStart);
  429. tbStart.millitm = 0;
  430. tmStop.tm_year -= 1900;
  431. tmStop.tm_mon -= 1;
  432. tbStop.time = mktime(&tmStop);
  433. tbStop.millitm = 0;
  434. result = DiffTimebSec(tbStart, tbStop);
  435. //DEBUG_INFO("getStartStop(): %d\n", result);
  436. }
  437. else
  438. {
  439. DEBUG_WARN("Start or stop date parsing error.\r\n");
  440. }
  441. return result;
  442. }
  443. int isOvertNow(uint8_t *start)
  444. {
  445. int result = NO;
  446. struct tm tmStart;
  447. struct timeb tbStart;
  448. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6))
  449. {
  450. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  451. tmStart.tm_year -= 1900;
  452. tmStart.tm_mon -= 1;
  453. tbStart.time = mktime(&tmStart);
  454. tbStart.millitm = 0;
  455. if(DiffTimebWithNowSec(tbStart) <= 0)
  456. result = NO;
  457. else
  458. result = YES;
  459. }
  460. else
  461. {
  462. DEBUG_WARN("Start date parsing error.\n");
  463. }
  464. return result;
  465. }
  466. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  467. {
  468. int result = -1;
  469. struct tm tmStart;
  470. struct timeb tbStart;
  471. struct tm tmStop;
  472. struct timeb tbStop;
  473. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  474. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  475. {
  476. tmStart.tm_year -= 1900;
  477. tmStart.tm_mon -= 1;
  478. tbStart.time = mktime(&tmStart);
  479. tbStart.millitm = 0;
  480. tmStop.tm_year -= 1900;
  481. tmStop.tm_mon -= 1;
  482. tbStop.time = mktime(&tmStop);
  483. tbStop.millitm = 0;
  484. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  485. }
  486. return result;
  487. }
  488. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  489. {
  490. FILE *fp;
  491. char profileFileName[128];
  492. char *line = NULL;
  493. size_t len = 0;
  494. time_t CurrentTime;
  495. struct tm *tmComposite;
  496. struct StructChargingProfile maxProfile;
  497. struct StructChargingProfile defaultTxProfile;
  498. struct StructChargingProfile txProfile;
  499. struct StructChargingSchedulePeriod tmpPeriod;
  500. uint8_t limitMax=0;
  501. uint8_t limitDef=0;
  502. uint8_t limitTx=0;
  503. int compositePeriodIdx = 0;
  504. CurrentTime = time(NULL);
  505. tmComposite=localtime(&CurrentTime);
  506. sprintf((char*)compositeProfile->ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec);
  507. if(isUnitA)
  508. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  509. else
  510. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  511. compositeProfile->ChargingSchedule.Duration = durationReq;
  512. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  513. {
  514. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  515. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  516. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  517. }
  518. compositeProfile->ChargingProfileId = 0;
  519. compositeProfile->StackLevel = 99 ;
  520. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  521. maxProfile.ChargingProfileId = -1;
  522. defaultTxProfile.ChargingProfileId = -1;
  523. txProfile.ChargingProfileId = -1;
  524. maxProfile.ChargingSchedule.Duration = -1;
  525. defaultTxProfile.ChargingSchedule.Duration = -1;
  526. txProfile.ChargingSchedule.Duration = -1;
  527. system("yes|rm /tmp/*.json");
  528. system("cp /Storage/OCPP/*.json /tmp");
  529. /*
  530. * Search valid charging profile
  531. */
  532. //DEBUG_INFO("====================================\n");
  533. // Search tx profile
  534. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  535. if((access(profileFileName, F_OK))!=-1)
  536. {
  537. fp = fopen(profileFileName, "r");
  538. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  539. {
  540. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  541. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  542. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  543. }
  544. txProfile.ChargingProfileId = -1;
  545. txProfile.StackLevel = -1;
  546. while(getline(&line, &len, fp) != -1)
  547. {
  548. json_object *obj = NULL;
  549. obj = json_tokener_parse(line);
  550. if(is_error(obj))
  551. {
  552. DEBUG_ERROR("Parse txProfile from file error.\n");
  553. }
  554. else
  555. {
  556. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  557. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  558. )
  559. {
  560. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  561. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  562. )
  563. {
  564. struct tm tmFrom, tmTo;
  565. struct timeb tbFrom, tbTo;
  566. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  567. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  568. {
  569. tmFrom.tm_year -= 1900;
  570. tmFrom.tm_mon -= 1;
  571. tbFrom.time = mktime(&tmFrom);
  572. tmTo.tm_year -= 1900;
  573. tmTo.tm_mon -= 1;
  574. tbTo.time = mktime(&tmTo);
  575. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  576. {
  577. if(txProfile.ChargingProfileId == -1)
  578. DEBUG_INFO("TxProfile found.\n");
  579. else
  580. DEBUG_INFO("TxProfile updated.\n");
  581. // Required item
  582. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  583. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  584. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  585. if(isUnitA)
  586. {
  587. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  588. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  589. {
  590. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  591. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  592. 3:
  593. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  594. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  595. }
  596. }
  597. else
  598. {
  599. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  600. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  601. {
  602. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  603. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  604. 3:
  605. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  606. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  607. }
  608. }
  609. // Optional item
  610. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  611. {
  612. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  613. }
  614. else
  615. {
  616. sprintf((char*)txProfile.ValidFrom, " ");
  617. }
  618. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  619. {
  620. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  621. }
  622. else
  623. {
  624. sprintf((char*)txProfile.ValidTo, " ");
  625. }
  626. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  627. {
  628. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  629. }
  630. else
  631. {
  632. sprintf((char*)txProfile.RecurrencyKind, " ");
  633. }
  634. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  635. {
  636. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  637. }
  638. else
  639. {
  640. txProfile.TransactionId = -1;
  641. }
  642. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  643. {
  644. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  645. }
  646. else
  647. {
  648. txProfile.ChargingSchedule.Duration = 86400;
  649. }
  650. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  651. {
  652. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  653. }
  654. else
  655. {
  656. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  657. }
  658. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  659. {
  660. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  661. }
  662. else
  663. {
  664. txProfile.ChargingSchedule.MinChargingRate = -1;
  665. }
  666. }
  667. }
  668. }
  669. else
  670. {
  671. if(txProfile.ChargingProfileId == -1)
  672. DEBUG_INFO("TxProfile found.\n");
  673. else
  674. DEBUG_INFO("TxProfile updated.\n");
  675. // Required item
  676. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  677. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  678. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  679. if(isUnitA)
  680. {
  681. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  682. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  683. {
  684. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  685. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  686. 3:
  687. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  688. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  689. }
  690. }
  691. else
  692. {
  693. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  694. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  695. {
  696. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  697. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  698. 3:
  699. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  700. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  701. }
  702. }
  703. // Optional item
  704. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  705. {
  706. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  707. }
  708. else
  709. {
  710. sprintf((char*)txProfile.ValidFrom, " ");
  711. }
  712. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  713. {
  714. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  715. }
  716. else
  717. {
  718. sprintf((char*)txProfile.ValidTo, " ");
  719. }
  720. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  721. {
  722. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  723. }
  724. else
  725. {
  726. sprintf((char*)txProfile.RecurrencyKind, " ");
  727. }
  728. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  729. {
  730. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  731. }
  732. else
  733. {
  734. txProfile.TransactionId = -1;
  735. }
  736. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  737. {
  738. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  739. }
  740. else
  741. {
  742. txProfile.ChargingSchedule.Duration = 86400;
  743. }
  744. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  745. {
  746. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  747. }
  748. else
  749. {
  750. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  751. }
  752. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  753. {
  754. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  755. }
  756. else
  757. {
  758. txProfile.ChargingSchedule.MinChargingRate = -1;
  759. }
  760. }
  761. }
  762. }
  763. json_object_put(obj);
  764. }
  765. fclose(fp);
  766. /*
  767. if(txProfile.ChargingProfileId != -1)
  768. {
  769. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  770. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  771. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  772. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  773. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  774. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  775. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  776. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  777. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  778. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  779. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  780. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  781. {
  782. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  783. {
  784. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  785. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  786. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  787. }
  788. }
  789. }
  790. else
  791. DEBUG_INFO("TxProfile not found.\n");*/
  792. }
  793. // Search default tx profile
  794. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  795. if((access(profileFileName, F_OK))==-1)
  796. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  797. if((access(profileFileName, F_OK))!=-1)
  798. {
  799. fp = fopen(profileFileName, "r");
  800. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  801. {
  802. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  803. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  804. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  805. }
  806. defaultTxProfile.ChargingProfileId = -1;
  807. defaultTxProfile.StackLevel = -1;
  808. while(getline(&line, &len, fp) != -1)
  809. {
  810. json_object *obj = NULL;
  811. obj = json_tokener_parse(line);
  812. if(is_error(obj))
  813. {
  814. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  815. }
  816. else
  817. {
  818. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  819. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  820. )
  821. {
  822. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  823. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  824. )
  825. {
  826. struct tm tmFrom, tmTo;
  827. struct timeb tbFrom, tbTo;
  828. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  829. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  830. {
  831. tmFrom.tm_year -= 1900;
  832. tmFrom.tm_mon -= 1;
  833. tbFrom.time = mktime(&tmFrom);
  834. tmTo.tm_year -= 1900;
  835. tmTo.tm_mon -= 1;
  836. tbTo.time = mktime(&tmTo);
  837. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  838. {
  839. if(defaultTxProfile.ChargingProfileId == -1)
  840. DEBUG_INFO("TxDefaultProfile found.\n");
  841. else
  842. DEBUG_INFO("TxDefaultProfile updated.\n");
  843. // Required item
  844. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  845. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  846. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  847. if(isUnitA)
  848. {
  849. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  850. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  851. {
  852. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  853. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  854. 3:
  855. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  856. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  857. }
  858. }
  859. else
  860. {
  861. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  862. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  863. {
  864. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  865. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  866. 3:
  867. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  868. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  869. }
  870. }
  871. // Optional item
  872. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  873. {
  874. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  875. }
  876. else
  877. {
  878. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  879. }
  880. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  881. {
  882. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  883. }
  884. else
  885. {
  886. sprintf((char*)defaultTxProfile.ValidTo, " ");
  887. }
  888. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  889. {
  890. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  891. }
  892. else
  893. {
  894. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  895. }
  896. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  897. {
  898. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  899. }
  900. else
  901. {
  902. defaultTxProfile.TransactionId = -1;
  903. }
  904. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  905. {
  906. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  907. }
  908. else
  909. {
  910. defaultTxProfile.ChargingSchedule.Duration = 86400;
  911. }
  912. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  913. {
  914. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  915. }
  916. else
  917. {
  918. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  919. }
  920. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  921. {
  922. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  923. }
  924. else
  925. {
  926. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  927. }
  928. }
  929. }
  930. }
  931. else
  932. {
  933. if(defaultTxProfile.ChargingProfileId == -1)
  934. DEBUG_INFO("TxDefaultProfile found.\n");
  935. else
  936. DEBUG_INFO("TxDefaultProfile updated.\n");
  937. // Required item
  938. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  939. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  940. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  941. if(isUnitA)
  942. {
  943. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  944. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  945. {
  946. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  947. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  948. 3:
  949. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  950. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  951. }
  952. }
  953. else
  954. {
  955. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  956. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  957. {
  958. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  959. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  960. 3:
  961. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  962. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  963. }
  964. }
  965. // Optional item
  966. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  967. {
  968. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  969. }
  970. else
  971. {
  972. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  973. }
  974. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  975. {
  976. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  977. }
  978. else
  979. {
  980. sprintf((char*)defaultTxProfile.ValidTo, " ");
  981. }
  982. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  983. {
  984. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  985. }
  986. else
  987. {
  988. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  989. }
  990. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  991. {
  992. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  993. }
  994. else
  995. {
  996. defaultTxProfile.TransactionId = -1;
  997. }
  998. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  999. {
  1000. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1001. }
  1002. else
  1003. {
  1004. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1005. }
  1006. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1007. {
  1008. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1009. }
  1010. else
  1011. {
  1012. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1013. }
  1014. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1015. {
  1016. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1017. }
  1018. else
  1019. {
  1020. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1021. }
  1022. }
  1023. }
  1024. }
  1025. json_object_put(obj);
  1026. }
  1027. fclose(fp);
  1028. /*
  1029. if(defaultTxProfile.ChargingProfileId != -1)
  1030. {
  1031. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1032. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1033. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1034. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1035. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1036. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1037. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1038. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  1039. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1040. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1041. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1042. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1043. {
  1044. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1045. {
  1046. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1047. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1048. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1049. }
  1050. }
  1051. }
  1052. else
  1053. DEBUG_INFO("TxDefaultProfile not found.\n");
  1054. DEBUG_INFO("------------------------------------\n");*/
  1055. }
  1056. // Search max profile
  1057. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1058. if((access(profileFileName, F_OK))!=-1)
  1059. {
  1060. fp = fopen(profileFileName, "r");
  1061. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1062. {
  1063. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1064. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1065. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1066. }
  1067. maxProfile.ChargingProfileId = -1;
  1068. maxProfile.StackLevel = -1;
  1069. while(getline(&line, &len, fp) != -1)
  1070. {
  1071. json_object *obj = NULL;
  1072. obj = json_tokener_parse(line);
  1073. if(is_error(obj))
  1074. {
  1075. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1076. }
  1077. else
  1078. {
  1079. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1080. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1081. )
  1082. {
  1083. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1084. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1085. )
  1086. {
  1087. struct tm tmFrom, tmTo;
  1088. struct timeb tbFrom, tbTo;
  1089. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  1090. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  1091. {
  1092. tmFrom.tm_year -= 1900;
  1093. tmFrom.tm_mon -= 1;
  1094. tbFrom.time = mktime(&tmFrom);
  1095. tmTo.tm_year -= 1900;
  1096. tmTo.tm_mon -= 1;
  1097. tbTo.time = mktime(&tmTo);
  1098. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1099. {
  1100. if(maxProfile.ChargingProfileId == -1)
  1101. DEBUG_INFO("MaxProfile found.\n");
  1102. else
  1103. DEBUG_INFO("MaxProfile updated.\n");
  1104. // Required item
  1105. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1106. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1107. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1108. if(isUnitA)
  1109. {
  1110. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1111. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1112. {
  1113. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1114. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1115. 3:
  1116. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1117. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1118. }
  1119. }
  1120. else
  1121. {
  1122. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1123. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1124. {
  1125. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1126. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1127. 3:
  1128. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1129. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1130. }
  1131. }
  1132. // Optional item
  1133. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1134. {
  1135. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1136. }
  1137. else
  1138. {
  1139. sprintf((char*)maxProfile.ValidFrom, " ");
  1140. }
  1141. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1142. {
  1143. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1144. }
  1145. else
  1146. {
  1147. sprintf((char*)maxProfile.ValidTo, " ");
  1148. }
  1149. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1150. {
  1151. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1152. }
  1153. else
  1154. {
  1155. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1156. }
  1157. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1158. {
  1159. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1160. }
  1161. else
  1162. {
  1163. maxProfile.TransactionId = -1;
  1164. }
  1165. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1166. {
  1167. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1168. }
  1169. else
  1170. {
  1171. maxProfile.ChargingSchedule.Duration = 86400;
  1172. }
  1173. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1174. {
  1175. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1176. }
  1177. else
  1178. {
  1179. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1180. }
  1181. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1182. {
  1183. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1184. }
  1185. else
  1186. {
  1187. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1188. }
  1189. }
  1190. }
  1191. }
  1192. else
  1193. {
  1194. if(maxProfile.ChargingProfileId == -1)
  1195. DEBUG_INFO("MaxProfile found.\n");
  1196. else
  1197. DEBUG_INFO("MaxProfile updated.\n");
  1198. // Required item
  1199. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1200. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1201. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1202. if(isUnitA)
  1203. {
  1204. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1205. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1206. {
  1207. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1208. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1209. 3:
  1210. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1211. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1212. }
  1213. }
  1214. else
  1215. {
  1216. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1217. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1218. {
  1219. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1220. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1221. 3:
  1222. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1223. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1224. }
  1225. }
  1226. // Optional item
  1227. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1228. {
  1229. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1230. }
  1231. else
  1232. {
  1233. sprintf((char*)maxProfile.ValidFrom, " ");
  1234. }
  1235. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1236. {
  1237. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1238. }
  1239. else
  1240. {
  1241. sprintf((char*)maxProfile.ValidTo, " ");
  1242. }
  1243. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1244. {
  1245. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1246. }
  1247. else
  1248. {
  1249. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1250. }
  1251. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1252. {
  1253. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1254. }
  1255. else
  1256. {
  1257. maxProfile.TransactionId = -1;
  1258. }
  1259. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1260. {
  1261. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1262. }
  1263. else
  1264. {
  1265. maxProfile.ChargingSchedule.Duration = 86400;
  1266. }
  1267. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1268. {
  1269. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1270. }
  1271. else
  1272. {
  1273. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1274. }
  1275. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1276. {
  1277. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1278. }
  1279. else
  1280. {
  1281. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1282. }
  1283. }
  1284. }
  1285. }
  1286. json_object_put(obj);
  1287. }
  1288. fclose(fp);
  1289. /*
  1290. if(maxProfile.ChargingProfileId !=-1)
  1291. {
  1292. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1293. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1294. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1295. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1296. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1297. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1298. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1299. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1300. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1301. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1302. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1303. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1304. {
  1305. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1306. {
  1307. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1308. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1309. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1310. }
  1311. }
  1312. }
  1313. else
  1314. DEBUG_INFO("MaxProfile not found.\n");
  1315. DEBUG_INFO("------------------------------------\n");*/
  1316. }
  1317. /*
  1318. * Align found profile start schedule & periods
  1319. */
  1320. //DEBUG_INFO("====================================\n");
  1321. /*
  1322. // For local test usage, force modify found profile start schedule info
  1323. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-10);
  1324. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-5);
  1325. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-3);
  1326. */
  1327. if(txProfile.ChargingProfileId != -1)
  1328. {
  1329. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1330. {
  1331. if(txProfile.ChargingSchedule.Duration != -1)
  1332. {
  1333. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1334. 0:
  1335. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1336. }
  1337. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1338. {
  1339. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1340. {
  1341. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1342. 0:
  1343. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1344. if(idxPeriod > 0)
  1345. {
  1346. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1347. {
  1348. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1349. }
  1350. }
  1351. }
  1352. }
  1353. }
  1354. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1355. {
  1356. if(txProfile.ChargingSchedule.Duration != -1)
  1357. {
  1358. txProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1359. 0:
  1360. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1361. }
  1362. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1363. {
  1364. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1365. {
  1366. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1367. 0:
  1368. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1369. if(idxPeriod > 0)
  1370. {
  1371. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1372. {
  1373. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1374. }
  1375. }
  1376. }
  1377. }
  1378. }
  1379. else
  1380. {
  1381. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1382. {
  1383. if(txProfile.ChargingSchedule.Duration != -1)
  1384. {
  1385. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1386. 0:
  1387. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1388. }
  1389. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1390. {
  1391. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1392. {
  1393. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1394. 0:
  1395. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1396. if(idxPeriod > 0)
  1397. {
  1398. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1399. {
  1400. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1401. }
  1402. }
  1403. }
  1404. }
  1405. }
  1406. else
  1407. {
  1408. if(txProfile.ChargingSchedule.Duration != -1)
  1409. {
  1410. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1411. 0:
  1412. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1413. }
  1414. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1415. {
  1416. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1417. {
  1418. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1419. 0:
  1420. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1421. if(idxPeriod > 0)
  1422. {
  1423. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1424. {
  1425. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1426. }
  1427. }
  1428. }
  1429. }
  1430. }
  1431. }
  1432. /*
  1433. DEBUG_INFO("txProfile after align.\n");
  1434. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1435. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1436. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1437. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1438. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1439. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1440. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1441. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1442. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1443. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1444. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1445. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1446. {
  1447. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1448. {
  1449. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1450. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1451. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1452. }
  1453. }*/
  1454. }
  1455. if(defaultTxProfile.ChargingProfileId != -1)
  1456. {
  1457. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1458. {
  1459. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1460. {
  1461. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1462. 0:
  1463. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1464. }
  1465. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1466. {
  1467. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1468. {
  1469. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1470. 0:
  1471. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1472. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1473. {
  1474. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1475. }
  1476. if(idxPeriod > 0)
  1477. {
  1478. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1479. {
  1480. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1481. }
  1482. }
  1483. }
  1484. }
  1485. }
  1486. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1487. {
  1488. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1489. {
  1490. defaultTxProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1491. 0:
  1492. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1493. }
  1494. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1495. {
  1496. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1497. {
  1498. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1499. 0:
  1500. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1501. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1502. {
  1503. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1504. }
  1505. if(idxPeriod > 0)
  1506. {
  1507. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1508. {
  1509. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1510. }
  1511. }
  1512. }
  1513. }
  1514. }
  1515. else
  1516. {
  1517. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1518. {
  1519. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1520. {
  1521. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1522. 0:
  1523. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1524. }
  1525. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1526. {
  1527. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1528. {
  1529. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1530. 0:
  1531. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1532. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1533. {
  1534. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1535. }
  1536. if(idxPeriod > 0)
  1537. {
  1538. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1539. {
  1540. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1541. }
  1542. }
  1543. }
  1544. }
  1545. }
  1546. else
  1547. {
  1548. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1549. {
  1550. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1551. 0:
  1552. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1553. }
  1554. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1555. {
  1556. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1557. {
  1558. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1559. 0:
  1560. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1561. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1562. {
  1563. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1564. }
  1565. if(idxPeriod > 0)
  1566. {
  1567. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1568. {
  1569. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1570. }
  1571. }
  1572. }
  1573. }
  1574. }
  1575. }
  1576. /*
  1577. DEBUG_INFO("defaultTxProfile after align.\n");
  1578. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1579. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1580. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1581. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1582. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1583. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1584. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1585. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1586. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1587. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1588. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1589. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1590. {
  1591. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1592. {
  1593. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1594. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1595. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1596. }
  1597. }
  1598. DEBUG_INFO("------------------------------------\n");*/
  1599. }
  1600. if(maxProfile.ChargingProfileId != -1)
  1601. {
  1602. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1603. {
  1604. if(maxProfile.ChargingSchedule.Duration != -1)
  1605. {
  1606. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1607. 0:
  1608. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1609. }
  1610. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1611. {
  1612. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1613. {
  1614. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1615. 0:
  1616. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1617. if(idxPeriod > 0)
  1618. {
  1619. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1620. {
  1621. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1622. }
  1623. }
  1624. }
  1625. }
  1626. }
  1627. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1628. {
  1629. if(maxProfile.ChargingSchedule.Duration != -1)
  1630. {
  1631. maxProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1632. 0:
  1633. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1634. }
  1635. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1636. {
  1637. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1638. {
  1639. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1640. 0:
  1641. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1642. if(idxPeriod > 0)
  1643. {
  1644. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1645. {
  1646. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1647. }
  1648. }
  1649. }
  1650. }
  1651. }
  1652. else
  1653. {
  1654. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1655. {
  1656. if(maxProfile.ChargingSchedule.Duration != -1)
  1657. {
  1658. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1659. 0:
  1660. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1661. }
  1662. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1663. {
  1664. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1665. {
  1666. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1667. 0:
  1668. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1669. if(idxPeriod > 0)
  1670. {
  1671. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1672. {
  1673. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1674. }
  1675. }
  1676. }
  1677. }
  1678. }
  1679. else
  1680. {
  1681. if(maxProfile.ChargingSchedule.Duration != -1)
  1682. {
  1683. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1684. 0:
  1685. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1686. }
  1687. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1688. {
  1689. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1690. {
  1691. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1692. 0:
  1693. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1694. if(idxPeriod > 0)
  1695. {
  1696. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1697. {
  1698. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1699. }
  1700. }
  1701. }
  1702. }
  1703. }
  1704. }
  1705. /*
  1706. DEBUG_INFO("MaxProfile after align.\n");
  1707. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1708. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1709. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1710. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1711. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1712. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1713. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1714. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1715. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1716. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1717. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1718. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1719. {
  1720. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1721. {
  1722. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1723. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1724. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1725. }
  1726. }
  1727. DEBUG_INFO("------------------------------------\n");*/
  1728. }
  1729. /*
  1730. * Merge to conposite schedule
  1731. */
  1732. //DEBUG_INFO("====================================\n");
  1733. // Find each profile period quantity
  1734. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1735. {
  1736. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1737. limitMax = idx+1;
  1738. }
  1739. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1740. {
  1741. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1742. limitDef = idx+1;
  1743. }
  1744. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1745. {
  1746. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1747. limitTx = idx+1;
  1748. }
  1749. // TxProfile found, composite schedule based on it
  1750. if(txProfile.ChargingProfileId != -1)
  1751. {
  1752. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  1753. {
  1754. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  1755. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  1756. (txProfile.ChargingSchedule.Duration > 0))
  1757. {
  1758. if(maxProfile.ChargingProfileId != -1)
  1759. {
  1760. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1761. {
  1762. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  1763. {
  1764. if((maxProfile.ChargingSchedule.Duration > 0))
  1765. {
  1766. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1767. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1768. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1769. }
  1770. else
  1771. {
  1772. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1773. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1774. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  1775. }
  1776. }
  1777. if(idxMaxPeriod == (limitMax-1))
  1778. {
  1779. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1780. {
  1781. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1782. {
  1783. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1784. compositePeriodIdx++;
  1785. }
  1786. else
  1787. {
  1788. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1789. }
  1790. }
  1791. }
  1792. }
  1793. }
  1794. else
  1795. {
  1796. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1797. {
  1798. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1799. compositePeriodIdx++;
  1800. }
  1801. else
  1802. {
  1803. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1804. }
  1805. }
  1806. }
  1807. if(idxTxPeriod == (limitTx-1))
  1808. {
  1809. if(defaultTxProfile.ChargingProfileId != -1)
  1810. {
  1811. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1812. {
  1813. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  1814. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  1815. (defaultTxProfile.ChargingSchedule.Duration>0))
  1816. {
  1817. if(maxProfile.ChargingProfileId != -1)
  1818. {
  1819. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1820. {
  1821. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1822. {
  1823. if((maxProfile.ChargingSchedule.Duration > 0))
  1824. {
  1825. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1826. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1827. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1828. }
  1829. else
  1830. {
  1831. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1832. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1833. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  1834. }
  1835. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1836. {
  1837. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1838. {
  1839. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1840. compositePeriodIdx++;
  1841. }
  1842. else
  1843. {
  1844. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1845. }
  1846. }
  1847. break;
  1848. }
  1849. }
  1850. }
  1851. else
  1852. {
  1853. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1854. {
  1855. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1856. compositePeriodIdx++;
  1857. }
  1858. else
  1859. {
  1860. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1861. }
  1862. }
  1863. }
  1864. }
  1865. }
  1866. }
  1867. }
  1868. }
  1869. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  1870. else if(defaultTxProfile.ChargingProfileId != -1)
  1871. {
  1872. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1873. {
  1874. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  1875. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  1876. (defaultTxProfile.ChargingSchedule.Duration > 0))
  1877. {
  1878. if(maxProfile.ChargingProfileId != -1)
  1879. {
  1880. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1881. {
  1882. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1883. {
  1884. if((maxProfile.ChargingSchedule.Duration > 0))
  1885. {
  1886. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1887. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1888. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  1889. }
  1890. else
  1891. {
  1892. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1893. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1894. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  1895. }
  1896. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1897. {
  1898. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1899. {
  1900. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1901. compositePeriodIdx++;
  1902. }
  1903. else
  1904. {
  1905. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1906. }
  1907. }
  1908. break;
  1909. }
  1910. }
  1911. }
  1912. else
  1913. {
  1914. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1915. {
  1916. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1917. compositePeriodIdx++;
  1918. }
  1919. else
  1920. {
  1921. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1922. }
  1923. }
  1924. }
  1925. }
  1926. }
  1927. // Fill other period by MaxProfile
  1928. if(maxProfile.ChargingProfileId != -1)
  1929. {
  1930. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1931. {
  1932. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1933. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1934. (maxProfile.ChargingSchedule.Duration > 0))
  1935. {
  1936. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  1937. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  1938. {
  1939. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  1940. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  1941. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1942. }
  1943. if((maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  1944. {
  1945. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.Duration;
  1946. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  1947. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1948. }
  1949. if(tmpPeriod.Limit != -1)
  1950. {
  1951. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1952. {
  1953. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1954. {
  1955. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1956. compositePeriodIdx++;
  1957. }
  1958. else
  1959. {
  1960. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1961. }
  1962. }
  1963. }
  1964. }
  1965. }
  1966. }
  1967. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  1968. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1969. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1970. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1971. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1972. {
  1973. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1974. {
  1975. compositeProfile->ChargingProfileId = 1;
  1976. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1977. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1978. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1979. }
  1980. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1981. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1982. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1983. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1984. }
  1985. if(line)
  1986. free(line);
  1987. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  1988. }
  1989. //==========================================
  1990. // Init all share memory
  1991. //==========================================
  1992. int InitShareMemory()
  1993. {
  1994. int result = PASS;
  1995. int MeterSMId;
  1996. //creat ShmSysConfigAndInfo
  1997. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  1998. {
  1999. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  2000. result = FAIL;
  2001. }
  2002. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2003. {
  2004. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  2005. result = FAIL;
  2006. }
  2007. else
  2008. {}
  2009. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  2010. {
  2011. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  2012. result = FAIL;
  2013. }
  2014. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2015. {
  2016. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  2017. result = FAIL;
  2018. }
  2019. else
  2020. {}
  2021. //creat ShmPsuData
  2022. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  2023. {
  2024. DEBUG_ERROR("shmget ShmPsuData NG\n");
  2025. result = FAIL;
  2026. }
  2027. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2028. {
  2029. DEBUG_ERROR("shmat ShmPsuData NG\n");
  2030. result = FAIL;
  2031. }
  2032. else
  2033. {}
  2034. //creat ShmOCPP16Data
  2035. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  2036. {
  2037. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  2038. result = FAIL;
  2039. }
  2040. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2041. {
  2042. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  2043. result = FAIL;
  2044. }
  2045. else
  2046. {}
  2047. /****************************** For Initial Settings************************************************/
  2048. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  2049. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  2050. // allocate Configuration memory address
  2051. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  2052. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  2053. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  2054. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  2055. //offline MeterValue Interval
  2056. TempMeterValueInterval = 0;
  2057. return result;
  2058. }
  2059. int ProcessShareMemory()
  2060. {
  2061. if(InitShareMemory() == FAIL)
  2062. {
  2063. DEBUG_ERROR("InitShareMemory NG\n");
  2064. if(ShmStatusCodeData!=NULL)
  2065. {
  2066. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  2067. }
  2068. sleep(5);
  2069. return FAIL;
  2070. }
  2071. return PASS;
  2072. }
  2073. //---------------------common routine---------------------------//
  2074. //---------------------------------------------
  2075. // new:
  2076. // enum SYSTEM_STATUS
  2077. // {
  2078. // SYS_MODE_BOOTING = 0,
  2079. // SYS_MODE_IDLE = 1,
  2080. // SYS_MODE_AUTHORIZING = 2,
  2081. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  2082. // SYS_MODE_REASSIGN = 4,
  2083. // SYS_MODE_PREPARING = 5,
  2084. // SYS_MODE_PREPARE_FOR_EV = 6,
  2085. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  2086. // SYS_MODE_CHARGING = 8,
  2087. // SYS_MODE_TERMINATING = 9,
  2088. // SYS_MODE_COMPLETE = 10,
  2089. // SYS_MODE_ALARM = 11,
  2090. // SYS_MODE_FAULT = 12,
  2091. // SYS_MODE_RESERVATION = 13,
  2092. // SYS_MODE_BOOKING = 14,
  2093. // SYS_MODE_MAINTAIN = 15,
  2094. // SYS_MODE_DEBUG = 16,
  2095. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  2096. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  2097. // SYS_MODE_UPDATE = 19
  2098. // };
  2099. //
  2100. //
  2101. //-----------------------------------------
  2102. void CheckSystemValue(void)
  2103. {
  2104. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  2105. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  2106. char filenmae[100]={0};
  2107. char str[100]={0};
  2108. int tempIndex = 0;
  2109. //===============================
  2110. // send Heartbeat
  2111. //===============================
  2112. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2113. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2114. {
  2115. clientTime.Heartbeat=time((time_t*)NULL);
  2116. if(server_sign == TRUE)
  2117. {
  2118. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2119. }
  2120. else
  2121. {
  2122. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2123. }
  2124. }
  2125. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  2126. {
  2127. //parameter for test
  2128. sendHeartbeatRequest(0);
  2129. //==============================================
  2130. // Reset Waiting Time
  2131. //==============================================
  2132. HeartBeatWithNOResponse += 1;
  2133. }
  2134. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2135. {
  2136. //==========================================
  2137. // csu trigger DataTransferReq
  2138. //==========================================
  2139. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2140. {
  2141. sendDataTransferRequest(gun_index);
  2142. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2143. }
  2144. //===============================
  2145. // CSU Trigger Reset Conf
  2146. //===============================
  2147. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  2148. {
  2149. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  2150. }
  2151. //===============================
  2152. // CSU Trigger Authorize Request
  2153. //===============================
  2154. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2155. {
  2156. sendAuthorizeRequest(0);
  2157. authorizeRetryTimes = authorizeRetryTimes + 1;
  2158. if(authorizeRetryTimes < 3)
  2159. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2160. }
  2161. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  2162. {
  2163. authorizeRetryTimes = 0;
  2164. SetOcppConnStatus(FALSE);
  2165. server_sign = FALSE;
  2166. }
  2167. else if((server_sign == FALSE) && (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0)&& (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1))
  2168. {
  2169. sendAuthorizeRequest(0);
  2170. }
  2171. //==============================================
  2172. // CSU Trigger Smart Charging Profilw
  2173. //==============================================
  2174. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2175. {
  2176. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  2177. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2178. }
  2179. //==============================================
  2180. // Charger start transaction
  2181. //==============================================
  2182. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2183. {
  2184. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  2185. sendStartTransactionRequest(gun_index);
  2186. clientTime.StartTransaction = time((time_t*)NULL);
  2187. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2188. storeTempStopTransaction(gun_index);
  2189. }
  2190. //==============================================
  2191. // Charger stop transaction
  2192. //==============================================
  2193. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2194. {
  2195. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2196. sendStopTransactionRequest(gun_index);
  2197. clientTime.StopTransaction = time((time_t*)NULL);
  2198. }
  2199. //==============================================
  2200. // Charger status report
  2201. //==============================================
  2202. //--- Check Mode Change ---//
  2203. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2204. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2205. {
  2206. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2207. {
  2208. tempIndex = ((gun_index==2) ? 1: 0);
  2209. }
  2210. else
  2211. {
  2212. tempIndex = gun_index;
  2213. }
  2214. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2215. {
  2216. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2217. {
  2218. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  2219. {
  2220. // Sent unplug message for California pricing logic
  2221. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  2222. {
  2223. uint8_t ts[20];
  2224. getNowDatetime(ts);
  2225. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2226. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2227. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2228. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2229. }
  2230. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2231. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2232. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2233. statusModeChage[gun_index] = TRUE;
  2234. }
  2235. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2236. {
  2237. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2238. if((access(filenmae,F_OK))!=-1)
  2239. {
  2240. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2241. sprintf(str,"rm -f %s",filenmae);
  2242. system(str);
  2243. }
  2244. }
  2245. #if 1 // for TempStopTransaction
  2246. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2247. {
  2248. checkTempStopTransaction(gun_index);
  2249. }
  2250. #endif
  2251. }
  2252. }
  2253. }
  2254. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2255. {
  2256. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2257. {
  2258. tempIndex = ((gun_index==2) ? 1: 0);
  2259. }
  2260. else
  2261. {
  2262. tempIndex = gun_index;
  2263. }
  2264. for (int index = 0; index < CCS_QUANTITY; index++)
  2265. {
  2266. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2267. {
  2268. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn != CcsPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  2269. {
  2270. // Sent unplug message for California pricing logic
  2271. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  2272. {
  2273. uint8_t ts[20];
  2274. getNowDatetime(ts);
  2275. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2276. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2277. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2278. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2279. }
  2280. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2281. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2282. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2283. statusModeChage[gun_index] = TRUE;
  2284. }
  2285. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2286. {
  2287. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2288. if((access(filenmae,F_OK))!=-1)
  2289. {
  2290. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2291. sprintf(str,"rm -f %s",filenmae);
  2292. system(str);
  2293. }
  2294. }
  2295. #if 1 // for TempStopTransaction
  2296. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2297. {
  2298. checkTempStopTransaction(gun_index);
  2299. }
  2300. #endif
  2301. }
  2302. }
  2303. }
  2304. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2305. {
  2306. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2307. {
  2308. tempIndex = ((gun_index==2) ? 1: 0);
  2309. }
  2310. else
  2311. {
  2312. tempIndex = gun_index;
  2313. }
  2314. for (int index = 0; index < GB_QUANTITY; index++)
  2315. {
  2316. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2317. {
  2318. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2319. {
  2320. // Sent unplug message for California pricing logic
  2321. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  2322. {
  2323. uint8_t ts[20];
  2324. getNowDatetime(ts);
  2325. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2326. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2327. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2328. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2329. }
  2330. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2331. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2332. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2333. statusModeChage[gun_index] = TRUE;
  2334. }
  2335. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2336. {
  2337. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2338. if((access(filenmae,F_OK))!=-1)
  2339. {
  2340. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2341. sprintf(str,"rm -f %s",filenmae);
  2342. system(str);
  2343. }
  2344. }
  2345. #if 1 // for TempStopTransaction
  2346. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2347. {
  2348. checkTempStopTransaction(gun_index);
  2349. }
  2350. #endif
  2351. }
  2352. }
  2353. }
  2354. else if(gunType[gun_index] == GUN_TYPE_DO)
  2355. {
  2356. tempIndex = gun_index;
  2357. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2358. {
  2359. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2360. {
  2361. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  2362. {
  2363. // Sent unplug message for California pricing logic
  2364. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  2365. {
  2366. uint8_t ts[20];
  2367. getNowDatetime(ts);
  2368. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2369. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2370. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2371. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2372. }
  2373. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  2374. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  2375. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2376. statusModeChage[gun_index] = TRUE;
  2377. }
  2378. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARING))) // complete
  2379. {
  2380. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2381. if((access(filenmae,F_OK))!=-1)
  2382. {
  2383. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2384. sprintf(str,"rm -f %s",filenmae);
  2385. system(str);
  2386. }
  2387. }
  2388. #if 1 // for TempStopTransaction
  2389. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2390. {
  2391. checkTempStopTransaction(gun_index);
  2392. }
  2393. #endif
  2394. }
  2395. }
  2396. }
  2397. else
  2398. {
  2399. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2400. {
  2401. tempIndex = 2;
  2402. }
  2403. else
  2404. {
  2405. tempIndex = gun_index;
  2406. }
  2407. for (int index = 0; index < AC_QUANTITY; index++)
  2408. {
  2409. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2410. {
  2411. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2412. {
  2413. // Sent unplug message for California pricing logic
  2414. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)
  2415. {
  2416. uint8_t ts[20];
  2417. getNowDatetime(ts);
  2418. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2419. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2420. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2421. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2422. }
  2423. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2424. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2425. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2426. statusModeChage[gun_index] = TRUE;
  2427. }
  2428. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2429. {
  2430. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2431. if((access(filenmae,F_OK))!=-1)
  2432. {
  2433. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2434. sprintf(str,"rm -f %s",filenmae);
  2435. system(str);
  2436. }
  2437. }
  2438. #if 1 // for TempStopTransaction
  2439. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2440. {
  2441. checkTempStopTransaction(gun_index);
  2442. }
  2443. #endif
  2444. }
  2445. }// END
  2446. }
  2447. if(isWebsocketSendable &&
  2448. (
  2449. (statusModeChage[gun_index] == TRUE) ||
  2450. //((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index))) ||
  2451. ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 10))
  2452. )
  2453. )
  2454. {
  2455. if(SystemInitial > 0)
  2456. SystemInitial -= 1;
  2457. sendStatusNotificationRequest(gun_index);
  2458. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2459. statusModeChage[gun_index] = FALSE;
  2460. }
  2461. //==============================================
  2462. // Meter report
  2463. //==============================================
  2464. // Trigger MeterValue
  2465. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  2466. {
  2467. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  2468. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  2469. }
  2470. // ClockAlign MeterValue
  2471. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  2472. {
  2473. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2474. {
  2475. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2476. {
  2477. tempIndex = ((gun_index==2) ? 1: 0);
  2478. }
  2479. else
  2480. {
  2481. tempIndex = gun_index;
  2482. }
  2483. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2484. {
  2485. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2486. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2487. {
  2488. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2489. {
  2490. reqClockAlignMeter[gun_index] = 1;
  2491. }
  2492. }
  2493. }// End for CHAdeMO
  2494. }
  2495. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2496. {
  2497. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2498. {
  2499. tempIndex = ((gun_index==2) ? 1: 0);
  2500. }
  2501. else
  2502. {
  2503. tempIndex = gun_index;
  2504. }
  2505. for (int index = 0; index < CCS_QUANTITY; index++)
  2506. {
  2507. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2508. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2509. {
  2510. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2511. {
  2512. reqClockAlignMeter[gun_index] = 1;
  2513. }
  2514. }
  2515. } // End for CCS
  2516. }
  2517. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2518. {
  2519. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2520. {
  2521. tempIndex = ((gun_index==2) ? 1: 0);
  2522. }
  2523. else
  2524. {
  2525. tempIndex = gun_index;
  2526. }
  2527. for (int index = 0; index < GB_QUANTITY; index++)
  2528. {
  2529. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2530. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2531. {
  2532. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2533. {
  2534. reqClockAlignMeter[gun_index] = 1;
  2535. }
  2536. }
  2537. }// End for GB
  2538. }
  2539. else if(gunType[gun_index] == GUN_TYPE_DO)
  2540. {
  2541. tempIndex = gun_index;
  2542. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2543. {
  2544. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2545. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2546. {
  2547. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_CHARGING)
  2548. {
  2549. reqClockAlignMeter[gun_index] = 1;
  2550. }
  2551. }
  2552. }
  2553. }
  2554. else
  2555. {
  2556. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2557. {
  2558. tempIndex = 2;
  2559. }
  2560. else
  2561. {
  2562. tempIndex = gun_index;
  2563. }
  2564. for (int index = 0; index < AC_QUANTITY; index++)
  2565. {
  2566. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2567. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2568. {
  2569. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2570. {
  2571. reqClockAlignMeter[gun_index] = 1;
  2572. }
  2573. }
  2574. }//End for AC
  2575. }
  2576. if(reqClockAlignMeter[gun_index] == 1)
  2577. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2578. }
  2579. // Sample period MeterValue
  2580. if((((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1))))
  2581. {
  2582. //check Transaction active
  2583. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2584. {
  2585. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2586. {
  2587. tempIndex = ((gun_index==2) ? 1: 0);
  2588. }
  2589. else
  2590. {
  2591. tempIndex = gun_index;
  2592. }
  2593. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2594. {
  2595. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2596. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2597. {
  2598. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2599. {
  2600. reqSampleMeter[gun_index] = 1;
  2601. }
  2602. }
  2603. }// End for CHAdeMO
  2604. }
  2605. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2606. {
  2607. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2608. {
  2609. tempIndex = ((gun_index==2) ? 1: 0);
  2610. }
  2611. else
  2612. {
  2613. tempIndex = gun_index;
  2614. }
  2615. for (int index = 0; index < CCS_QUANTITY; index++)
  2616. {
  2617. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2618. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2619. {
  2620. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2621. {
  2622. reqSampleMeter[gun_index] = 1;
  2623. }
  2624. }
  2625. } // End for CCS
  2626. }
  2627. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2628. {
  2629. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2630. {
  2631. tempIndex = ((gun_index==2) ? 1: 0);
  2632. }
  2633. else
  2634. {
  2635. tempIndex = gun_index;
  2636. }
  2637. for (int index = 0; index < GB_QUANTITY; index++)
  2638. {
  2639. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2640. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2641. {
  2642. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2643. {
  2644. reqSampleMeter[gun_index] = 1;
  2645. }
  2646. }
  2647. }// End for GB
  2648. }
  2649. else if(gunType[gun_index] == GUN_TYPE_DO)
  2650. {
  2651. tempIndex = gun_index;
  2652. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2653. {
  2654. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2655. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2656. {
  2657. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  2658. {
  2659. reqSampleMeter[gun_index] = 1;
  2660. }
  2661. }
  2662. }
  2663. }
  2664. else
  2665. {
  2666. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2667. {
  2668. tempIndex = 2;
  2669. }
  2670. else
  2671. {
  2672. tempIndex = gun_index;
  2673. }
  2674. for (int index = 0; index < AC_QUANTITY; index++)
  2675. {
  2676. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2677. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2678. {
  2679. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  2680. {
  2681. reqSampleMeter[gun_index] = 1;
  2682. }
  2683. }
  2684. }//End for AC
  2685. }
  2686. if(reqSampleMeter[gun_index] == 1)
  2687. {
  2688. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  2689. storeTempStopTransaction(gun_index);
  2690. }
  2691. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2692. }
  2693. //==============================================
  2694. // Check Connector reserved
  2695. //==============================================
  2696. //===============================
  2697. // Check if Reserve is expired
  2698. //===============================
  2699. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  2700. {
  2701. double diff_t;
  2702. struct tm tp;
  2703. // current time
  2704. time_t t = time(NULL);
  2705. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  2706. tp.tm_isdst = -1;
  2707. time_t utc = mktime(&tp);
  2708. diff_t = difftime(utc, t);
  2709. if(diff_t <= 0)
  2710. {
  2711. DEBUG_INFO("reserve expired.\n");
  2712. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  2713. }
  2714. }//END OF Check if Reserve is expired
  2715. //==========================================
  2716. // csu trigger FirmwareStatusNotificationReq
  2717. //==========================================
  2718. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  2719. {
  2720. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  2721. }
  2722. //==========================================
  2723. // csu trigger CancelReservationConf
  2724. //==========================================
  2725. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  2726. {
  2727. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  2728. }
  2729. //==========================================
  2730. // csu trigger ChangeAvailabilityConf
  2731. //==========================================
  2732. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  2733. {
  2734. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  2735. }
  2736. //==========================================
  2737. // csu trigger UnlockConnectorConf
  2738. //==========================================
  2739. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  2740. {
  2741. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  2742. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  2743. }
  2744. //==========================================
  2745. // csu trigger ReserveNowConf
  2746. //==========================================
  2747. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  2748. {
  2749. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  2750. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  2751. }
  2752. }
  2753. }
  2754. //==========================================
  2755. // send request routine
  2756. //==========================================
  2757. int sendAuthorizeRequest(int gun_index)
  2758. {
  2759. mtrace();
  2760. int result = FAIL;
  2761. char message[100]={0};
  2762. char guid[37];
  2763. char tempdata[65]={0};
  2764. DEBUG_INFO("sendAuthorizeRequest...\n");
  2765. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  2766. //Local Authorize
  2767. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  2768. {
  2769. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  2770. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2771. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  2772. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  2773. result = PASS;
  2774. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2775. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2776. authorizeRetryTimes = 0;
  2777. return result;
  2778. }
  2779. else if(((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0))||
  2780. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  2781. {
  2782. // Query from cache
  2783. DEBUG_INFO("Authorize from cache.\n");
  2784. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2785. // Query from list
  2786. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  2787. {
  2788. DEBUG_INFO("Authorize from list.\n");
  2789. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2790. }
  2791. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  2792. {
  2793. if(strcmp(idTagQuery.idTagstr,"") == 0)
  2794. {
  2795. DEBUG_INFO("off-line Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  2796. }
  2797. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  2798. {
  2799. DEBUG_INFO("off-line Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  2800. }
  2801. DEBUG_INFO("off-line Local Authorization Fail !!!!\n");
  2802. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2803. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2804. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  2805. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  2806. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2807. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2808. authorizeRetryTimes = 0;
  2809. return result;
  2810. }
  2811. else
  2812. {
  2813. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  2814. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  2815. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2816. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  2817. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  2818. else
  2819. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  2820. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  2821. result = PASS;
  2822. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2823. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2824. authorizeRetryTimes = 0;
  2825. return result;
  2826. }
  2827. }
  2828. //initialize struct Authorize
  2829. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  2830. //get data from shared memory
  2831. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2832. random_uuid(guid);
  2833. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  2834. LWS_Send(message);
  2835. sprintf(tempdata, "Authorize,%d", gun_index);
  2836. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2837. {
  2838. result = PASS;
  2839. DEBUG_INFO("Authorize mapItem pass\n");
  2840. }
  2841. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2842. return result;
  2843. }
  2844. int sendBootNotificationRequest(void)
  2845. {
  2846. mtrace();
  2847. int result = FAIL;
  2848. char message[500]={0}, payload[700]={0};
  2849. char guid[37]={0};
  2850. char tempdata[65]={0};
  2851. // Fill BootNotification fields
  2852. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  2853. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  2854. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  2855. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2856. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  2857. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  2858. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  2859. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  2860. ShmOCPP16Data->ChargeBoxId
  2861. ,ShmSysConfigAndInfo->SysConfig.ModelName
  2862. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  2863. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  2864. ,ShmOCPP16Data->BootNotification.CpFwVersion
  2865. ,ShmOCPP16Data->BootNotification.CpIccid
  2866. ,ShmOCPP16Data->BootNotification.CpImsi);
  2867. random_uuid(guid);
  2868. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  2869. LWS_Send(message);
  2870. sprintf(tempdata, "BootNotification,0");
  2871. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid,mapItem, tempdata/*(void**)(&mapItem)*//*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  2872. {
  2873. result = PASS;
  2874. }
  2875. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  2876. strcpy(queuedata,message);
  2877. return result;
  2878. }
  2879. int sendDataTransferRequest(int gun_index)
  2880. {
  2881. mtrace();
  2882. char message[1000]={0};
  2883. char guid[37]={0};
  2884. char tempdata[65]={0};
  2885. int result = FAIL;
  2886. random_uuid(guid);
  2887. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  2888. MESSAGE_TYPE_CALL,
  2889. guid,
  2890. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  2891. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  2892. ShmOCPP16Data->DataTransfer[gun_index].Data);
  2893. LWS_Send(message);
  2894. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  2895. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2896. {
  2897. result = PASS;
  2898. DEBUG_INFO("DataTransfer mapItem pass\n");
  2899. }
  2900. return result;
  2901. }
  2902. int sendDiagnosticsStatusNotificationRequest(char *status)
  2903. {
  2904. mtrace();
  2905. int result = FAIL;
  2906. char message[110]={0};
  2907. char guid[37]={0};
  2908. char tempdata[65]={0};
  2909. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  2910. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  2911. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  2912. random_uuid(guid);
  2913. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  2914. LWS_SendNow(message);
  2915. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  2916. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2917. {
  2918. result = PASS;
  2919. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  2920. }
  2921. //#ifdef SystemLogMessage
  2922. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  2923. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2924. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  2925. //#endif
  2926. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  2927. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  2928. //record status
  2929. if(strcmp(status,"Idle")==0)
  2930. {
  2931. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  2932. }
  2933. else if(strcmp(status,"Uploaded")==0)
  2934. {
  2935. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  2936. }
  2937. else if(strcmp(status,"UploadFailed")==0)
  2938. {
  2939. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  2940. }
  2941. else if(strcmp(status,"Uploading")==0)
  2942. {
  2943. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  2944. }
  2945. return result;
  2946. }
  2947. int sendFirmwareStatusNotificationRequest(char *status)
  2948. {
  2949. mtrace();
  2950. int result = FAIL;
  2951. char message[110]={0};
  2952. char guid[37]={0};
  2953. char tempdata[65]={0};
  2954. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  2955. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  2956. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  2957. random_uuid(guid);
  2958. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  2959. LWS_SendNow(message);
  2960. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  2961. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  2962. {
  2963. result = PASS;
  2964. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  2965. }
  2966. //#ifdef SystemLogMessage
  2967. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  2968. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2969. //#endif
  2970. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  2971. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  2972. //record status
  2973. if(strcmp(status,"Downloaded")==0)
  2974. {
  2975. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  2976. }
  2977. else if(strcmp(status,"DownloadFailed")==0)
  2978. {
  2979. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  2980. }
  2981. else if(strcmp(status,"Downloading")==0)
  2982. {
  2983. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  2984. }
  2985. else if(strcmp(status,"Idle")==0)
  2986. {
  2987. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  2988. }
  2989. else if(strcmp(status,"InstallationFailed")==0)
  2990. {
  2991. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  2992. }
  2993. else if(strcmp(status,"Installing")==0)
  2994. {
  2995. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  2996. }
  2997. else if(strcmp(status,"Installed")==0)
  2998. {
  2999. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  3000. }
  3001. return result;
  3002. }
  3003. int sendHeartbeatRequest(int gun_index)
  3004. {
  3005. mtrace();
  3006. int result = FAIL;
  3007. char message[80]={0};
  3008. char guid[37]={0};
  3009. char tempdata[65]={0};
  3010. random_uuid(guid);
  3011. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  3012. , MESSAGE_TYPE_CALL
  3013. , guid );
  3014. LWS_Send(message);
  3015. sprintf(tempdata, "Heartbeat,%d", 0);
  3016. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid, mapItem, tempdata/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  3017. {
  3018. result = PASS;
  3019. }
  3020. return result;
  3021. }
  3022. int sendStartTransactionRequest(int gun_index)
  3023. {
  3024. mtrace();
  3025. int result = FAIL;
  3026. char message[250]={0};
  3027. char guid[37]={0};
  3028. struct timeval tmnow;
  3029. struct tm *tm;
  3030. char buf[28];//, usec_buf[6];
  3031. char tempdata[65]={0};
  3032. int tempIndex = 0;
  3033. DEBUG_INFO("sendStartTransactionRequest...\n");
  3034. gettimeofday(&tmnow, NULL);
  3035. time_t t;
  3036. t = time(NULL);
  3037. /*UTC time and date*/
  3038. tm = gmtime(&t);
  3039. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3040. #if 0 // remove temporally
  3041. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3042. strcat(buf,".");
  3043. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3044. strcat(buf,usec_buf);
  3045. #endif
  3046. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  3047. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  3048. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3049. // clear StartTransaction Response
  3050. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  3051. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  3052. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  3053. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  3054. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3055. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3056. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3057. {
  3058. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3059. {
  3060. tempIndex = ((gun_index==2) ? 1: 0);
  3061. }
  3062. else
  3063. {
  3064. tempIndex = gun_index;
  3065. }
  3066. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3067. {
  3068. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3069. {
  3070. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3071. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  3072. }
  3073. }
  3074. }
  3075. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3076. {
  3077. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3078. {
  3079. tempIndex = ((gun_index==2) ? 1: 0);
  3080. }
  3081. else
  3082. {
  3083. tempIndex = gun_index;
  3084. }
  3085. for (int index = 0; index < CCS_QUANTITY; index++)
  3086. {
  3087. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3088. {
  3089. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3090. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  3091. }
  3092. }
  3093. }
  3094. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3095. {
  3096. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3097. {
  3098. tempIndex = ((gun_index==2) ? 1: 0);
  3099. }
  3100. else
  3101. {
  3102. tempIndex = gun_index;
  3103. }
  3104. for (int index = 0; index < GB_QUANTITY; index++)
  3105. {
  3106. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3107. {
  3108. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3109. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  3110. }
  3111. }
  3112. }
  3113. else if(gunType[gun_index] == GUN_TYPE_DO)
  3114. {
  3115. tempIndex = gun_index;
  3116. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3117. {
  3118. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3119. {
  3120. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3121. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  3122. }
  3123. }
  3124. }
  3125. else
  3126. {
  3127. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3128. {
  3129. tempIndex = 2;
  3130. }
  3131. else
  3132. {
  3133. tempIndex = gun_index;
  3134. }
  3135. for (int index = 0; index < AC_QUANTITY; index++)
  3136. {
  3137. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3138. {
  3139. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3140. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  3141. }
  3142. }
  3143. }
  3144. random_uuid(guid);
  3145. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  3146. {
  3147. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  3148. , gun_index +1
  3149. , MESSAGE_TYPE_CALL
  3150. , guid
  3151. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3152. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3153. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3154. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3155. }
  3156. else
  3157. {
  3158. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  3159. , gun_index +1
  3160. , MESSAGE_TYPE_CALL
  3161. , guid
  3162. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3163. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3164. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3165. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  3166. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3167. }
  3168. #if 1
  3169. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  3170. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  3171. {
  3172. result = PASS;
  3173. }
  3174. #endif
  3175. strcpy(queuedata, message);
  3176. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3177. return result;
  3178. }
  3179. int sendStatusNotificationRequest(int gun_index)
  3180. {
  3181. mtrace();
  3182. int result = FAIL;
  3183. char message[600]={0};
  3184. char guid[37];
  3185. int currentStatus = 0;
  3186. struct timeval tmnow;
  3187. struct tm *tm;
  3188. char buf[28];//, usec_buf[6];
  3189. char tempdata[65]={0};
  3190. int tempIndex = 0;
  3191. gettimeofday(&tmnow, NULL);
  3192. time_t t;
  3193. t = time(NULL);
  3194. /*UTC time and date*/
  3195. tm = gmtime(&t);
  3196. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3197. #if 0 // remove temporally
  3198. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3199. strcat(buf,".");
  3200. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3201. strcat(buf,usec_buf);
  3202. #endif
  3203. printf("%s",buf);
  3204. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  3205. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  3206. // it's option
  3207. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  3208. /*
  3209. enum _SYSTEM_STATUS
  3210. {
  3211. S_BOOTING = 0,
  3212. S_IDLE, = 1
  3213. S_AUTHORIZING, =2
  3214. S_REASSIGN_CHECK, =3
  3215. S_REASSIGN, =4
  3216. S_PRECHARGE, =5
  3217. S_PREPARING_FOR_EV, =6
  3218. S_PREPARING_FOR_EVSE, =7
  3219. S_CHARGING, =8
  3220. S_TERMINATING, =9
  3221. S_COMPLETE, =10
  3222. S_ALARM, =11
  3223. S_FAULT =12
  3224. }
  3225. */
  3226. //check Transaction active
  3227. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3228. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3229. {
  3230. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3231. {
  3232. tempIndex = ((gun_index==2) ? 1: 0);
  3233. }
  3234. else
  3235. {
  3236. tempIndex = gun_index;
  3237. }
  3238. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3239. {
  3240. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  3241. {
  3242. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  3243. {
  3244. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3245. {
  3246. currentStatus = Preparing; //OCPP Status: Preparing
  3247. }
  3248. else
  3249. {
  3250. currentStatus = Available; //OCPP Status: Available
  3251. }
  3252. }
  3253. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3254. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3255. ) //S_PRECHARGE
  3256. {
  3257. currentStatus = Preparing; //OCPP Status: Preparing
  3258. }
  3259. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3260. {
  3261. currentStatus = Charging; //OCPP Status: Charging
  3262. }
  3263. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3264. {
  3265. currentStatus = Finishing; //OCPP Status: Finishing
  3266. }
  3267. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3268. {
  3269. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3270. }
  3271. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  3272. {
  3273. currentStatus = Unavailable; //OCPP Status: Unavailable
  3274. }
  3275. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3276. {
  3277. currentStatus = Faulted; //OCPP Status: Faulted
  3278. }
  3279. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3280. {
  3281. currentStatus = Reserved; //OCPP Status: Reserved
  3282. }
  3283. } //end of the same index
  3284. }//end of for CHAdeMO_QUANTITY
  3285. }
  3286. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3287. {
  3288. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3289. {
  3290. tempIndex = ((gun_index==2) ? 1: 0);
  3291. }
  3292. else
  3293. {
  3294. tempIndex = gun_index;
  3295. }
  3296. for (int index = 0; index < CCS_QUANTITY; index++)
  3297. {
  3298. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3299. {
  3300. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3301. {
  3302. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3303. {
  3304. currentStatus = Preparing; //OCPP Status: Preparing
  3305. }
  3306. else
  3307. {
  3308. currentStatus = Available; //OCPP Status: Available
  3309. }
  3310. }
  3311. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3312. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3313. ) //S_PRECHARGE
  3314. {
  3315. currentStatus = Preparing; //OCPP Status: Preparing
  3316. }
  3317. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3318. {
  3319. currentStatus = Charging; //OCPP Status: Charging
  3320. }
  3321. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3322. {
  3323. currentStatus = Finishing; //OCPP Status: Finishing
  3324. }
  3325. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3326. {
  3327. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3328. }
  3329. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  3330. {
  3331. currentStatus = Unavailable; //OCPP Status : Unavailable
  3332. }
  3333. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3334. {
  3335. currentStatus = Faulted; //OCPP Status: Faulted
  3336. }
  3337. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3338. {
  3339. currentStatus = Reserved; //OCPP Status: Reserved
  3340. }
  3341. } //end of the same index
  3342. } // end of for CCS_QUANTITY
  3343. }
  3344. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3345. {
  3346. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3347. {
  3348. tempIndex = ((gun_index==2) ? 1: 0);
  3349. }
  3350. else
  3351. {
  3352. tempIndex = gun_index;
  3353. }
  3354. for (int index = 0; index < GB_QUANTITY; index++)
  3355. {
  3356. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3357. {
  3358. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3359. {
  3360. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3361. {
  3362. currentStatus = Preparing; //OCPP Status: Preparing
  3363. }
  3364. else
  3365. {
  3366. currentStatus = Available; //OCPP Status: Available
  3367. }
  3368. }
  3369. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3370. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3371. ) //S_PRECHARGE
  3372. {
  3373. currentStatus = Preparing; //OCPP Status: Preparing
  3374. }
  3375. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3376. {
  3377. currentStatus = Charging; //OCPP Status: Charging
  3378. }
  3379. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3380. {
  3381. currentStatus = Finishing; //OCPP Status: Finishing
  3382. }
  3383. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3384. {
  3385. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3386. }
  3387. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  3388. {
  3389. currentStatus = Unavailable; //OCPP Status: Unavailable
  3390. }
  3391. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3392. {
  3393. currentStatus = Faulted; //OCPP Status: Faulted
  3394. }
  3395. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3396. {
  3397. currentStatus = Reserved; //OCPP Status: Reserved
  3398. }
  3399. } //end of the same index
  3400. } // end of for GB_QUANTITY
  3401. }
  3402. else if(gunType[gun_index] == GUN_TYPE_DO)
  3403. {
  3404. tempIndex = gun_index;
  3405. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3406. {
  3407. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3408. {
  3409. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3410. {
  3411. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3412. {
  3413. currentStatus = Preparing; //OCPP Status: Preparing
  3414. }
  3415. else
  3416. {
  3417. currentStatus = Available; //OCPP Status: Available
  3418. }
  3419. }
  3420. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3421. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3422. ) //S_PRECHARGE
  3423. {
  3424. currentStatus = Preparing; //OCPP Status: Preparing
  3425. }
  3426. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3427. {
  3428. currentStatus = Charging; //OCPP Status: Charging
  3429. }
  3430. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3431. {
  3432. currentStatus = Finishing; //OCPP Status: Finishing
  3433. }
  3434. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3435. {
  3436. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3437. }
  3438. else if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  3439. {
  3440. currentStatus = Unavailable; //OCPP Status: Unavailable
  3441. }
  3442. else if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3443. {
  3444. currentStatus = Faulted; //OCPP Status: Faulted
  3445. }
  3446. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3447. {
  3448. currentStatus = Reserved; //OCPP Status: Reserved
  3449. }
  3450. } //end of the same index
  3451. }
  3452. }
  3453. else
  3454. {
  3455. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3456. {
  3457. tempIndex = 2;
  3458. }
  3459. else
  3460. {
  3461. tempIndex = gun_index;
  3462. }
  3463. for (int index = 0; index < AC_QUANTITY; index++)
  3464. {
  3465. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3466. {
  3467. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3468. {
  3469. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_C) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_D))
  3470. {
  3471. currentStatus = Preparing; //OCPP Status: Preparing
  3472. }
  3473. else
  3474. {
  3475. currentStatus = Available; //OCPP Status: Available
  3476. }
  3477. }
  3478. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3479. {
  3480. currentStatus = Preparing; //OCPP Status: Preparing
  3481. }
  3482. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3483. {
  3484. currentStatus = Charging; //OCPP Status: Charging
  3485. }
  3486. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3487. {
  3488. currentStatus = Finishing; //OCPP Status: Finishing
  3489. }
  3490. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3491. {
  3492. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3493. }
  3494. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  3495. {
  3496. currentStatus = Unavailable; //OCPP Status: Unavailable
  3497. }
  3498. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3499. {
  3500. currentStatus = Faulted; //OCPP Status: Faulted
  3501. }
  3502. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3503. {
  3504. currentStatus = Reserved; //OCPP Status: Reserved
  3505. }
  3506. }//end of the same index
  3507. }//end of for AC_QUANTITY
  3508. }
  3509. //it's option
  3510. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3511. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  3512. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3513. random_uuid(guid);
  3514. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3515. , MESSAGE_TYPE_CALL
  3516. , guid
  3517. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3518. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3519. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3520. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3521. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3522. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3523. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3524. if((server_sign == TRUE))
  3525. {
  3526. LWS_Send(message);
  3527. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3528. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid, mapItem, tempdata/*(void**)(&mapItem)*//*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  3529. {
  3530. //DEBUG_ERROR("statusNotification mapitem pass");
  3531. result = PASS;
  3532. }
  3533. }
  3534. else
  3535. {
  3536. result = PASS;
  3537. }
  3538. return result;
  3539. }
  3540. int sendStopTransactionRequest(int gun_index)
  3541. {
  3542. mtrace();
  3543. int result = FAIL;
  3544. //char message[1500]={0};
  3545. char guid[37]={0};
  3546. char tempdata[65]={0};
  3547. int tempIndex = 0;
  3548. char TempStopTransaction[256];
  3549. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  3550. //int idx_sample=0;
  3551. DEBUG_INFO("sendStopTransactionRequest \n");
  3552. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3553. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  3554. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3555. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3556. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3557. {
  3558. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3559. {
  3560. tempIndex = ((gun_index==2) ? 1: 0);
  3561. }
  3562. else
  3563. {
  3564. tempIndex = gun_index;
  3565. }
  3566. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3567. {
  3568. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3569. {
  3570. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3571. }
  3572. }// END OF CHAdeMO_QUANTITY
  3573. }
  3574. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3575. {
  3576. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3577. {
  3578. tempIndex = ((gun_index==2) ? 1: 0);
  3579. }
  3580. else
  3581. {
  3582. tempIndex = gun_index;
  3583. }
  3584. for (int index = 0; index < CCS_QUANTITY; index++)
  3585. {
  3586. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3587. {
  3588. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3589. }
  3590. }// END OF CCS_QUANTITY
  3591. }
  3592. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3593. {
  3594. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3595. {
  3596. tempIndex = ((gun_index==2) ? 1: 0);
  3597. }
  3598. else
  3599. {
  3600. tempIndex = gun_index;
  3601. }
  3602. for (int index = 0; index < GB_QUANTITY; index++)
  3603. {
  3604. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3605. {
  3606. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3607. }
  3608. }// END OF GB_QUANTITY
  3609. }
  3610. else if(gunType[gun_index] == GUN_TYPE_DO)
  3611. {
  3612. tempIndex = gun_index;
  3613. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3614. {
  3615. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3616. {
  3617. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3618. }
  3619. }// END OF GB_QUANTITY
  3620. }
  3621. else
  3622. {
  3623. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3624. {
  3625. tempIndex = 2;
  3626. }
  3627. else
  3628. {
  3629. tempIndex = gun_index;
  3630. }
  3631. for (int index = 0; index < AC_QUANTITY; index++)
  3632. {
  3633. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3634. {
  3635. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3636. }
  3637. }// END OF AC_QUANTITY
  3638. }
  3639. //====================================== Stop Transaction Time =====================================================
  3640. struct timeval tmnow;
  3641. struct tm *tm;
  3642. char buf[28];//, usec_buf[6];
  3643. gettimeofday(&tmnow, NULL);
  3644. time_t t;
  3645. t = time(NULL);
  3646. /*UTC time and date*/
  3647. tm = gmtime(&t);
  3648. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3649. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  3650. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  3651. random_uuid(guid);
  3652. /***********************************transactionData******************************************************/
  3653. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  3654. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  3655. //=================================
  3656. // Transaction_Begin
  3657. //=================================
  3658. //============================================ Energy.Active.Import.Interval ================================
  3659. //idx_sample=0;
  3660. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  3661. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  3662. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  3663. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  3664. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3665. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  3666. {
  3667. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  3668. }
  3669. else
  3670. {
  3671. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  3672. }
  3673. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  3674. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3675. //=================================
  3676. // Transaction_End
  3677. //=================================
  3678. // ================================= Current.Import L1 ===============================================
  3679. //idx_sample=1;
  3680. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  3681. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3682. {
  3683. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3684. {
  3685. tempIndex = ((gun_index==2) ? 1: 0);
  3686. }
  3687. else
  3688. {
  3689. tempIndex = gun_index;
  3690. }
  3691. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3692. {
  3693. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3694. {
  3695. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3696. }
  3697. }// End of for CHAdeMO_QUANTITY
  3698. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3699. }
  3700. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3701. {
  3702. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3703. {
  3704. tempIndex = ((gun_index==2) ? 1: 0);
  3705. }
  3706. else
  3707. {
  3708. tempIndex = gun_index;
  3709. }
  3710. for (int index = 0; index < CCS_QUANTITY; index++)
  3711. {
  3712. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3713. {
  3714. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3715. }
  3716. }// End of for CCS_QUANTITY
  3717. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3718. }
  3719. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3720. {
  3721. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3722. {
  3723. tempIndex = ((gun_index==2) ? 1: 0);
  3724. }
  3725. else
  3726. {
  3727. tempIndex = gun_index;
  3728. }
  3729. for (int index = 0; index < GB_QUANTITY; index++)
  3730. {
  3731. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3732. {
  3733. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3734. }
  3735. }// End of for GB_QUANTITY
  3736. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3737. }
  3738. else if(gunType[gun_index] == GUN_TYPE_DO)
  3739. {
  3740. tempIndex = gun_index;
  3741. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3742. {
  3743. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3744. {
  3745. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3746. }
  3747. }
  3748. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3749. }
  3750. else
  3751. {
  3752. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3753. {
  3754. tempIndex = 2;
  3755. }
  3756. else
  3757. {
  3758. tempIndex = gun_index;
  3759. }
  3760. for (int index = 0; index < AC_QUANTITY; index++)
  3761. {
  3762. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3763. {
  3764. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  3765. }
  3766. }// End of for AC_QUANTITY
  3767. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  3768. }
  3769. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3770. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  3771. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  3772. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  3773. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3774. // ================================= Energy.Active.Import.Interval ==============================================
  3775. //idx_sample=2;
  3776. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3777. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3778. {
  3779. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3780. {
  3781. tempIndex = ((gun_index==2) ? 1: 0);
  3782. }
  3783. else
  3784. {
  3785. tempIndex = gun_index;
  3786. }
  3787. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3788. {
  3789. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3790. {
  3791. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3792. }
  3793. }// END OF CHAdeMO_QUANTITY
  3794. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3795. }
  3796. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3797. {
  3798. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3799. {
  3800. tempIndex = ((gun_index==2) ? 1: 0);
  3801. }
  3802. else
  3803. {
  3804. tempIndex = gun_index;
  3805. }
  3806. for (int index = 0; index < CCS_QUANTITY; index++)
  3807. {
  3808. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3809. {
  3810. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3811. }
  3812. }// END OF CCS_QUANTITY
  3813. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3814. }
  3815. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3816. {
  3817. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3818. {
  3819. tempIndex = ((gun_index==2) ? 1: 0);
  3820. }
  3821. else
  3822. {
  3823. tempIndex = gun_index;
  3824. }
  3825. for (int index = 0; index < GB_QUANTITY; index++)
  3826. {
  3827. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3828. {
  3829. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3830. }
  3831. }// END OF GB_QUANTITY
  3832. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3833. }
  3834. else if(gunType[gun_index] == GUN_TYPE_DO)
  3835. {
  3836. tempIndex = gun_index;
  3837. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3838. {
  3839. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3840. {
  3841. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3842. }
  3843. }
  3844. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3845. }
  3846. else
  3847. {
  3848. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3849. {
  3850. tempIndex = 2;
  3851. }
  3852. else
  3853. {
  3854. tempIndex = gun_index;
  3855. }
  3856. for (int index = 0; index < AC_QUANTITY; index++)
  3857. {
  3858. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3859. {
  3860. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3861. }
  3862. }// END OF AC_QUANTITY
  3863. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  3864. }
  3865. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3866. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  3867. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  3868. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  3869. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3870. //=================================== Power.Active.Import ==================================================
  3871. //idx_sample=3;
  3872. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3873. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3874. {
  3875. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3876. {
  3877. tempIndex = ((gun_index==2) ? 1: 0);
  3878. }
  3879. else
  3880. {
  3881. tempIndex = gun_index;
  3882. }
  3883. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3884. {
  3885. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3886. {
  3887. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3888. }
  3889. } // End for CHAdeMO_QUANTITY
  3890. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3891. }
  3892. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3893. {
  3894. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3895. {
  3896. tempIndex = ((gun_index==2) ? 1: 0);
  3897. }
  3898. else
  3899. {
  3900. tempIndex = gun_index;
  3901. }
  3902. for (int index = 0; index < CCS_QUANTITY; index++)
  3903. {
  3904. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3905. {
  3906. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3907. }
  3908. } // END for CCS_QUANTITY
  3909. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3910. }
  3911. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3912. {
  3913. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3914. {
  3915. tempIndex = ((gun_index==2) ? 1: 0);
  3916. }
  3917. else
  3918. {
  3919. tempIndex = gun_index;
  3920. }
  3921. for (int index = 0; index < GB_QUANTITY; index++)
  3922. {
  3923. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3924. {
  3925. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3926. }
  3927. }// END for GB_QUANTITY
  3928. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3929. }
  3930. else if(gunType[gun_index] == GUN_TYPE_DO)
  3931. {
  3932. tempIndex = gun_index;
  3933. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3934. {
  3935. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3936. {
  3937. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3938. }
  3939. }
  3940. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3941. }
  3942. else
  3943. {
  3944. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3945. {
  3946. tempIndex = 2;
  3947. }
  3948. else
  3949. {
  3950. tempIndex = gun_index;
  3951. }
  3952. for (int index = 0; index < AC_QUANTITY; index++)
  3953. {
  3954. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3955. {
  3956. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3957. }
  3958. } // END for AC_QUANTITY
  3959. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  3960. }
  3961. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3962. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  3963. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  3964. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  3965. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  3966. //============================ Voltage L1 ====================================
  3967. //idx_sample=4;
  3968. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3969. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3970. {
  3971. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3972. {
  3973. tempIndex = ((gun_index==2) ? 1: 0);
  3974. }
  3975. else
  3976. {
  3977. tempIndex = gun_index;
  3978. }
  3979. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3980. {
  3981. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3982. {
  3983. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3984. }
  3985. } // END OF FOR CHAdeMO_QUANTITY
  3986. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3987. }
  3988. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3989. {
  3990. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3991. {
  3992. tempIndex = ((gun_index==2) ? 1: 0);
  3993. }
  3994. else
  3995. {
  3996. tempIndex = gun_index;
  3997. }
  3998. for (int index = 0; index < CCS_QUANTITY; index++)
  3999. {
  4000. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4001. {
  4002. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4003. }
  4004. } // END OF FOR CCS_QUANTITY
  4005. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4006. }
  4007. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4008. {
  4009. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4010. {
  4011. tempIndex = ((gun_index==2) ? 1: 0);
  4012. }
  4013. else
  4014. {
  4015. tempIndex = gun_index;
  4016. }
  4017. for (int index = 0; index < GB_QUANTITY; index++)
  4018. {
  4019. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4020. {
  4021. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4022. }
  4023. } // END OF FOR GB_QUANTITY
  4024. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4025. }
  4026. else if(gunType[gun_index] == GUN_TYPE_DO)
  4027. {
  4028. tempIndex = gun_index;
  4029. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4030. {
  4031. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4032. {
  4033. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4034. }
  4035. }
  4036. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4037. }
  4038. else
  4039. {
  4040. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4041. {
  4042. tempIndex = 2;
  4043. }
  4044. else
  4045. {
  4046. tempIndex = gun_index;
  4047. }
  4048. for (int index = 0; index < AC_QUANTITY; index++)
  4049. {
  4050. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4051. {
  4052. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  4053. }
  4054. } // END OF FOR AC_QUANTITY
  4055. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  4056. }
  4057. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4058. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  4059. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  4060. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  4061. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4062. //====================== End SoC ================================
  4063. //idx_sample=5;
  4064. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4065. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  4066. {
  4067. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4068. {
  4069. tempIndex = ((gun_index==2) ? 1: 0);
  4070. }
  4071. else
  4072. {
  4073. tempIndex = gun_index;
  4074. }
  4075. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4076. {
  4077. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4078. {
  4079. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4080. {
  4081. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  4082. }
  4083. }
  4084. }
  4085. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4086. {
  4087. for (int index = 0; index < CCS_QUANTITY; index++)
  4088. {
  4089. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4090. {
  4091. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  4092. }
  4093. }
  4094. }
  4095. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4096. {
  4097. for (int index = 0; index < GB_QUANTITY; index++)
  4098. {
  4099. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4100. {
  4101. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  4102. }
  4103. }
  4104. }
  4105. else if(gunType[gun_index] == GUN_TYPE_DO)
  4106. {
  4107. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4108. {
  4109. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4110. {
  4111. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  4112. }
  4113. }
  4114. }
  4115. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4116. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  4117. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4118. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  4119. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  4120. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4121. } // END FOR DC CASE
  4122. // ================================= Current.Import L2 ===============================================
  4123. //idx_sample=6;
  4124. // AC 3 phse L2 current
  4125. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4126. {
  4127. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4128. {
  4129. tempIndex = 2;
  4130. }
  4131. else
  4132. {
  4133. tempIndex = gun_index;
  4134. }
  4135. for (int index = 0; index < AC_QUANTITY; index++)
  4136. {
  4137. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4138. {
  4139. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  4140. }
  4141. }// End of for AC_QUANTITY
  4142. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  4143. }
  4144. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4145. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  4146. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  4147. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  4148. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4149. // ================================= Current.Import L3 ===============================================
  4150. //idx_sample=7;
  4151. // AC 3 phse L3 current
  4152. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4153. {
  4154. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4155. {
  4156. tempIndex = 2;
  4157. }
  4158. else
  4159. {
  4160. tempIndex = gun_index;
  4161. }
  4162. for (int index = 0; index < AC_QUANTITY; index++)
  4163. {
  4164. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4165. {
  4166. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  4167. }
  4168. }// End of for AC_QUANTITY
  4169. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  4170. }
  4171. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4172. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  4173. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  4174. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  4175. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4176. //============================ Voltage L2 ====================================
  4177. //idx_sample=8;
  4178. // AC 3 phse L2 voltage
  4179. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4180. {
  4181. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4182. {
  4183. tempIndex = 2;
  4184. }
  4185. else
  4186. {
  4187. tempIndex = gun_index;
  4188. }
  4189. for (int index = 0; index < AC_QUANTITY; index++)
  4190. {
  4191. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4192. {
  4193. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  4194. }
  4195. } // END OF FOR AC_QUANTITY
  4196. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  4197. }
  4198. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4199. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  4200. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  4201. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  4202. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4203. //============================ Voltage L3 ====================================
  4204. //idx_sample=8;
  4205. // AC 3 phse L3 voltage
  4206. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4207. {
  4208. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4209. {
  4210. tempIndex = 2;
  4211. }
  4212. else
  4213. {
  4214. tempIndex = gun_index;
  4215. }
  4216. for (int index = 0; index < AC_QUANTITY; index++)
  4217. {
  4218. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4219. {
  4220. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  4221. }
  4222. } // END OF FOR AC_QUANTITY
  4223. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  4224. }
  4225. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4226. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  4227. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  4228. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  4229. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4230. //====================== Start SoC ================================
  4231. //idx_sample=10;
  4232. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4233. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  4234. {
  4235. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4236. {
  4237. tempIndex = ((gun_index==2) ? 1: 0);
  4238. }
  4239. else
  4240. {
  4241. tempIndex = gun_index;
  4242. }
  4243. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4244. {
  4245. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4246. {
  4247. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4248. {
  4249. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  4250. }
  4251. }
  4252. }
  4253. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4254. {
  4255. for (int index = 0; index < CCS_QUANTITY; index++)
  4256. {
  4257. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4258. {
  4259. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  4260. }
  4261. }
  4262. }
  4263. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4264. {
  4265. for (int index = 0; index < GB_QUANTITY; index++)
  4266. {
  4267. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4268. {
  4269. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  4270. }
  4271. }
  4272. }
  4273. else if(gunType[gun_index] == GUN_TYPE_DO)
  4274. {
  4275. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4276. {
  4277. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4278. {
  4279. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  4280. }
  4281. }
  4282. }
  4283. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4284. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  4285. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4286. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  4287. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  4288. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4289. } // END FOR DC CASE
  4290. //================================================ Message create ====================================================
  4291. json_object *StopTransaction = json_object_new_object();
  4292. json_object *transactionDatas = json_object_new_array();
  4293. json_object *sampledValues = json_object_new_array();
  4294. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  4295. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  4296. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  4297. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  4298. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  4299. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  4300. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  4301. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  4302. {
  4303. json_object *transactionData = json_object_new_object();
  4304. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  4305. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  4306. {
  4307. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  4308. {
  4309. json_object *sampledValue = json_object_new_object();
  4310. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  4311. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  4312. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  4313. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  4314. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  4315. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  4316. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  4317. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  4318. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  4319. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  4320. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  4321. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  4322. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  4323. json_object_array_add(sampledValues, sampledValue);
  4324. }
  4325. }
  4326. json_object_object_add(transactionData, "sampledValue", sampledValues);
  4327. json_object_array_add(transactionDatas, transactionData);
  4328. }
  4329. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  4330. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  4331. ,MESSAGE_TYPE_CALL
  4332. ,guid
  4333. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  4334. json_object_put(StopTransaction);
  4335. #if 1 // for TempStopTransaction
  4336. //Delete TempStopTransaction
  4337. if((access(TempStopTransaction,F_OK))!=-1)
  4338. {
  4339. remove(TempStopTransaction); // remove file "TempStopTransaction"
  4340. }
  4341. #endif
  4342. #if 1
  4343. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4344. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4345. {
  4346. result = PASS;
  4347. //DEBUG_INFO("StopTransaction mapitem pass\n");
  4348. }
  4349. #endif
  4350. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4351. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4352. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4353. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  4354. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4355. {
  4356. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4357. }
  4358. //for test
  4359. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4360. return result;
  4361. }
  4362. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4363. {
  4364. mtrace();
  4365. int result = FAIL;
  4366. char guid[37]={0};
  4367. char tempdata[65]={0};
  4368. int tempIndex = 0;
  4369. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4370. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4371. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  4372. //set value
  4373. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4374. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (((strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging") != NULL) || (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "SuspendedEV") != NULL) || (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "SuspendedEVSE") != NULL) )?
  4375. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  4376. -1);
  4377. random_uuid(guid);
  4378. //UTC Date time
  4379. struct timeval tmnow;
  4380. struct tm *tm;
  4381. char buf[28];//, usec_buf[6];
  4382. gettimeofday(&tmnow, NULL);
  4383. time_t t;
  4384. t = time(NULL);
  4385. /*UTC time and date*/
  4386. tm = gmtime(&t);
  4387. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4388. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4389. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4390. //idx_sample=0;
  4391. //********************************(1)Current.Import L1************************************************/
  4392. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4393. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4394. {
  4395. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4396. {
  4397. tempIndex = ((gun_index==2) ? 1: 0);
  4398. }
  4399. else
  4400. {
  4401. tempIndex = gun_index;
  4402. }
  4403. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4404. {
  4405. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4406. {
  4407. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4408. }
  4409. }
  4410. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4411. }
  4412. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4413. {
  4414. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4415. {
  4416. tempIndex = ((gun_index==2) ? 1: 0);
  4417. }
  4418. else
  4419. {
  4420. tempIndex = gun_index;
  4421. }
  4422. for (int index = 0; index < CCS_QUANTITY; index++)
  4423. {
  4424. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4425. {
  4426. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4427. }
  4428. }
  4429. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4430. }
  4431. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4432. {
  4433. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4434. {
  4435. tempIndex = ((gun_index==2) ? 1: 0);
  4436. }
  4437. else
  4438. {
  4439. tempIndex = gun_index;
  4440. }
  4441. for (int index = 0; index < GB_QUANTITY; index++)
  4442. {
  4443. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4444. {
  4445. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4446. }
  4447. }
  4448. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4449. }
  4450. else if(gunType[gun_index] == GUN_TYPE_DO)
  4451. {
  4452. tempIndex = gun_index;
  4453. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4454. {
  4455. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4456. {
  4457. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  4458. }
  4459. }
  4460. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4461. }
  4462. else
  4463. {
  4464. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4465. {
  4466. tempIndex = 2;
  4467. }
  4468. else
  4469. {
  4470. tempIndex = gun_index;
  4471. }
  4472. for (int index = 0; index < AC_QUANTITY; index++)
  4473. {
  4474. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4475. {
  4476. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4477. }
  4478. }
  4479. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4480. }
  4481. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4482. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4483. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4484. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4485. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4486. //idx_sample=1;
  4487. //********************************(2)Energy.Active.Import.Register ************************************************/
  4488. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4489. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4490. {
  4491. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4492. {
  4493. tempIndex = ((gun_index==2) ? 1: 0);
  4494. }
  4495. else
  4496. {
  4497. tempIndex = gun_index;
  4498. }
  4499. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4500. {
  4501. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4502. {
  4503. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4504. }
  4505. }
  4506. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4507. }
  4508. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4509. {
  4510. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4511. {
  4512. tempIndex = ((gun_index==2) ? 1: 0);
  4513. }
  4514. else
  4515. {
  4516. tempIndex = gun_index;
  4517. }
  4518. for (int index = 0; index < CCS_QUANTITY; index++)
  4519. {
  4520. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4521. {
  4522. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4523. }
  4524. }
  4525. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4526. }
  4527. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4528. {
  4529. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4530. {
  4531. tempIndex = ((gun_index==2) ? 1: 0);
  4532. }
  4533. else
  4534. {
  4535. tempIndex = gun_index;
  4536. }
  4537. for (int index = 0; index < GB_QUANTITY; index++)
  4538. {
  4539. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4540. {
  4541. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4542. }
  4543. }
  4544. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4545. }
  4546. else if(gunType[gun_index] == GUN_TYPE_DO)
  4547. {
  4548. tempIndex = gun_index;
  4549. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4550. {
  4551. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4552. {
  4553. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  4554. }
  4555. }
  4556. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4557. }
  4558. else
  4559. {
  4560. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4561. {
  4562. tempIndex = 2;
  4563. }
  4564. else
  4565. {
  4566. tempIndex = gun_index;
  4567. }
  4568. for (int index = 0; index < AC_QUANTITY; index++)
  4569. {
  4570. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4571. {
  4572. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4573. }
  4574. }
  4575. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4576. }
  4577. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  4578. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4579. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4580. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4581. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4582. //idx_sample=2;
  4583. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  4584. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4585. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4586. {
  4587. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4588. {
  4589. tempIndex = ((gun_index==2) ? 1: 0);
  4590. }
  4591. else
  4592. {
  4593. tempIndex = gun_index;
  4594. }
  4595. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4596. {
  4597. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4598. {
  4599. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4600. }
  4601. } // END OF FOR CHAdeMO_QUANTITY
  4602. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4603. }
  4604. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4605. {
  4606. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4607. {
  4608. tempIndex = ((gun_index==2) ? 1: 0);
  4609. }
  4610. else
  4611. {
  4612. tempIndex = gun_index;
  4613. }
  4614. for (int index = 0; index < CCS_QUANTITY; index++)
  4615. {
  4616. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4617. {
  4618. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  4619. }
  4620. } // END OF CCS_QUANTITY
  4621. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4622. }
  4623. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4624. {
  4625. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4626. {
  4627. tempIndex = ((gun_index==2) ? 1: 0);
  4628. }
  4629. else
  4630. {
  4631. tempIndex = gun_index;
  4632. }
  4633. for (int index = 0; index < GB_QUANTITY; index++)
  4634. {
  4635. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4636. {
  4637. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  4638. }
  4639. } // END OF GB_QUANTITY
  4640. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4641. }
  4642. else if(gunType[gun_index] == GUN_TYPE_DO)
  4643. {
  4644. tempIndex = gun_index;
  4645. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4646. {
  4647. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4648. {
  4649. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  4650. }
  4651. }
  4652. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4653. }
  4654. else
  4655. {
  4656. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4657. {
  4658. tempIndex = 2;
  4659. }
  4660. else
  4661. {
  4662. tempIndex = gun_index;
  4663. }
  4664. for (int index = 0; index < AC_QUANTITY; index++)
  4665. {
  4666. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4667. {
  4668. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  4669. }
  4670. }
  4671. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  4672. }
  4673. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  4674. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  4675. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  4676. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  4677. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4678. //idx_sample=3;
  4679. //********************************(4)Power.Active.Import************************************************/
  4680. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4681. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4682. {
  4683. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4684. {
  4685. tempIndex = ((gun_index==2) ? 1: 0);
  4686. }
  4687. else
  4688. {
  4689. tempIndex = gun_index;
  4690. }
  4691. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4692. {
  4693. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4694. {
  4695. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  4696. }
  4697. } // END OF FOR
  4698. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4699. }
  4700. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4701. {
  4702. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4703. {
  4704. tempIndex = ((gun_index==2) ? 1: 0);
  4705. }
  4706. else
  4707. {
  4708. tempIndex = gun_index;
  4709. }
  4710. for (int index = 0; index < CCS_QUANTITY; index++)
  4711. {
  4712. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4713. {
  4714. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  4715. }
  4716. }
  4717. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4718. }
  4719. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4720. {
  4721. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4722. {
  4723. tempIndex = ((gun_index==2) ? 1: 0);
  4724. }
  4725. else
  4726. {
  4727. tempIndex = gun_index;
  4728. }
  4729. for (int index = 0; index < GB_QUANTITY; index++)
  4730. {
  4731. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4732. {
  4733. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4734. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  4735. }
  4736. }
  4737. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4738. }
  4739. else if(gunType[gun_index] == GUN_TYPE_DO)
  4740. {
  4741. tempIndex = gun_index;
  4742. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4743. {
  4744. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4745. {
  4746. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4747. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  4748. }
  4749. }
  4750. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4751. }
  4752. else
  4753. {
  4754. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4755. {
  4756. tempIndex = 2;
  4757. }
  4758. else
  4759. {
  4760. tempIndex = gun_index;
  4761. }
  4762. for (int index = 0; index < AC_QUANTITY; index++)
  4763. {
  4764. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4765. {
  4766. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  4767. }
  4768. }
  4769. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  4770. }
  4771. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  4772. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  4773. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  4774. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  4775. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  4776. //idx_sample=4;
  4777. //***********************************************(5)VOLTAGE L1******************************************************/
  4778. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4779. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4780. {
  4781. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4782. {
  4783. tempIndex = ((gun_index==2) ? 1: 0);
  4784. }
  4785. else
  4786. {
  4787. tempIndex = gun_index;
  4788. }
  4789. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4790. {
  4791. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4792. {
  4793. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  4794. }
  4795. }
  4796. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4797. }
  4798. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4799. {
  4800. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4801. {
  4802. tempIndex = ((gun_index==2) ? 1: 0);
  4803. }
  4804. else
  4805. {
  4806. tempIndex = gun_index;
  4807. }
  4808. for (int index = 0; index < CCS_QUANTITY; index++)
  4809. {
  4810. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4811. {
  4812. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  4813. }
  4814. }
  4815. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4816. }
  4817. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4818. {
  4819. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4820. {
  4821. tempIndex = ((gun_index==2) ? 1: 0);
  4822. }
  4823. else
  4824. {
  4825. tempIndex = gun_index;
  4826. }
  4827. for (int index = 0; index < GB_QUANTITY; index++)
  4828. {
  4829. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4830. {
  4831. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  4832. }
  4833. }
  4834. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4835. }
  4836. else if(gunType[gun_index] == GUN_TYPE_DO)
  4837. {
  4838. tempIndex = gun_index;
  4839. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4840. {
  4841. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4842. {
  4843. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  4844. }
  4845. }
  4846. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4847. }
  4848. else
  4849. {
  4850. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4851. {
  4852. tempIndex = 2;
  4853. }
  4854. else
  4855. {
  4856. tempIndex = gun_index;
  4857. }
  4858. for (int index = 0; index < AC_QUANTITY; index++)
  4859. {
  4860. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4861. {
  4862. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  4863. }
  4864. }
  4865. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  4866. }
  4867. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  4868. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  4869. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  4870. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  4871. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4872. //***********************************************(6)SOC******************************************************/
  4873. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  4874. {
  4875. //idx_sample=5;
  4876. //sampledValue = NULL;
  4877. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4878. {
  4879. tempIndex = ((gun_index==2) ? 1: 0);
  4880. }
  4881. else
  4882. {
  4883. tempIndex = gun_index;
  4884. }
  4885. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4886. {
  4887. //tempIndex = ((gun_index==2) ? 1: 0);
  4888. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4889. {
  4890. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4891. {
  4892. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  4893. }
  4894. }
  4895. }
  4896. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4897. {
  4898. //tempIndex = ((gun_index==2) ? 1: 0);
  4899. for (int index = 0; index < CCS_QUANTITY; index++)
  4900. {
  4901. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4902. {
  4903. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  4904. }
  4905. }
  4906. }
  4907. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4908. {
  4909. //tempIndex = ((gun_index==2) ? 1: 0);
  4910. for (int index = 0; index < GB_QUANTITY; index++)
  4911. {
  4912. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4913. {
  4914. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  4915. }
  4916. }
  4917. }
  4918. else if(gunType[gun_index] == GUN_TYPE_DO)
  4919. {
  4920. //tempIndex = ((gun_index==2) ? 1: 0);
  4921. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4922. {
  4923. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4924. {
  4925. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  4926. }
  4927. }
  4928. }
  4929. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  4930. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  4931. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  4932. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  4933. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  4934. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  4935. }
  4936. //********************************(7)Current.Import L2************************************************/
  4937. // Only for AC 3 phase
  4938. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4939. {
  4940. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4941. {
  4942. tempIndex = 2;
  4943. }
  4944. else
  4945. {
  4946. tempIndex = gun_index;
  4947. }
  4948. for (int index = 0; index < AC_QUANTITY; index++)
  4949. {
  4950. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4951. {
  4952. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  4953. }
  4954. }
  4955. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  4956. }
  4957. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  4958. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  4959. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  4960. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  4961. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4962. //********************************(8)Current.Import L3************************************************/
  4963. // Only for AC 3 phase
  4964. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4965. {
  4966. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4967. {
  4968. tempIndex = 2;
  4969. }
  4970. else
  4971. {
  4972. tempIndex = gun_index;
  4973. }
  4974. for (int index = 0; index < AC_QUANTITY; index++)
  4975. {
  4976. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4977. {
  4978. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  4979. }
  4980. }
  4981. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  4982. }
  4983. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  4984. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  4985. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  4986. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  4987. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4988. //***********************************************(9)VOLTAGE L2******************************************************/
  4989. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4990. {
  4991. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4992. {
  4993. tempIndex = 2;
  4994. }
  4995. else
  4996. {
  4997. tempIndex = gun_index;
  4998. }
  4999. for (int index = 0; index < AC_QUANTITY; index++)
  5000. {
  5001. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5002. {
  5003. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  5004. }
  5005. }
  5006. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  5007. }
  5008. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  5009. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  5010. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  5011. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  5012. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5013. //***********************************************(10)VOLTAGE L3******************************************************/
  5014. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5015. {
  5016. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5017. {
  5018. tempIndex = 2;
  5019. }
  5020. else
  5021. {
  5022. tempIndex = gun_index;
  5023. }
  5024. for (int index = 0; index < AC_QUANTITY; index++)
  5025. {
  5026. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5027. {
  5028. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  5029. }
  5030. }
  5031. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  5032. }
  5033. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  5034. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  5035. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  5036. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  5037. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5038. // Message create ====================================================================================================
  5039. if(TRUE)
  5040. {
  5041. json_object *MeterValueReq = json_object_new_object();
  5042. json_object *MeterValues = json_object_new_array();
  5043. json_object *sampledValues = json_object_new_array();
  5044. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  5045. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  5046. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  5047. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  5048. {
  5049. json_object *MeterValue = json_object_new_object();
  5050. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  5051. {
  5052. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  5053. {
  5054. json_object *sampledValue = json_object_new_object();
  5055. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  5056. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  5057. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  5058. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  5059. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  5060. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  5061. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  5062. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  5063. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  5064. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  5065. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  5066. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  5067. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  5068. json_object_array_add(sampledValues, sampledValue);
  5069. }
  5070. }
  5071. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  5072. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  5073. json_object_array_add(MeterValues, MeterValue);
  5074. }
  5075. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  5076. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  5077. ,gun_index + 1
  5078. ,MESSAGE_TYPE_CALL
  5079. ,guid
  5080. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  5081. json_object_put(MeterValueReq);
  5082. }
  5083. // Put request guid to hash map
  5084. sprintf(tempdata, "MeterValues,%d", (gun_index));
  5085. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  5086. {
  5087. result = PASS;
  5088. //DEBUG_INFO("MeterValues mapitem pass\n");
  5089. }
  5090. if((dataType != ReadingContext_Trigger) &&
  5091. (dataType != ReadingContext_Sample_Clock) &&
  5092. (ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1))
  5093. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  5094. else
  5095. {
  5096. if(FirstHeartBeat)
  5097. LWS_Send(queuedata +2);
  5098. }
  5099. return result;
  5100. }
  5101. //==========================================
  5102. // send confirm routine
  5103. //==========================================
  5104. int sendCancelReservationConfirmation(char *uuid,char *payload)
  5105. {
  5106. mtrace();
  5107. int result = FAIL;
  5108. char message[100]={0};
  5109. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  5110. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5111. LWS_Send(message);
  5112. result = TRUE;
  5113. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  5114. return result;
  5115. }
  5116. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  5117. {
  5118. mtrace();
  5119. int result = FAIL;
  5120. char message[100]={0};
  5121. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  5122. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5123. LWS_Send(message);
  5124. result = TRUE;
  5125. return result;
  5126. }
  5127. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  5128. {
  5129. mtrace();
  5130. int result = FAIL;
  5131. char message[100]={0};
  5132. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  5133. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5134. LWS_Send(message);
  5135. result = TRUE;
  5136. return result;
  5137. }
  5138. int sendClearCacheConfirmation(char *uuid,char *payload)
  5139. {
  5140. mtrace();
  5141. int result = FAIL;
  5142. char message[500]={0};
  5143. DEBUG_INFO("sendClearCacheConfirmation...\n");
  5144. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5145. LWS_Send(message);
  5146. return result;
  5147. }
  5148. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  5149. {
  5150. mtrace();
  5151. int result = FAIL;
  5152. char message[500]={0};
  5153. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  5154. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5155. LWS_Send(message);
  5156. return result;
  5157. }
  5158. int sendDataTransferConfirmation(char *uuid,char *payload)
  5159. {
  5160. mtrace();
  5161. char statusStr[20]={0};
  5162. char dataStr[10]={0};
  5163. char sstr[20]={0};
  5164. int c = 0;
  5165. char *loc;
  5166. int result = FAIL;
  5167. DEBUG_INFO("sendDataTransferConfirmation...\n");
  5168. /**********************status**************************/
  5169. loc = strstr(payload, "status");
  5170. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5171. c = 0;
  5172. while (loc[3+strlen("status")+c] != '\"')
  5173. {
  5174. sstr[c] = loc[3+strlen("status")+c];
  5175. c++;
  5176. }
  5177. sstr[c] = '\0';
  5178. strcpy(statusStr, sstr);
  5179. /**********************data**************************/
  5180. loc = strstr(payload, "data");
  5181. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5182. c = 0;
  5183. while (loc[3+strlen("data")+c] != '\"')
  5184. {
  5185. sstr[c] = loc[3+strlen("data")+c];
  5186. c++;
  5187. }
  5188. sstr[c] = '\0';
  5189. strcpy(dataStr, sstr);
  5190. return result;
  5191. }
  5192. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  5193. {
  5194. mtrace();
  5195. int result = FAIL;
  5196. char message[1000]={0};
  5197. int CompositeScheduleIndex = 0;
  5198. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  5199. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  5200. if(nPeriod == 0)
  5201. {
  5202. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  5203. {
  5204. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  5205. ,MESSAGE_TYPE_CALLRESULT
  5206. ,uuid
  5207. ,payload
  5208. ,connectorIdInt);
  5209. }
  5210. else
  5211. {
  5212. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  5213. ,MESSAGE_TYPE_CALLRESULT
  5214. ,uuid
  5215. ,payload
  5216. ,connectorIdInt
  5217. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5218. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5219. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5220. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  5221. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  5222. }
  5223. }
  5224. else
  5225. {
  5226. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  5227. ,MESSAGE_TYPE_CALLRESULT
  5228. ,uuid
  5229. ,payload
  5230. ,connectorIdInt
  5231. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5232. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5233. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5234. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  5235. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  5236. {
  5237. if (idx_sample == 0)
  5238. {
  5239. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5240. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5241. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5242. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5243. }
  5244. else
  5245. {
  5246. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5247. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5248. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5249. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5250. }
  5251. }
  5252. sprintf(message + strlen(message), "]}}]");
  5253. }
  5254. LWS_Send(message);
  5255. result = TRUE;
  5256. return result;
  5257. }
  5258. int sendGetConfigurationConfirmation(char *uuid)
  5259. {
  5260. mtrace();
  5261. int result = FAIL;
  5262. int MaxKeySupported = 0;
  5263. int sentConfigurationNumber= 0;
  5264. int sentunConfigurationNumber= 0;
  5265. char message[4000]={0};
  5266. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5267. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5268. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5269. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5270. ,MESSAGE_TYPE_CALLRESULT
  5271. ,uuid );
  5272. //configuration key
  5273. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5274. {
  5275. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5276. {
  5277. if (sentConfigurationNumber == 0)
  5278. {
  5279. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5280. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5281. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5282. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5283. }
  5284. else
  5285. {
  5286. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5287. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5288. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5289. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5290. }
  5291. sentConfigurationNumber = sentConfigurationNumber + 1;
  5292. }
  5293. }
  5294. sprintf(message + strlen(message), "]");
  5295. if(UnknownKeynum != 0)
  5296. {
  5297. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5298. //unkown key
  5299. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5300. {
  5301. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5302. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5303. if(sentunConfigurationNumber == 0)
  5304. {
  5305. sprintf(message + strlen(message), "\"%s\""
  5306. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5307. }
  5308. else
  5309. {
  5310. sprintf(message + strlen(message), ",\"%s\""
  5311. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5312. }
  5313. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5314. }
  5315. sprintf(message + strlen(message), "]");
  5316. }
  5317. sprintf(message + strlen(message), "}]");
  5318. LWS_Send(message);
  5319. return result;
  5320. }
  5321. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5322. {
  5323. mtrace();
  5324. int result = FAIL;
  5325. char message[400]={0};
  5326. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5327. if(strcmp(payload,"")==0)
  5328. {
  5329. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5330. }
  5331. else
  5332. {
  5333. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5334. }
  5335. LWS_Send(message);
  5336. result = TRUE;
  5337. return result;
  5338. }
  5339. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5340. {
  5341. mtrace();
  5342. int result = FAIL;
  5343. char message[80]={0};
  5344. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5345. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  5346. LWS_Send(message);
  5347. result = TRUE;
  5348. return result;
  5349. }
  5350. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5351. {
  5352. mtrace();
  5353. int result = FAIL;
  5354. char message[80]={0};
  5355. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5356. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5357. LWS_Send(message);
  5358. result = TRUE;
  5359. return result;
  5360. }
  5361. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5362. {
  5363. mtrace();
  5364. int result = FAIL;
  5365. char message[80]={0};
  5366. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5367. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5368. LWS_Send(message);
  5369. result = TRUE;
  5370. return result;
  5371. }
  5372. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5373. {
  5374. mtrace();
  5375. int result = FAIL;
  5376. char message[80]={0};
  5377. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5378. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5379. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5380. LWS_Send(message);
  5381. result = TRUE;
  5382. return result;
  5383. }
  5384. int sendResetConfirmation(char *uuid,char *payload)
  5385. {
  5386. mtrace();
  5387. int result = FAIL;
  5388. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  5389. char message[80]={0};
  5390. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  5391. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5392. LWS_Send(message);
  5393. result = TRUE;
  5394. return result;
  5395. }
  5396. int sendSendLocalListConfirmation(char *uuid,char *payload)
  5397. {
  5398. mtrace();
  5399. int result = FAIL;
  5400. char message[500]={0};
  5401. // [ 3, "1571284266109", { "status": "Accepted" } ]
  5402. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5403. LWS_Send(message);
  5404. result = TRUE;
  5405. return result;
  5406. }
  5407. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  5408. {
  5409. mtrace();
  5410. int result = FAIL;
  5411. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  5412. char message[80]={0};
  5413. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  5414. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5415. LWS_Send(message);
  5416. result = TRUE;
  5417. return result;
  5418. }
  5419. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  5420. {
  5421. mtrace();
  5422. int result = FAIL;
  5423. char message[80]={0};
  5424. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  5425. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5426. LWS_Send(message);
  5427. result = TRUE;
  5428. return result;
  5429. }
  5430. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  5431. {
  5432. mtrace();
  5433. int result = FAIL;
  5434. char message[80]={0};
  5435. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5436. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  5437. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5438. LWS_Send(message);
  5439. result = TRUE;
  5440. return result;
  5441. }
  5442. int sendUpdateFirmwareConfirmation(char *uuid)
  5443. {
  5444. mtrace();
  5445. int result = FAIL;
  5446. char message[60]={0};
  5447. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5448. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  5449. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5450. LWS_Send(message);
  5451. result = TRUE;
  5452. return result;
  5453. }
  5454. //==========================================
  5455. // send CallError routine
  5456. //==========================================
  5457. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  5458. {
  5459. mtrace();
  5460. char message[220]={0};
  5461. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  5462. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  5463. LWS_Send(message);
  5464. }
  5465. //==========================================
  5466. // Handle server request routine Start
  5467. //==========================================
  5468. int handleCancelReservationRequest(char *uuid, char *payload)
  5469. {
  5470. mtrace();
  5471. int result = FAIL;
  5472. int gunNO = 0;
  5473. int reservationIdInt = -1;
  5474. char comfirmstr[20];
  5475. DEBUG_INFO("handleCancelReservationRequest...\n");
  5476. json_object *CancelReservation;
  5477. CancelReservation = json_tokener_parse(payload);
  5478. if(!is_error(CancelReservation))
  5479. {
  5480. // Required data
  5481. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  5482. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  5483. }
  5484. json_object_put(CancelReservation);
  5485. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  5486. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5487. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  5488. if(reservationIdInt != -1)
  5489. {
  5490. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  5491. //check Transaction active
  5492. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5493. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5494. {
  5495. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  5496. {
  5497. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5498. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5499. if(gunType[2] == GUN_TYPE_CHAdeMO)
  5500. {
  5501. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  5502. }
  5503. else
  5504. {
  5505. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  5506. }
  5507. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5508. goto end;
  5509. }
  5510. }
  5511. for (int index = 0; index < CCS_QUANTITY; index++)
  5512. {
  5513. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  5514. {
  5515. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5516. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5517. if(gunType[2] == GUN_TYPE_CCS)
  5518. {
  5519. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  5520. }
  5521. else
  5522. {
  5523. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  5524. }
  5525. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5526. goto end;
  5527. }
  5528. }
  5529. for (int index = 0; index < GB_QUANTITY; index++)
  5530. {
  5531. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  5532. {
  5533. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5534. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5535. if(gunType[2] == GUN_TYPE_GBT)
  5536. {
  5537. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  5538. }
  5539. else
  5540. {
  5541. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  5542. }
  5543. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5544. goto end;
  5545. }
  5546. }
  5547. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5548. {
  5549. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  5550. {
  5551. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5552. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5553. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  5554. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5555. goto end;
  5556. }
  5557. }
  5558. for (int index = 0; index < AC_QUANTITY; index++)
  5559. {
  5560. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  5561. {
  5562. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5563. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5564. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5565. {
  5566. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  5567. }
  5568. else
  5569. {
  5570. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  5571. }
  5572. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5573. goto end;
  5574. }
  5575. }
  5576. }
  5577. //The reservationId does NOT match the reservationId
  5578. sendCancelReservationConfirmation(uuid, comfirmstr);
  5579. end:
  5580. // Fill in ocpp packet uuid
  5581. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  5582. return result;
  5583. }
  5584. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  5585. {
  5586. mtrace();
  5587. int result = FAIL;
  5588. int gunIndex = 0;
  5589. char typeStr[16]={0};
  5590. char comfirmstr[20];
  5591. int specificId = FALSE;
  5592. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  5593. json_object *ChangeAvailability;
  5594. ChangeAvailability = json_tokener_parse(payload);
  5595. if(!is_error(ChangeAvailability))
  5596. {
  5597. // Required data
  5598. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  5599. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  5600. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  5601. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  5602. }
  5603. json_object_put(ChangeAvailability);
  5604. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5605. {
  5606. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  5607. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  5608. }
  5609. else if(gunIndex == 0)
  5610. {
  5611. for(int i=0; i < gunTotalNumber; i++)
  5612. {
  5613. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  5614. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  5615. }
  5616. }
  5617. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5618. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5619. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  5620. {
  5621. specificId = TRUE;
  5622. }
  5623. if(specificId == FALSE)
  5624. goto end;
  5625. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  5626. {
  5627. //----------------------gunIndex is 0 ------------------------------------------------//
  5628. if(gunIndex == 0)
  5629. {
  5630. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5631. {
  5632. for(int i=0; i < gunTotalNumber; i++)
  5633. {
  5634. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5635. {
  5636. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  5637. {
  5638. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5639. {
  5640. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5641. goto end;
  5642. }
  5643. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5644. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5645. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5646. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5647. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5648. {
  5649. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5650. goto end;
  5651. }
  5652. }
  5653. }//END FOR CHAdeMO_QUANTITY
  5654. for (int index = 0; index < CCS_QUANTITY; index++)
  5655. {
  5656. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  5657. {
  5658. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  5659. {
  5660. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5661. goto end;
  5662. }
  5663. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5664. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5665. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5666. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5667. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5668. {
  5669. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5670. goto end;
  5671. }
  5672. }
  5673. }//END FOR CCS_QUANTITY
  5674. for (int index = 0; index < GB_QUANTITY; index++)
  5675. {
  5676. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  5677. {
  5678. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5679. {
  5680. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5681. goto end;
  5682. }
  5683. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5684. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5685. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5686. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5687. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5688. {
  5689. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5690. goto end;
  5691. }
  5692. }
  5693. }// END FOR GB_QUANTITY
  5694. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5695. {
  5696. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  5697. {
  5698. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5699. {
  5700. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5701. goto end;
  5702. }
  5703. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  5704. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  5705. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  5706. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  5707. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5708. {
  5709. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5710. goto end;
  5711. }
  5712. }
  5713. }// END FOR GENERAL_GUN_QUANTITY
  5714. for (int index = 0; index < AC_QUANTITY; index++)
  5715. {
  5716. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  5717. {
  5718. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5719. {
  5720. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5721. goto end;
  5722. }
  5723. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5724. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5725. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5726. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5727. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5728. {
  5729. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5730. goto end;
  5731. }
  5732. }
  5733. }//END FOR AC_QUANTITY
  5734. }// END FOR gunTotalNumber
  5735. }
  5736. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5737. {
  5738. for(int i=0; i < gunTotalNumber; i++)
  5739. {
  5740. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5741. {
  5742. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5743. goto end;
  5744. }
  5745. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5746. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  5747. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  5748. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  5749. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5750. {
  5751. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5752. goto end;
  5753. }
  5754. }
  5755. }
  5756. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5757. goto end;
  5758. }
  5759. //----------------------gunIndex is not 0 ------------------------------------------------//
  5760. //check Transaction active
  5761. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5762. {
  5763. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  5764. {
  5765. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  5766. {
  5767. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5768. goto end;
  5769. }
  5770. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5771. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5772. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5773. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5774. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5775. {
  5776. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5777. goto end;
  5778. }
  5779. else
  5780. {
  5781. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  5782. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5783. goto end;
  5784. }
  5785. }
  5786. }//END FOR CHAdeMO_QUANTITY
  5787. for (int index = 0; index < CCS_QUANTITY; index++)
  5788. {
  5789. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  5790. {
  5791. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  5792. {
  5793. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5794. goto end;
  5795. }
  5796. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5797. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5798. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5799. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5800. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5801. {
  5802. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5803. goto end;
  5804. }
  5805. else
  5806. {
  5807. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  5808. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5809. goto end;
  5810. }
  5811. }
  5812. }//END FOR CCS_QUANTITY
  5813. for (int index = 0; index < GB_QUANTITY; index++)
  5814. {
  5815. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  5816. {
  5817. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5818. {
  5819. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5820. goto end;
  5821. }
  5822. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5823. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5824. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5825. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5826. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5827. {
  5828. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5829. goto end;
  5830. }
  5831. else
  5832. {
  5833. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  5834. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5835. goto end;
  5836. }
  5837. }
  5838. }// END FOR GB_QUANTITY
  5839. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5840. {
  5841. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  5842. {
  5843. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5844. {
  5845. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5846. goto end;
  5847. }
  5848. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  5849. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  5850. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  5851. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  5852. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5853. {
  5854. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5855. goto end;
  5856. }
  5857. else
  5858. {
  5859. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  5860. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5861. goto end;
  5862. }
  5863. }
  5864. }// END FOR GENERAL_GUN_QUANTITY
  5865. for (int index = 0; index < AC_QUANTITY; index++)
  5866. {
  5867. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  5868. {
  5869. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5870. {
  5871. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5872. goto end;
  5873. }
  5874. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5875. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5876. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5877. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5878. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5879. {
  5880. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5881. goto end;
  5882. }
  5883. else
  5884. {
  5885. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  5886. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5887. goto end;
  5888. }
  5889. }
  5890. }//END FOR AC_QUANTITY
  5891. }//END FOR AvailabilityTypeStr[Inoperative]
  5892. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  5893. {
  5894. //----------------------gunIndex is 0 ------------------------------------------------//
  5895. if(gunIndex == 0)
  5896. {
  5897. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5898. {
  5899. for(int i=0; i < gunTotalNumber; i++)
  5900. {
  5901. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5902. {
  5903. if ((gunType[i] == GUN_TYPE_CHAdeMO )&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO)) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5904. {
  5905. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5906. goto end;
  5907. }
  5908. }//END FOR CHAdeMO_QUANTITY
  5909. for (int index = 0; index < CCS_QUANTITY; index++)
  5910. {
  5911. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT//(((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5912. {
  5913. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5914. goto end;
  5915. }
  5916. }//END FOR CCS_QUANTITY
  5917. for (int index = 0; index < GB_QUANTITY; index++)
  5918. {
  5919. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G')))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5920. {
  5921. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5922. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5923. goto end;
  5924. }
  5925. }// END FOR GB_QUANTITY
  5926. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5927. {
  5928. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'O')))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5929. {
  5930. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5931. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5932. goto end;
  5933. }
  5934. }// END FOR GENERAL_GUN_QUANTITY
  5935. for (int index = 0; index < AC_QUANTITY; index++)
  5936. {
  5937. if ((gunType[i] == GUN_TYPE_AC) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT // (((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5938. {
  5939. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5940. goto end;
  5941. }
  5942. }//END FOR CHAdeMO_QUANTITY
  5943. }// END FOR gunTotalNumber
  5944. }
  5945. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5946. {
  5947. for(int i=0; i < gunTotalNumber; i++)
  5948. {
  5949. for (int index = 0; index < AC_QUANTITY; index++)
  5950. {
  5951. if ((gunType[i] == GUN_TYPE_AC) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT // (((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5952. {
  5953. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5954. goto end;
  5955. }
  5956. }//END FOR CHAdeMO_QUANTITY
  5957. } // END FOR gunTotalNumber
  5958. }
  5959. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5960. goto end;
  5961. }
  5962. //----------------------gunIndex is not 0 ------------------------------------------------//
  5963. //check Transaction active
  5964. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5965. {
  5966. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5967. {
  5968. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5969. goto end;
  5970. }
  5971. }//END FOR CHAdeMO_QUANTITY
  5972. for (int index = 0; index < CCS_QUANTITY; index++)
  5973. {
  5974. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5975. {
  5976. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5977. goto end;
  5978. }
  5979. }//END FOR CCS_QUANTITY
  5980. for (int index = 0; index < GB_QUANTITY; index++)
  5981. {
  5982. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5983. {
  5984. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5985. goto end;
  5986. }
  5987. }// END FOR GB_QUANTITY
  5988. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5989. {
  5990. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5991. {
  5992. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5993. goto end;
  5994. }
  5995. }// END FOR GENERAL_GUN_QUANTITY
  5996. for (int index = 0; index < AC_QUANTITY; index++)
  5997. {
  5998. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5999. {
  6000. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6001. goto end;
  6002. }
  6003. }//END FOR AC_QUANTITY
  6004. }//END FOR AvailabilityTypeStr[Operative]
  6005. end:
  6006. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6007. {
  6008. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  6009. }
  6010. else
  6011. {
  6012. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  6013. }
  6014. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6015. {
  6016. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6017. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6018. }
  6019. else if(gunIndex == 0)
  6020. {
  6021. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6022. {
  6023. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  6024. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  6025. }
  6026. }
  6027. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  6028. return result;
  6029. }
  6030. int handleChangeConfigurationRequest(char *uuid, char *payload)
  6031. {
  6032. mtrace();
  6033. int result = FAIL;
  6034. char keystr[40]={0};
  6035. char valuestr[100]={0};
  6036. char comfirmstr[20]={0};
  6037. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  6038. json_object *ChangeConfiguration;
  6039. ChangeConfiguration = json_tokener_parse(payload);
  6040. if(!is_error(ChangeConfiguration))
  6041. {
  6042. // Required data
  6043. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  6044. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  6045. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  6046. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  6047. }
  6048. json_object_put(ChangeConfiguration);
  6049. if((uuid==NULL) || (payload ==NULL) )
  6050. {
  6051. DEBUG_ERROR("Payload is null\n");
  6052. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6053. }
  6054. else
  6055. {
  6056. int status = setKeyValue(keystr, valuestr);
  6057. switch(status)
  6058. {
  6059. case ConfigurationStatus_Accepted:
  6060. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  6061. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  6062. StoreConfigurationTable();
  6063. break;
  6064. case RebootRequired:
  6065. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  6066. StoreConfigurationTable();
  6067. break;
  6068. case NotSupported:
  6069. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  6070. break;
  6071. case ConfigurationStatus_Rejected:
  6072. default:
  6073. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6074. break;
  6075. }
  6076. }
  6077. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  6078. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  6079. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6080. {
  6081. ChageWebSocketPingInterval(atoi(valuestr));
  6082. }
  6083. if((strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6084. {
  6085. SetOcppConnStatus(FALSE);
  6086. }
  6087. return result;
  6088. }
  6089. int handleClearCacheRequest(char *uuid, char *payload)
  6090. {
  6091. mtrace();
  6092. int result = FAIL;
  6093. char comfirmstr[20];
  6094. char rmFileCmd[100]={0};
  6095. struct stat stats;
  6096. DEBUG_INFO("handleClearCacheRequest...\n");
  6097. stat("/Storage/OCPP", &stats);
  6098. // Check for directory existence
  6099. if (S_ISDIR(stats.st_mode) == 1)
  6100. {}
  6101. else
  6102. {
  6103. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  6104. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  6105. system(rmFileCmd);
  6106. }
  6107. if(OCPP_cleanLocalCache())
  6108. {
  6109. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  6110. }
  6111. else
  6112. {
  6113. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  6114. }
  6115. sendClearCacheConfirmation(uuid, comfirmstr);
  6116. return result;
  6117. }
  6118. int handleClearChargingProfileRequest(char *uuid, char *payload)
  6119. {
  6120. mtrace();
  6121. int result = FAIL;
  6122. int resultRename;
  6123. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  6124. char chargingProfilePurposeStr[26]={0};
  6125. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  6126. char tempchargingProfilePurposeStr[26]={0};
  6127. char str[100]={0};
  6128. char fname[200]={0};
  6129. char comfirmstr[20]={0};
  6130. char word[1600]={0};
  6131. int clearflag = FALSE;
  6132. int chargingProfileIdIsNULL = FALSE;
  6133. int connectorIsNULL = FALSE;
  6134. int chargingProfilePurposeIsNULL = FALSE;
  6135. int stackLevelIsNULL = FALSE;
  6136. //int GotoEnd = FALSE;
  6137. FILE *fptr1, *fptr2;
  6138. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  6139. int n_chargingProfile=0;
  6140. int isEmptyFile = FALSE;
  6141. char sLineWord[1600]={0};
  6142. char chargingProfiles[10][100]={0};
  6143. int ChargeProfileCount = 0;
  6144. int ch;
  6145. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  6146. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  6147. json_object *ClearChargingProfile;
  6148. ClearChargingProfile = json_tokener_parse(payload);
  6149. if(!is_error(ClearChargingProfile))
  6150. {
  6151. // Optional data
  6152. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  6153. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  6154. else
  6155. chargingProfileIdIsNULL = TRUE;
  6156. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  6157. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  6158. else
  6159. connectorIsNULL = TRUE;
  6160. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  6161. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  6162. else
  6163. chargingProfilePurposeIsNULL = TRUE;
  6164. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  6165. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  6166. else
  6167. stackLevelIsNULL = TRUE;
  6168. }
  6169. json_object_put(ClearChargingProfile);
  6170. if(connectorIsNULL == FALSE)
  6171. {
  6172. switch(connectorIdInt)
  6173. {
  6174. case 0:
  6175. if(chargingProfilePurposeIsNULL == TRUE)
  6176. {
  6177. int l = 0;
  6178. strcpy(fname, ChargePointMaxProfile_JSON);
  6179. if((access(fname,F_OK))!=-1)
  6180. {
  6181. strcpy(chargingProfiles[l], fname);
  6182. l = l + 1;
  6183. }
  6184. strcpy(fname, TxDefaultProfile_0_JSON);
  6185. if((access(fname,F_OK))!=-1)
  6186. {
  6187. strcpy(chargingProfiles[l], fname);
  6188. l = l + 1;
  6189. }
  6190. ChargeProfileCount = l;
  6191. }
  6192. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  6193. {
  6194. strcpy(fname, ChargePointMaxProfile_JSON);
  6195. if((access(fname,F_OK))!=-1)
  6196. {
  6197. strcpy(chargingProfiles[0], fname);
  6198. ChargeProfileCount = 1;
  6199. }
  6200. }
  6201. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6202. {
  6203. strcpy(fname, TxDefaultProfile_0_JSON);
  6204. if((access(fname,F_OK))!=-1)
  6205. {
  6206. strcpy(chargingProfiles[0], fname);
  6207. ChargeProfileCount = 1;
  6208. }
  6209. }
  6210. break;
  6211. default:
  6212. if(chargingProfilePurposeIsNULL == TRUE)
  6213. {
  6214. int m = 0;
  6215. memset(fname, 0, ARRAY_SIZE(fname));
  6216. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6217. if((access(fname,F_OK))!=-1)
  6218. {
  6219. strcpy(chargingProfiles[m], fname);
  6220. m = m + 1;
  6221. }
  6222. memset(fname, 0, ARRAY_SIZE(fname));
  6223. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6224. if((access(fname,F_OK))!=-1)
  6225. {
  6226. strcpy(chargingProfiles[m], fname);
  6227. m = m + 1;
  6228. }
  6229. ChargeProfileCount = m;
  6230. }
  6231. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6232. {
  6233. //strcpy(fname, TxDefaultProfile_1_JSON);
  6234. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6235. if((access(fname,F_OK))!=-1)
  6236. {
  6237. strcpy(chargingProfiles[0], fname);
  6238. ChargeProfileCount = 1;
  6239. }
  6240. }
  6241. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  6242. {
  6243. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6244. if((access(fname,F_OK))!=-1)
  6245. {
  6246. strcpy(chargingProfiles[0], fname);
  6247. ChargeProfileCount = 1;
  6248. }
  6249. //strcpy(fname, TxProfile_1_JSON);
  6250. }
  6251. //strcpy(fname, ChargePointMaxProfile_JSON );
  6252. break;
  6253. }
  6254. }
  6255. else // Check all Charging Profiles
  6256. {
  6257. int i = 0;
  6258. char fnametemp[200]={0};
  6259. ChargeProfileCount = 0;
  6260. //Check ChargePointMaxProfile.json exit
  6261. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  6262. {
  6263. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  6264. i = i + 1;
  6265. }
  6266. //Check TxDefaultProfile_0.json exit
  6267. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  6268. {
  6269. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  6270. i = i + 1;
  6271. }
  6272. //Check TxDefaultProfile_%d.json
  6273. for(int j=1; j <= gunTotalNumber; j++)
  6274. {
  6275. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6276. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  6277. if((access(fnametemp,F_OK))!=-1)
  6278. {
  6279. strcpy(chargingProfiles[i], fnametemp);
  6280. i = i + 1;
  6281. }
  6282. }
  6283. //Check TxProfile_%d.json
  6284. for(int j=1; j <= gunTotalNumber; j++)
  6285. {
  6286. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6287. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  6288. if((access(fnametemp,F_OK))!=-1)
  6289. {
  6290. strcpy(chargingProfiles[i], fnametemp);
  6291. i = i + 1;
  6292. }
  6293. }
  6294. ChargeProfileCount = i;
  6295. }// End connectorIsNULL is TRUE
  6296. if(ChargeProfileCount == 0)
  6297. {
  6298. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6299. goto end;
  6300. }
  6301. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  6302. {
  6303. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6304. goto end;
  6305. }
  6306. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  6307. {
  6308. memset(str, 0, ARRAY_SIZE(str));
  6309. // clear temp file
  6310. sprintf(str,"rm -f %s",temp);
  6311. system(str);
  6312. for(int k=0; k < ChargeProfileCount; k++)
  6313. {
  6314. memset(str, 0, ARRAY_SIZE(str));
  6315. //clear file in C
  6316. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6317. system(str);
  6318. }
  6319. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6320. goto end;
  6321. }
  6322. else if(connectorIsNULL == TRUE)
  6323. {
  6324. for(int k=0; k < ChargeProfileCount; k++)
  6325. {
  6326. fptr1 = fopen(chargingProfiles[k], "r");
  6327. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  6328. //Check Charging Profile Count
  6329. while(fscanf(fptr1, "%s", word) != EOF)
  6330. {
  6331. //DEBUG_INFO("word=%s\n",word);
  6332. if(strstr(word, "chargingProfileId")!= NULL)
  6333. {
  6334. //DEBUG_INFO("test chargingProfileId \n");
  6335. n_chargingProfile = n_chargingProfile + 1;
  6336. //DEBUG_INFO("chargingProfileId Found\n");
  6337. }
  6338. }
  6339. rewind(fptr1);
  6340. //search Charging Profile Element
  6341. //int i= 0;
  6342. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6343. {
  6344. json_object *tmpProfilee;
  6345. tmpProfilee = json_tokener_parse(sLineWord);
  6346. if(!is_error(tmpProfilee))
  6347. {
  6348. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  6349. {
  6350. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  6351. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  6352. }
  6353. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  6354. {
  6355. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  6356. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  6357. }
  6358. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  6359. {
  6360. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  6361. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  6362. }
  6363. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  6364. {
  6365. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  6366. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  6367. }
  6368. }
  6369. json_object_put(tmpProfilee);
  6370. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6371. {
  6372. //------- not write to fptr2-------//
  6373. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6374. //clearflag = TRUE;
  6375. }
  6376. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  6377. {
  6378. //------- not write to fptr2-------//
  6379. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6380. }
  6381. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6382. {
  6383. //------- not write to fptr2-------//
  6384. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6385. }
  6386. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  6387. {
  6388. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6389. }
  6390. else
  6391. {
  6392. fprintf(fptr2, sLineWord);//writing data into file
  6393. }
  6394. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6395. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6396. if(clearflag == TRUE)
  6397. {
  6398. fclose(fptr1);
  6399. fclose(fptr2);
  6400. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6401. system(str);
  6402. // clear temp file
  6403. sprintf(str,"rm -f %s",temp);
  6404. system(str);
  6405. }
  6406. else
  6407. {
  6408. fclose(fptr1);
  6409. fclose(fptr2);
  6410. memset(str, 0, ARRAY_SIZE(str));
  6411. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6412. system(str);
  6413. resultRename = rename(temp, chargingProfiles[k]);
  6414. if(resultRename == 0)
  6415. {
  6416. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  6417. }
  6418. else
  6419. {
  6420. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  6421. }
  6422. if(comfirmstr[0]== 0)
  6423. {
  6424. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6425. }
  6426. //Check chargingProfile is empty file
  6427. /*------ Read the file ----------------*/
  6428. fptr1=fopen(chargingProfiles[k],"r");
  6429. ch=fgetc(fptr1);
  6430. rewind(fptr1);
  6431. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6432. if(ch!=EOF)
  6433. {
  6434. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6435. {
  6436. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6437. if(sLineWord[0]=='\0')
  6438. {
  6439. isEmptyFile = TRUE;
  6440. break;
  6441. }
  6442. else
  6443. {
  6444. isEmptyFile = FALSE;
  6445. break;
  6446. }
  6447. }
  6448. }
  6449. else
  6450. isEmptyFile = TRUE;
  6451. fclose(fptr1);
  6452. if(isEmptyFile == TRUE)
  6453. {
  6454. memset(str, 0, ARRAY_SIZE(str));
  6455. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6456. system(str);
  6457. }
  6458. }
  6459. }// End of while(int k=0; k < ChargePointCount; k++)
  6460. }
  6461. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  6462. {
  6463. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  6464. for(int k=0; k < ChargeProfileCount; k++)
  6465. {
  6466. fptr1 = fopen(chargingProfiles[k], "r");
  6467. fptr2 = fopen(temp, "w+");
  6468. //Check Charging Profile Count
  6469. while(fscanf(fptr1, "%s", word) != EOF)
  6470. {
  6471. //DEBUG_INFO("word=%s\n",word);
  6472. if(strstr(word, "chargingProfileId")!= NULL)
  6473. {
  6474. n_chargingProfile = n_chargingProfile + 1;
  6475. }
  6476. }
  6477. rewind(fptr1);
  6478. //search Charging Profile Element
  6479. //int i= 0;
  6480. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6481. {
  6482. json_object *tmpProfilee;
  6483. tmpProfilee = json_tokener_parse(sLineWord);
  6484. if(!is_error(tmpProfilee))
  6485. {
  6486. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  6487. {
  6488. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  6489. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  6490. }
  6491. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  6492. {
  6493. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  6494. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  6495. }
  6496. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  6497. {
  6498. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  6499. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  6500. }
  6501. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  6502. {
  6503. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  6504. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  6505. }
  6506. }
  6507. json_object_put(tmpProfilee);
  6508. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6509. {
  6510. //------- not write to fptr2-------//
  6511. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6512. //clearflag = TRUE;
  6513. }
  6514. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6515. {
  6516. //------- not write to fptr2-------//
  6517. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6518. }
  6519. else if(stackLevelIsNULL == TRUE)
  6520. {
  6521. //Clear Whole File
  6522. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6523. clearflag = TRUE;
  6524. break;
  6525. }
  6526. else
  6527. {
  6528. fprintf(fptr2, sLineWord);//writing data into file
  6529. }
  6530. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6531. }
  6532. if(clearflag == TRUE)
  6533. {
  6534. fclose(fptr1);
  6535. fclose(fptr2);
  6536. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6537. system(str);
  6538. // clear temp file
  6539. sprintf(str,"rm -f %s",temp);
  6540. system(str);
  6541. }
  6542. else
  6543. {
  6544. fclose(fptr1);
  6545. fclose(fptr2);
  6546. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6547. system(str);
  6548. resultRename = rename(temp, chargingProfiles[k]);
  6549. if(resultRename == 0)
  6550. {
  6551. DEBUG_INFO("File ChargingProfile renamed successfully");
  6552. }
  6553. else
  6554. {
  6555. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6556. }
  6557. if(comfirmstr[0]== 0)
  6558. {
  6559. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6560. }
  6561. //Check chargingProfile is empty file
  6562. /*------ Read the file ----------------*/
  6563. fptr1=fopen(chargingProfiles[k],"r");
  6564. ch=fgetc(fptr1);
  6565. rewind(fptr1);
  6566. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6567. if(ch!=EOF)
  6568. {
  6569. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6570. {
  6571. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6572. if(sLineWord[0]=='\0')
  6573. {
  6574. isEmptyFile = TRUE;
  6575. break;
  6576. }
  6577. else
  6578. {
  6579. isEmptyFile = FALSE;
  6580. break;
  6581. }
  6582. }
  6583. }
  6584. else
  6585. isEmptyFile = TRUE;
  6586. fclose(fptr1);
  6587. if(isEmptyFile == TRUE)
  6588. {
  6589. memset(str, 0, ARRAY_SIZE(str));
  6590. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6591. system(str);
  6592. }
  6593. /*------- End of reading ---------------*/
  6594. }
  6595. } // while(int k=0; k < ChargeProfileCount; k++)
  6596. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  6597. end:
  6598. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  6599. {
  6600. if(connectorIdInt == 0)
  6601. {
  6602. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  6603. {
  6604. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  6605. }
  6606. }
  6607. else
  6608. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  6609. }
  6610. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  6611. return result;
  6612. }
  6613. void createFirmwareVersionByDataTransfer(void)
  6614. {
  6615. json_object *FirmwareDataTransfer = json_object_new_object();
  6616. // AC & DC model
  6617. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  6618. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  6619. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  6620. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  6621. // DC model
  6622. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O')
  6623. {
  6624. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  6625. {
  6626. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6627. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6628. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  6629. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  6630. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6631. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6632. }
  6633. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  6634. ((gunType[1] != GUN_TYPE_UNKNOWN) || (gunType[2] != GUN_TYPE_UNKNOWN) || (gunType[3] != GUN_TYPE_UNKNOWN)))
  6635. {
  6636. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  6637. }
  6638. }
  6639. else
  6640. {
  6641. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6642. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6643. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6644. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6645. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  6646. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  6647. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  6648. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  6649. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  6650. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  6651. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  6652. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  6653. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  6654. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  6655. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  6656. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  6657. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  6658. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  6659. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  6660. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  6661. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  6662. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  6663. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  6664. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  6665. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  6666. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  6667. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  6668. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  6669. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  6670. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  6671. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  6672. }
  6673. // 4G model
  6674. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  6675. {
  6676. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  6677. }
  6678. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "Phihong Technology");
  6679. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  6680. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  6681. json_object_put(FirmwareDataTransfer);
  6682. }
  6683. int handleDataTransferRequest(char *uuid, char *payload)
  6684. {
  6685. mtrace();
  6686. json_object *response = json_object_new_object();
  6687. int result = FAIL;
  6688. char tempvendorId[255]={0};
  6689. char tempmessageId[50]={0};
  6690. char tempdata[512]={0};
  6691. char message[2048]={0};
  6692. DEBUG_INFO("handleDataTransferRequest...\n");
  6693. if((uuid != NULL) && (payload != NULL))
  6694. {
  6695. json_object *DataTransfer;
  6696. DataTransfer = json_tokener_parse(payload);
  6697. if(!is_error(DataTransfer))
  6698. {
  6699. // Required data
  6700. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  6701. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  6702. // Optional data
  6703. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  6704. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  6705. if(json_object_object_get(DataTransfer, "data") != NULL)
  6706. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  6707. result = PASS;
  6708. }
  6709. json_object_put(DataTransfer);
  6710. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  6711. {
  6712. // Send all moudle firmware version on EVSE
  6713. createFirmwareVersionByDataTransfer();
  6714. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6715. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  6716. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6717. json_object_put(response);
  6718. }
  6719. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  6720. {
  6721. system("/usr/bin/run_tmate_restart.sh &");
  6722. }
  6723. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  6724. {
  6725. json_object *data;
  6726. data = json_tokener_parse(tempdata);
  6727. if(!is_error(data))
  6728. {
  6729. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  6730. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  6731. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  6732. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  6733. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  6734. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  6735. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  6736. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  6737. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  6738. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  6739. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6740. }
  6741. else
  6742. {
  6743. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6744. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6745. }
  6746. json_object_put(data);
  6747. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6748. json_object_put(response);
  6749. }
  6750. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  6751. {
  6752. json_object *data;
  6753. data = json_tokener_parse(tempdata);
  6754. if(!is_error(data))
  6755. {
  6756. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  6757. if(json_object_object_get(data, "idToken") != NULL)
  6758. {
  6759. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  6760. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  6761. }
  6762. if(json_object_object_get(data, "price") != NULL)
  6763. {
  6764. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  6765. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  6766. }
  6767. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6768. }
  6769. else
  6770. {
  6771. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6772. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6773. }
  6774. json_object_put(data);
  6775. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6776. json_object_put(response);
  6777. }
  6778. else if(strstr(tempmessageId, "RunningCost") != NULL)
  6779. {
  6780. json_object *data;
  6781. data = json_tokener_parse(tempdata);
  6782. if(!is_error(data))
  6783. {
  6784. if(json_object_object_get(data, "txId") != NULL)
  6785. {
  6786. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  6787. for(int idx = 0;idx<gunTotalNumber;idx++)
  6788. {
  6789. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  6790. {
  6791. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  6792. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  6793. if(json_object_object_get(data, "description") != NULL)
  6794. {
  6795. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  6796. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  6797. }
  6798. }
  6799. }
  6800. }
  6801. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6802. }
  6803. else
  6804. {
  6805. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6806. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6807. }
  6808. json_object_put(data);
  6809. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6810. json_object_put(response);
  6811. }
  6812. else if(strstr(tempmessageId, "FinalCost") != NULL)
  6813. {
  6814. json_object *data;
  6815. data = json_tokener_parse(tempdata);
  6816. if(!is_error(data))
  6817. {
  6818. if(json_object_object_get(data, "txId") != NULL)
  6819. {
  6820. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  6821. for(int idx = 0;idx<gunTotalNumber;idx++)
  6822. {
  6823. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  6824. {
  6825. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  6826. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  6827. if(json_object_object_get(data, "description") != NULL)
  6828. {
  6829. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  6830. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  6831. }
  6832. }
  6833. }
  6834. }
  6835. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6836. }
  6837. else
  6838. {
  6839. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6840. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6841. }
  6842. json_object_put(data);
  6843. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6844. json_object_put(response);
  6845. }
  6846. else
  6847. {
  6848. // Can not find valid message id
  6849. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  6850. }
  6851. }
  6852. else
  6853. {
  6854. // Payload is null
  6855. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  6856. }
  6857. LWS_Send(message);
  6858. return result;
  6859. }
  6860. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  6861. {
  6862. mtrace();
  6863. int result = FAIL;
  6864. int connectorIdInt, durationInt;
  6865. char chargingRateUnitStr[4]={0};
  6866. char comfirmstr[20];
  6867. int confirmPeriods = 0;
  6868. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  6869. json_object *GetCompositeSchedule;
  6870. GetCompositeSchedule = json_tokener_parse(payload);
  6871. if(!is_error(GetCompositeSchedule))
  6872. {
  6873. // Required data
  6874. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  6875. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  6876. else
  6877. connectorIdInt = -1;
  6878. if(json_object_object_get(GetCompositeSchedule, "duration"))
  6879. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  6880. else
  6881. durationInt = 86400;
  6882. // Optional data
  6883. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  6884. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  6885. }
  6886. json_object_put(GetCompositeSchedule);
  6887. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  6888. if((connectorIdInt == 0) ||
  6889. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  6890. {
  6891. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  6892. struct StructChargingProfile tmpProfile[1];
  6893. if(strstr(chargingRateUnitStr, "W") != NULL)
  6894. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  6895. else
  6896. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  6897. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6898. {
  6899. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6900. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6901. }
  6902. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  6903. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  6904. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  6905. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6906. {
  6907. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6908. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6909. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  6910. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  6911. {
  6912. confirmPeriods = idx;
  6913. break;
  6914. }
  6915. }
  6916. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6917. }
  6918. else
  6919. {
  6920. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  6921. }
  6922. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  6923. return result;
  6924. }
  6925. int handleGetConfigurationRequest(char *uuid, char *payload)
  6926. {
  6927. mtrace();
  6928. int result = FAIL;
  6929. int MaxKeySupported = 0;
  6930. int n_keys = 0;
  6931. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  6932. DEBUG_INFO("handleGetConfigurationRequest...\n");
  6933. json_object *GetConfiguration;
  6934. GetConfiguration = json_tokener_parse(payload);
  6935. if(!is_error(GetConfiguration))
  6936. {
  6937. // Optional data
  6938. if(json_object_object_get(GetConfiguration, "key") != NULL)
  6939. {
  6940. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  6941. {
  6942. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  6943. n_keys = idx + 1;
  6944. }
  6945. }
  6946. }
  6947. json_object_put(GetConfiguration);
  6948. UnknownKeynum = 0;
  6949. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  6950. MaxKeySupported = GetConfigurationMaxKeysNUM;
  6951. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  6952. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  6953. if(n_keys != 0)
  6954. {
  6955. for(int i=0;i<n_keys;i++)
  6956. {
  6957. getKeyValue(requestKey[i]);
  6958. }
  6959. }
  6960. else
  6961. {
  6962. DEBUG_INFO("There is no key in Message, get all configuration\n");
  6963. getKeyValue("");
  6964. }
  6965. processUnkownKey();
  6966. sendGetConfigurationConfirmation(uuid);
  6967. return result;
  6968. }
  6969. static char fnamePlusPath[100]={0};
  6970. static char fnamePWithNoPath[60]={0};
  6971. void checkUploadLog(void)
  6972. {
  6973. FILE *fp;
  6974. /* Open the command for reading. */
  6975. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  6976. if (fp == NULL) {
  6977. printf("Failed to run command\n" );
  6978. exit(1);
  6979. }
  6980. int ftppathlen = 0;
  6981. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  6982. int i = 0;
  6983. /* Read the output a line at a time - output it. */
  6984. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  6985. if(i==0)
  6986. {
  6987. ftppathlen = strlen(fnamePlusPath);
  6988. printf("%s\n", fnamePlusPath);
  6989. fnamePlusPath[ftppathlen]='\0';
  6990. break;
  6991. }
  6992. i= i+1;
  6993. }
  6994. /* close */
  6995. pclose(fp);
  6996. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  6997. {
  6998. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  6999. {
  7000. fnamePlusPath[k]='\0';
  7001. }
  7002. }
  7003. i=1;
  7004. //char fname[60]={0};
  7005. while(i < ftppathlen)
  7006. {
  7007. int len=ftppathlen-i;
  7008. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  7009. {
  7010. printf("compare '/' all right\n");
  7011. break;
  7012. }
  7013. i=i+1;
  7014. }
  7015. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  7016. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  7017. fnamePWithNoPath[i+1] = '\0';
  7018. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  7019. {
  7020. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  7021. {
  7022. fnamePWithNoPath[j]='\0';
  7023. }
  7024. }
  7025. FILE* fp1 = fopen(fnamePlusPath, "r");
  7026. if (fp1)
  7027. {
  7028. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  7029. // file exists
  7030. fclose(fp1);
  7031. }
  7032. else
  7033. {
  7034. // file doesn't exist
  7035. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  7036. }
  7037. }
  7038. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  7039. {
  7040. mtrace();
  7041. int result = FAIL;
  7042. time_t CurrentTime;
  7043. struct tm *tm;
  7044. pthread_t th_Status;
  7045. CurrentTime = time(NULL);
  7046. tm = localtime(&CurrentTime);
  7047. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  7048. 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);
  7049. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  7050. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  7051. return result;
  7052. }
  7053. void* GetDiagnosticsProcess(void* data)
  7054. {
  7055. pthread_detach(pthread_self());
  7056. mtrace();
  7057. int retriesInt=0, retryIntervalInt=0;
  7058. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  7059. char protocol[10]={0}, user[50]={0},password[50]={0},host[50]={0}, path[50]={0}, ftppath[60]={0},host1[50]={0},path1[50]={0};
  7060. int port=0;
  7061. int isSuccess = FALSE;
  7062. char ftpbuf[200]={0};
  7063. char cmdBuf[512];
  7064. json_object *GetDiagnostics;
  7065. DEBUG_INFO("GetDiagnosticsProcess...\n");
  7066. GetDiagnostics = json_tokener_parse(data);
  7067. if(!is_error(GetDiagnostics))
  7068. {
  7069. // Required data
  7070. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  7071. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  7072. // Optional data
  7073. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  7074. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  7075. else
  7076. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  7077. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  7078. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  7079. else
  7080. retryIntervalInt = 30;
  7081. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  7082. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  7083. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  7084. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  7085. }
  7086. json_object_put(GetDiagnostics);
  7087. // Pack log to compress file
  7088. system("exec /root/logPackTools 'log' 6");
  7089. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  7090. system(cmdBuf);
  7091. checkUploadLog();
  7092. //****************location*******************/
  7093. if(strcmp(locationstr,"")==0)
  7094. {
  7095. DEBUG_INFO("location is <Empty>!\n");
  7096. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7097. goto end;
  7098. }
  7099. memset(protocol, 0, ARRAY_SIZE(protocol));
  7100. memset(user, 0, ARRAY_SIZE(user) );
  7101. memset(password, 0, ARRAY_SIZE(password));
  7102. memset(host, 0, ARRAY_SIZE(host));
  7103. memset(path, 0, ARRAY_SIZE(path));
  7104. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  7105. memset(host1, 0, ARRAY_SIZE(host1));
  7106. memset(path1, 0, ARRAY_SIZE(path1));
  7107. /*location: ftp://user:password@host:port/path*/
  7108. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  7109. if((access(fnamePlusPath,F_OK))!=-1)
  7110. {
  7111. DEBUG_INFO("fnamePlusPath exist.\n");
  7112. }
  7113. else
  7114. {
  7115. DEBUG_INFO("fnamePlusPath not exist!\n");
  7116. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7117. goto end;
  7118. }
  7119. if(strchr(locationstr,'@')==NULL)
  7120. {
  7121. sscanf(locationstr,
  7122. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  7123. protocol, host, &port, path);
  7124. strcpy(user,"anonymous");
  7125. strcpy(password,"");
  7126. }
  7127. else
  7128. {
  7129. //DEBUG_INFO("pch=%s\n", pch);
  7130. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  7131. protocol, user, password, host, &port, path);
  7132. }
  7133. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  7134. {
  7135. DEBUG_INFO("protocol is not ftp/http ! \n");
  7136. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7137. goto end;
  7138. }
  7139. if(strncmp(locationstr,"http", 4) == 0)
  7140. {
  7141. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  7142. sprintf(ftppath,"/%s", path);
  7143. do
  7144. {
  7145. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7146. sleep(3);
  7147. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  7148. if(!isSuccess)
  7149. {
  7150. DEBUG_INFO("Diagnostics fail.\n");
  7151. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7152. sleep(retryIntervalInt);
  7153. }
  7154. else
  7155. {
  7156. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7157. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7158. }
  7159. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  7160. }
  7161. else
  7162. {
  7163. sscanf(host,"%[^/]%s",host1, path1);
  7164. sprintf(ftppath,"%s", path1);
  7165. int ftppathlen=strlen(ftppath);
  7166. int i=1;
  7167. char filenametemp[50];
  7168. while(i < ftppathlen)
  7169. {
  7170. int len=ftppathlen-i;
  7171. if(ftppath[len]== 47) // '/' ascll code: 47
  7172. {
  7173. DEBUG_INFO("find '/' all right\n");
  7174. break;
  7175. }
  7176. i=i+1;
  7177. }
  7178. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  7179. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  7180. filenametemp[i+1] = 0;
  7181. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  7182. if(port == 0)
  7183. port = 21;
  7184. do
  7185. {
  7186. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7187. sleep(3);
  7188. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  7189. if(!isSuccess)
  7190. {
  7191. DEBUG_INFO("Diagnostics fail.\n");
  7192. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7193. sleep(retryIntervalInt);
  7194. }
  7195. else
  7196. {
  7197. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7198. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7199. }
  7200. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  7201. }
  7202. end:
  7203. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  7204. pthread_exit(NULL);
  7205. }
  7206. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  7207. {
  7208. mtrace();
  7209. int result = FAIL;
  7210. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  7211. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  7212. {
  7213. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  7214. localversion = -1;
  7215. }
  7216. else
  7217. {
  7218. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  7219. OCPP_getListVerion();
  7220. }
  7221. //from db.OCPP_getListVerion
  7222. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  7223. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  7224. sendGetLocalListVersionConfirmation(uuid,"");
  7225. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  7226. return result;
  7227. }
  7228. int handleRemoteStartRequest(char *uuid, char *payload)
  7229. {
  7230. mtrace();
  7231. int result = FAIL;
  7232. int connectorIdInt=0;
  7233. int tempIndex = 0;
  7234. int connectorIdIsNULL, chargingProfileIsNULL;
  7235. char comfirmstr[20]={0};
  7236. char cmdBuf[512];
  7237. json_object *RemoteStartTransaction;
  7238. FILE *fp;
  7239. DEBUG_INFO("handleRemoteStartRequest ...\n");
  7240. if(server_pending == TRUE)
  7241. {
  7242. return 0;
  7243. }
  7244. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  7245. RemoteStartTransaction = json_tokener_parse(payload);
  7246. if(!is_error(RemoteStartTransaction))
  7247. {
  7248. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  7249. {
  7250. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  7251. if(connectorIdInt <= gunTotalNumber)
  7252. {
  7253. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  7254. // Required data
  7255. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  7256. // Optional data
  7257. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  7258. {
  7259. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  7260. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  7261. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  7262. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  7263. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  7264. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  7265. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  7266. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  7267. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  7268. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  7269. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  7270. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  7271. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  7272. {
  7273. 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")));
  7274. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  7275. 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"));
  7276. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  7277. 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"));
  7278. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  7279. 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")));
  7280. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  7281. {
  7282. 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++)
  7283. {
  7284. 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"));
  7285. 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"));
  7286. 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)
  7287. 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"));
  7288. }
  7289. }
  7290. }
  7291. }
  7292. else
  7293. chargingProfileIsNULL = TRUE;
  7294. }
  7295. }
  7296. else
  7297. connectorIdIsNULL = TRUE;
  7298. }
  7299. else
  7300. connectorIdIsNULL = TRUE;
  7301. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  7302. {
  7303. DEBUG_WARN("Connector id is NULL\n.");
  7304. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7305. goto end;
  7306. }
  7307. /*
  7308. enum _SYSTEM_STATUS
  7309. {
  7310. S_BOOTING = 0,
  7311. S_IDLE, = 1
  7312. S_AUTHORIZING, = 2
  7313. S_REASSIGN_CHECK, = 3
  7314. S_REASSIGN, = 4
  7315. S_PRECHARGE, = 5
  7316. S_PREPARING_FOR_EV, = 6
  7317. S_PREPARING_FOR_EVSE, = 7
  7318. S_CHARGING, = 8
  7319. S_TERMINATING, = 9
  7320. S_COMPLETE, = 10
  7321. S_ALARM, = 11
  7322. S_FAULT = 12
  7323. }
  7324. */
  7325. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  7326. {
  7327. //check Transaction active
  7328. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  7329. {
  7330. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7331. {
  7332. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7333. }
  7334. else
  7335. {
  7336. tempIndex = connectorIdInt -1;
  7337. }
  7338. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7339. {
  7340. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  7341. {
  7342. 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))
  7343. {
  7344. //Reserved
  7345. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7346. }
  7347. 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))
  7348. {
  7349. //Reserved
  7350. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7351. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7352. goto end;
  7353. }
  7354. else
  7355. {
  7356. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7357. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  7358. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  7359. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  7360. {
  7361. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  7362. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7363. goto end;
  7364. }
  7365. }//END FOR ELSE
  7366. }
  7367. }// END FOR CHAdeMO_QUANTITY
  7368. }
  7369. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  7370. {
  7371. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7372. {
  7373. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7374. }
  7375. else
  7376. {
  7377. tempIndex = connectorIdInt -1;
  7378. }
  7379. for (int index = 0; index < CCS_QUANTITY; index++)
  7380. {
  7381. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7382. {
  7383. 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))
  7384. {
  7385. //Reserved
  7386. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7387. }
  7388. 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))
  7389. {
  7390. //Reserved
  7391. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7392. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7393. goto end;
  7394. }
  7395. else
  7396. {
  7397. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7398. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7399. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7400. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7401. {
  7402. DEBUG_WARN("CCS connector not allow start\n.");
  7403. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7404. goto end;
  7405. }
  7406. }// END FOR ELSE
  7407. }
  7408. }// END FOR CCS_QUANTITY
  7409. }
  7410. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  7411. {
  7412. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7413. {
  7414. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7415. }
  7416. else
  7417. {
  7418. tempIndex = connectorIdInt -1;
  7419. }
  7420. for (int index = 0; index < GB_QUANTITY; index++)
  7421. {
  7422. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7423. {
  7424. 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))
  7425. {
  7426. //Reserved
  7427. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7428. }
  7429. 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))
  7430. {
  7431. //Reserved
  7432. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7433. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7434. goto end;
  7435. }
  7436. else
  7437. {
  7438. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7439. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7440. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7441. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7442. {
  7443. DEBUG_WARN("GB connector not allow start\n.");
  7444. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7445. goto end;
  7446. }
  7447. }// END FOR ELSE
  7448. }
  7449. } // END FOR GB_QUANTITY
  7450. }
  7451. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  7452. {
  7453. tempIndex = connectorIdInt -1;
  7454. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7455. {
  7456. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  7457. {
  7458. 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))
  7459. {
  7460. //Reserved
  7461. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7462. }
  7463. 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))
  7464. {
  7465. //Reserved
  7466. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7467. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7468. goto end;
  7469. }
  7470. else
  7471. {
  7472. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7473. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7474. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7475. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7476. {
  7477. DEBUG_WARN("GB connector not allow start\n.");
  7478. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7479. goto end;
  7480. }
  7481. }// END FOR ELSE
  7482. }
  7483. } // END FOR GB_QUANTITY
  7484. }
  7485. else
  7486. {
  7487. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7488. {
  7489. tempIndex = 2;
  7490. }
  7491. else
  7492. {
  7493. tempIndex = connectorIdInt -1;
  7494. }
  7495. for (int index = 0; index < AC_QUANTITY; index++)
  7496. {
  7497. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7498. {
  7499. 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))
  7500. {
  7501. //Reserved
  7502. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7503. }
  7504. 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))
  7505. {
  7506. //Reserved
  7507. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7508. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7509. goto end;
  7510. }
  7511. else
  7512. {
  7513. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7514. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7515. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7516. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7517. {
  7518. DEBUG_WARN("AC connector not allow start\n.");
  7519. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7520. goto end;
  7521. }
  7522. }//END FOR ELSE
  7523. }
  7524. }// END FOR AC_QUANTITY
  7525. }
  7526. if(chargingProfileIsNULL == FALSE)
  7527. {
  7528. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7529. {
  7530. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7531. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7532. //memset idTag
  7533. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7534. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7535. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7536. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7537. // Save profile to file
  7538. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7539. system(cmdBuf);
  7540. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7541. fp = fopen(cmdBuf, "w");
  7542. 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));
  7543. fclose(fp);
  7544. }
  7545. else
  7546. {
  7547. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  7548. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7549. }
  7550. }
  7551. else
  7552. {
  7553. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7554. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7555. //memset idTag
  7556. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7557. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7558. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7559. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7560. }
  7561. }
  7562. else
  7563. {
  7564. DEBUG_WARN("Connector id over\n.");
  7565. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7566. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7567. }
  7568. end:
  7569. json_object_put(RemoteStartTransaction);
  7570. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  7571. {
  7572. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7573. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7574. }
  7575. //OCPP send RemoteStartConfirmation by first.
  7576. sendRemoteStartConfirmation(uuid, comfirmstr);
  7577. return result;
  7578. }
  7579. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7580. {
  7581. mtrace();
  7582. int result = FAIL;
  7583. int match = FALSE;
  7584. int GunNO = 0;
  7585. int tempIndex = 0;
  7586. int transactionIdInt=0;
  7587. int transactionIdIsNULL= TRUE;
  7588. char comfirmstr[20];
  7589. json_object *RemoteStopTransaction;
  7590. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7591. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7592. if(server_pending == TRUE)
  7593. {
  7594. return 0;
  7595. }
  7596. RemoteStopTransaction = json_tokener_parse(payload);
  7597. if(!is_error(RemoteStopTransaction))
  7598. {
  7599. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  7600. {
  7601. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  7602. transactionIdIsNULL = FALSE;
  7603. }
  7604. }
  7605. json_object_put(RemoteStopTransaction);
  7606. if(transactionIdIsNULL == FALSE)
  7607. {
  7608. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7609. {
  7610. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7611. {
  7612. //check Transaction active
  7613. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7614. {
  7615. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7616. {
  7617. tempIndex = ((gun_index==2) ? 1: 0);
  7618. }
  7619. else
  7620. {
  7621. tempIndex = gun_index;
  7622. }
  7623. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7624. {
  7625. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7626. {
  7627. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7628. {
  7629. match = TRUE;
  7630. GunNO = gun_index;
  7631. }
  7632. }
  7633. }// END FOR CHAdeMO_QUANTITY
  7634. }
  7635. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7636. {
  7637. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7638. {
  7639. tempIndex = ((gun_index==2) ? 1: 0);
  7640. }
  7641. else
  7642. {
  7643. tempIndex = gun_index;
  7644. }
  7645. for (int index = 0; index < CCS_QUANTITY; index++)
  7646. {
  7647. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7648. {
  7649. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7650. {
  7651. match = TRUE;
  7652. GunNO = gun_index;
  7653. }
  7654. }
  7655. }// END FOR CCS_QUANTITY
  7656. }
  7657. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7658. {
  7659. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7660. {
  7661. tempIndex = ((gun_index==2) ? 1: 0);
  7662. }
  7663. else
  7664. {
  7665. tempIndex = gun_index;
  7666. }
  7667. for (int index = 0; index < GB_QUANTITY; index++)
  7668. {
  7669. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7670. {
  7671. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7672. {
  7673. match = TRUE;
  7674. GunNO = gun_index;
  7675. }
  7676. }
  7677. }// END FOR GB_QUANTITY
  7678. }
  7679. else if(gunType[gun_index] == GUN_TYPE_DO)
  7680. {
  7681. tempIndex = gun_index;
  7682. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7683. {
  7684. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7685. {
  7686. 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
  7687. {
  7688. match = TRUE;
  7689. GunNO = gun_index;
  7690. }
  7691. }
  7692. }// END FOR GB_QUANTITY
  7693. }
  7694. else
  7695. {
  7696. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7697. {
  7698. tempIndex = 2;
  7699. }
  7700. else
  7701. {
  7702. tempIndex = gun_index;
  7703. }
  7704. for (int index = 0; index < AC_QUANTITY; index++)
  7705. {
  7706. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7707. {
  7708. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7709. {
  7710. match = TRUE;
  7711. GunNO = gun_index;
  7712. }
  7713. }
  7714. }// END FOR CHAdeMO_QUANTITY
  7715. } // END FOR AC ELSE
  7716. }// CHECK IF ResponseTransactionId == transactionIdInt
  7717. }//END FOR
  7718. if( match == TRUE)
  7719. {
  7720. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7721. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7722. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7723. }
  7724. else
  7725. {
  7726. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7727. }
  7728. }
  7729. else
  7730. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7731. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7732. return result;
  7733. }
  7734. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7735. {
  7736. mtrace();
  7737. int result = FAIL;
  7738. int connectorIdInt=0, reservationIdInt=0;
  7739. int tempIndex = 0;
  7740. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7741. char comfirmstr[20]={0};
  7742. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7743. int c = 0;
  7744. char *loc;
  7745. //char *ptr;
  7746. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  7747. strcpy(sstrtemp, stringtrimspace(payload));
  7748. //***(1)connectorId ****/
  7749. c=0;
  7750. loc = strstr(sstrtemp, "connectorId");
  7751. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7752. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7753. {
  7754. sstr[c] = loc[strlen("connectorId")+2+c];
  7755. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7756. c++;
  7757. }
  7758. sstr[c] = '\0';
  7759. connectorIdInt = atoi(sstr);
  7760. //***(2)expiryDate ****/
  7761. loc = strstr(sstrtemp, "expiryDate");
  7762. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7763. c = 0;
  7764. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7765. {
  7766. sstr[c] = loc[3+strlen("expiryDate")+c];
  7767. c++;
  7768. }
  7769. sstr[c] = '\0';
  7770. strcpy(expiryDatestr, sstr);
  7771. //***(3)idTag ****/
  7772. loc = strstr(sstrtemp, "idTag");
  7773. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7774. c = 0;
  7775. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7776. {
  7777. sstr[c] = loc[3+strlen("idTag")+c];
  7778. c++;
  7779. }
  7780. sstr[c] = '\0';
  7781. strcpy(idTagstr, sstr);
  7782. //***(4)parentIdTag ****/
  7783. loc = strstr(sstrtemp, "parentIdTag");
  7784. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7785. c = 0;
  7786. if(loc == NULL)
  7787. {
  7788. strcpy(parentIdTagstr, "");
  7789. }
  7790. else
  7791. {
  7792. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7793. {
  7794. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7795. c++;
  7796. }
  7797. sstr[c] = '\0';
  7798. strcpy(parentIdTagstr, sstr);
  7799. }
  7800. //***(5)reservationId ****/
  7801. c=0;
  7802. loc = strstr(sstrtemp, "reservationId");
  7803. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7804. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7805. {
  7806. sstr[c] = loc[strlen("reservationId")+2+c];
  7807. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7808. c++;
  7809. }
  7810. sstr[c] = '\0';
  7811. reservationIdInt = atoi(sstr);
  7812. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7813. /*
  7814. enum SYSTEM_STATUS
  7815. {
  7816. SYS_MODE_BOOTING = 0,
  7817. SYS_MODE_IDLE = 1,
  7818. SYS_MODE_AUTHORIZING = 2,
  7819. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7820. SYS_MODE_REASSIGN = 4,
  7821. SYS_MODE_PREPARING = 5,
  7822. SYS_MODE_PREPARE_FOR_EV = 6,
  7823. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7824. SYS_MODE_CHARGING = 8,
  7825. SYS_MODE_TERMINATING = 9,
  7826. SYS_MODE_COMPLETE = 10,
  7827. SYS_MODE_ALARM = 11,
  7828. SYS_MODE_FAULT = 12,
  7829. SYS_MODE_RESERVATION = 13,
  7830. SYS_MODE_BOOKING = 14,
  7831. SYS_MODE_MAINTAIN = 15,
  7832. SYS_MODE_DEBUG = 16,
  7833. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7834. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7835. SYS_MODE_UPDATE = 19
  7836. };
  7837. */
  7838. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7839. {
  7840. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7841. goto end;
  7842. }
  7843. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7844. {
  7845. //check Transaction active
  7846. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  7847. {
  7848. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7849. {
  7850. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7851. }
  7852. else
  7853. {
  7854. tempIndex = connectorIdInt -1;
  7855. }
  7856. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7857. {
  7858. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7859. {
  7860. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7861. {
  7862. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7863. {
  7864. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7865. {
  7866. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7867. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7868. }
  7869. 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'))
  7870. {
  7871. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7872. }
  7873. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7874. {
  7875. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7876. }
  7877. else
  7878. {
  7879. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7880. }
  7881. }
  7882. 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
  7883. {
  7884. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7885. }
  7886. }
  7887. else
  7888. {
  7889. //replace reservation
  7890. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7891. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7892. }
  7893. }
  7894. } // END FOR CHAdeMO_QUANTITY
  7895. }
  7896. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  7897. {
  7898. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7899. {
  7900. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7901. }
  7902. else
  7903. {
  7904. tempIndex = connectorIdInt -1;
  7905. }
  7906. for (int index = 0; index < CCS_QUANTITY; index++)
  7907. {
  7908. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7909. {
  7910. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7911. {
  7912. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7913. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7914. {
  7915. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7916. {
  7917. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7918. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7919. }
  7920. 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'))
  7921. {
  7922. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7923. }
  7924. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7925. {
  7926. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7927. }
  7928. else
  7929. {
  7930. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7931. }
  7932. }
  7933. 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
  7934. {
  7935. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7936. }
  7937. }
  7938. else
  7939. {
  7940. //replace reservation
  7941. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7942. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7943. }
  7944. }
  7945. } // END FOR CCS_QUANTITY
  7946. }
  7947. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  7948. {
  7949. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7950. {
  7951. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7952. }
  7953. else
  7954. {
  7955. tempIndex = connectorIdInt -1;
  7956. }
  7957. for (int index = 0; index < GB_QUANTITY; index++)
  7958. {
  7959. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7960. {
  7961. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7962. {
  7963. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7964. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7965. {
  7966. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7967. {
  7968. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7969. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7970. }
  7971. 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'))
  7972. {
  7973. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7974. }
  7975. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7976. {
  7977. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7978. }
  7979. else
  7980. {
  7981. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7982. }
  7983. }
  7984. 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
  7985. {
  7986. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7987. }
  7988. }
  7989. else
  7990. {
  7991. //replace reservation
  7992. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7993. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7994. }
  7995. }
  7996. }// END FOR GB_QUANTITY
  7997. }
  7998. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  7999. {
  8000. tempIndex = connectorIdInt -1;
  8001. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8002. {
  8003. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8004. {
  8005. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  8006. {
  8007. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8008. 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
  8009. {
  8010. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8011. {
  8012. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8013. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8014. }
  8015. 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'))
  8016. {
  8017. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8018. }
  8019. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8020. {
  8021. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8022. }
  8023. else
  8024. {
  8025. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8026. }
  8027. }
  8028. 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
  8029. {
  8030. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8031. }
  8032. }
  8033. else
  8034. {
  8035. //replace reservation
  8036. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8037. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8038. }
  8039. }
  8040. }// END FOR GB_QUANTITY
  8041. }
  8042. else
  8043. {
  8044. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8045. {
  8046. tempIndex = 2;
  8047. }
  8048. else
  8049. {
  8050. tempIndex = (connectorIdInt -1);
  8051. }
  8052. for (int index = 0; index < AC_QUANTITY; index++)
  8053. {
  8054. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8055. {
  8056. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8057. {
  8058. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8059. {
  8060. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8061. {
  8062. 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))
  8063. {
  8064. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8065. }
  8066. else
  8067. {
  8068. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8069. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8070. }
  8071. }
  8072. 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'))
  8073. {
  8074. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8075. }
  8076. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8077. {
  8078. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8079. }
  8080. else
  8081. {
  8082. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8083. }
  8084. }
  8085. 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
  8086. {
  8087. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8088. }
  8089. }
  8090. else
  8091. {
  8092. //replace reservation
  8093. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8094. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8095. }
  8096. }
  8097. } // END FOR AC_QUANTITY
  8098. }
  8099. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8100. }
  8101. else if(connectorIdInt == 0)
  8102. {
  8103. //check Transaction active
  8104. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8105. {
  8106. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8107. {
  8108. 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'))
  8109. {
  8110. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8111. goto end;
  8112. }
  8113. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8114. {
  8115. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8116. goto end;
  8117. }
  8118. 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
  8119. {
  8120. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8121. goto end;
  8122. }
  8123. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8124. {
  8125. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8126. goto end;
  8127. }
  8128. }
  8129. }// END FOR CHAdeMO_QUANTITY
  8130. for (int index = 0; index < CCS_QUANTITY; index++)
  8131. {
  8132. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8133. {
  8134. 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'))
  8135. {
  8136. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8137. goto end;
  8138. }
  8139. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  8140. {
  8141. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8142. goto end;
  8143. }
  8144. 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
  8145. {
  8146. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8147. goto end;
  8148. }
  8149. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8150. {
  8151. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8152. goto end;
  8153. }
  8154. }
  8155. } // END FOR CCS_QUANTITY
  8156. for (int index = 0; index < GB_QUANTITY; index++)
  8157. {
  8158. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8159. {
  8160. 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'))
  8161. {
  8162. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8163. goto end;
  8164. }
  8165. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8166. {
  8167. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8168. goto end;
  8169. }
  8170. 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
  8171. {
  8172. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8173. goto end;
  8174. }
  8175. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8176. {
  8177. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8178. goto end;
  8179. }
  8180. }
  8181. } // END FOR GB_QUANTITY
  8182. for (int index = 0; index < AC_QUANTITY; index++)
  8183. {
  8184. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8185. {
  8186. 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'))
  8187. {
  8188. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8189. goto end;
  8190. }
  8191. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8192. {
  8193. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8194. goto end;
  8195. }
  8196. 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
  8197. {
  8198. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8199. goto end;
  8200. }
  8201. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8202. {
  8203. 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))
  8204. {
  8205. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8206. goto end;
  8207. }
  8208. }
  8209. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8210. {
  8211. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8212. goto end;
  8213. }
  8214. }
  8215. }// END FOR AC_QUANTITY
  8216. //The connectorId is 0
  8217. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  8218. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8219. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  8220. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  8221. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  8222. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  8223. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  8224. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  8225. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  8226. result = TRUE;
  8227. return result;
  8228. }
  8229. else
  8230. {
  8231. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8232. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8233. }
  8234. if(strcmp(comfirmstr,"Accepted") == 0)
  8235. {
  8236. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  8237. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  8238. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  8239. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  8240. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  8241. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  8242. result = TRUE;
  8243. return result;
  8244. }
  8245. end:
  8246. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  8247. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  8248. return result;
  8249. }
  8250. int handleResetRequest(char *uuid, char *payload)
  8251. {
  8252. mtrace();
  8253. int result = FAIL;
  8254. char sstr[10]={0},sstrtemp[30]={ 0 };
  8255. char typestr[10]={0};
  8256. char comfirmstr[20]={0};
  8257. int c = 0;
  8258. char *loc;
  8259. DEBUG_INFO("handleResetRequest...\n");
  8260. strcpy(sstrtemp, stringtrimspace(payload));
  8261. loc = strstr(sstrtemp, "type");
  8262. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8263. c = 0;
  8264. while (loc[3+strlen("type")+c] != '\"')
  8265. {
  8266. sstr[c] = loc[3+strlen("type")+c];
  8267. c++;
  8268. }
  8269. sstr[c] = '\0';
  8270. strcpy(typestr,sstr);
  8271. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  8272. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  8273. {
  8274. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  8275. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  8276. result = TRUE;
  8277. return result;
  8278. }
  8279. else
  8280. {
  8281. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  8282. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  8283. goto errorend;
  8284. }
  8285. errorend:
  8286. sendResetConfirmation(uuid, comfirmstr);
  8287. return result;
  8288. }
  8289. int handleSendLocalListRequest(char *uuid, char *payload)
  8290. {
  8291. mtrace();
  8292. int result = FAIL;
  8293. int listVersionInt;
  8294. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  8295. char listsearch[]="listVersion";
  8296. char updateTypesearch[]="updateType";
  8297. char localAuthorizationListsearch[]="localAuthorizationList";
  8298. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  8299. char CardList[500][160]={0};
  8300. char updateTypestr[15]={0};
  8301. char idTagstr[20]={0};
  8302. char parentIdTag[20]={0};
  8303. char expiryDate[30]={0};
  8304. char idTagstatus[16]={0};
  8305. int c = 0;
  8306. int i = 0;
  8307. char *delim1 = "}";
  8308. char * pch;
  8309. char *loc;
  8310. //char *ptr;
  8311. char comfirmstr[20];
  8312. //int n_localAuthorizations = 0;
  8313. int checkState_Faulted = FALSE;
  8314. DEBUG_INFO("handleSendLocalListRequest...\n");
  8315. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  8316. {
  8317. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8318. goto end;
  8319. }
  8320. //check Charge Point state
  8321. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8322. {
  8323. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8324. {
  8325. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8326. }
  8327. }
  8328. for (int index = 0; index < CCS_QUANTITY; index++)
  8329. {
  8330. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8331. {
  8332. checkState_Faulted = TRUE; //OCPP Status
  8333. }
  8334. }
  8335. for (int index = 0; index < GB_QUANTITY; index++)
  8336. {
  8337. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8338. {
  8339. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8340. }
  8341. }
  8342. //check Charge Point state
  8343. for (int index = 0; index < AC_QUANTITY; index++)
  8344. {
  8345. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8346. {
  8347. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8348. }
  8349. }
  8350. if(checkState_Faulted == TRUE)
  8351. {
  8352. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8353. goto end;
  8354. }
  8355. //Filter payload space
  8356. strcpy(sstrtemp, stringtrimspace(payload));
  8357. //listVersion
  8358. c = 0;
  8359. loc = strstr(sstrtemp, listsearch);
  8360. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  8361. {
  8362. sstr[c] = loc[strlen("listVersion")+2+c];
  8363. c++;
  8364. }
  8365. sstr[c] = '\0';
  8366. listVersionInt = atoi(sstr);
  8367. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8368. //updateType
  8369. loc = strstr(sstrtemp, updateTypesearch);
  8370. c = 0;
  8371. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  8372. {
  8373. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  8374. c++;
  8375. }
  8376. sstr[c] = '\0';
  8377. strcpy(updateTypestr, sstr);
  8378. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  8379. //localAuthorizationList
  8380. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8381. loc = strstr(sstrtemp, localAuthorizationListsearch);
  8382. if(loc != NULL) // localAuthorizationList is not NULL
  8383. {
  8384. //Check UpdateType
  8385. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8386. {
  8387. //Local list full update
  8388. printf("Local list full update.\n");
  8389. OCPP_getListVerion();
  8390. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8391. {
  8392. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8393. goto end;
  8394. }
  8395. OCPP_cleanLocalList();
  8396. }
  8397. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8398. {
  8399. //Local list different update
  8400. printf("Local list different update.\n");
  8401. OCPP_getListVerion();
  8402. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8403. {
  8404. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  8405. goto end;
  8406. }
  8407. }
  8408. else
  8409. {
  8410. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8411. goto end;
  8412. }
  8413. c = 0;
  8414. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  8415. {
  8416. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  8417. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8418. c++;
  8419. }
  8420. sstr[c] = '\0';
  8421. //DEBUG_INFO("sstr=%s\n", sstr);
  8422. //parsing strings to words
  8423. i = 0;
  8424. pch = strtok(sstr,delim1);
  8425. while (pch != NULL)
  8426. {
  8427. strcpy(CardList[i], pch);
  8428. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  8429. pch = strtok (NULL, delim1);
  8430. i = i + 1;
  8431. }
  8432. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  8433. //local Authorizations List Numbers
  8434. //n_localAuthorizations = i;
  8435. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8436. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  8437. c= 0;
  8438. while(c < i) // i is CardList Number
  8439. {
  8440. //Search "IdToken"
  8441. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8442. loc = strstr(CardList[c], "idTag");
  8443. int j = 0;
  8444. while (loc[3+strlen("idTag")+j] != '\"')
  8445. {
  8446. sstr[j] = loc[3+strlen("idTag")+j];
  8447. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8448. j++;
  8449. }
  8450. sstr[j] = '\0';
  8451. strcpy(idTagstr, sstr);
  8452. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  8453. //Search "expiryDate"
  8454. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8455. loc = strstr(CardList[c], "expiryDate");
  8456. j = 0;
  8457. if(loc != NULL)
  8458. {
  8459. while (loc[3+strlen("expiryDate")+j] != '\"')
  8460. {
  8461. sstr[j] = loc[3+strlen("expiryDate")+j];
  8462. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8463. j++;
  8464. }
  8465. sstr[j] = '\0';
  8466. strcpy(expiryDate, sstr);
  8467. }
  8468. else
  8469. {
  8470. strcpy(expiryDate, "");
  8471. }
  8472. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  8473. //Search "parentIdTag"
  8474. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8475. loc = strstr(CardList[c], "parentIdTag");
  8476. j = 0;
  8477. if(loc != NULL)
  8478. {
  8479. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8480. {
  8481. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8482. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8483. j++;
  8484. }
  8485. sstr[j] = '\0';
  8486. strcpy(parentIdTag, sstr);
  8487. }
  8488. else
  8489. {
  8490. strcpy(parentIdTag, "");
  8491. }
  8492. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8493. //Search "status"
  8494. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8495. loc = strstr(CardList[c], "status");
  8496. j = 0;
  8497. while (loc[3+strlen("status")+j] != '\"')
  8498. {
  8499. sstr[j] = loc[3+strlen("status")+j];
  8500. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8501. j++;
  8502. }
  8503. sstr[j] = '\0';
  8504. strcpy(idTagstatus, sstr);
  8505. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8506. OCPP_getIdTagFromLocalList(idTagstr);
  8507. //OCPP_getIdTagFromLocalList("test"); For Test
  8508. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8509. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8510. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8511. {
  8512. //Local list full update
  8513. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8514. // update list
  8515. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8516. //DEBUG_INFO("Local list full update. 1\n");
  8517. //OCPP_get_TableAuthlocalAllData();
  8518. //DEBUG_INFO("Local list full update. 2\n");
  8519. }
  8520. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8521. {
  8522. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8523. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8524. }
  8525. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8526. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8527. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8528. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8529. c++;
  8530. }
  8531. }
  8532. else
  8533. {
  8534. //Check UpdateType
  8535. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8536. {
  8537. //Local list full update
  8538. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8539. OCPP_cleanLocalList();
  8540. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8541. goto end;
  8542. }
  8543. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8544. {
  8545. //Local list different update
  8546. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8547. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8548. goto end;
  8549. }
  8550. }
  8551. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8552. end:
  8553. sendSendLocalListConfirmation(uuid, comfirmstr);
  8554. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8555. return result;
  8556. }
  8557. #define MAX 200
  8558. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8559. {
  8560. mtrace();
  8561. int result = FAIL;
  8562. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8563. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8564. char chargingProfilePurposeStr[30]={0};
  8565. char chargingProfileKindStr[16]={0};
  8566. char recurrencyKindStr[10]={0};
  8567. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8568. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8569. int chargingSchedulePeriodCount = 0;
  8570. char comfirmstr[20]={0};
  8571. int meet= FALSE;
  8572. FILE *fptr1;
  8573. char filename[MAX]={0};
  8574. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8575. char rmFileCmd[50]={0};
  8576. char tempchargingProfilePurposeStr[30]={0};
  8577. char word[1600]={0};
  8578. int n_chargingProfile = 0;
  8579. json_object *SetChargingProfile;
  8580. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8581. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8582. SetChargingProfile = json_tokener_parse(payload);
  8583. if(!is_error(SetChargingProfile))
  8584. {
  8585. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  8586. {
  8587. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  8588. if(connectorIdInt == 0)
  8589. {
  8590. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  8591. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8592. }
  8593. else
  8594. {
  8595. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  8596. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  8597. }
  8598. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  8599. }
  8600. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  8601. {
  8602. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  8603. {
  8604. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  8605. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8606. {
  8607. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8608. }
  8609. else
  8610. {
  8611. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8612. }
  8613. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  8614. }
  8615. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  8616. {
  8617. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  8618. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8619. {
  8620. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8621. }
  8622. else
  8623. {
  8624. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8625. }
  8626. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  8627. }
  8628. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8629. {
  8630. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  8631. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8632. {
  8633. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8634. }
  8635. else
  8636. {
  8637. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8638. }
  8639. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  8640. }
  8641. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  8642. {
  8643. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  8644. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8645. {
  8646. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8647. }
  8648. else
  8649. {
  8650. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8651. }
  8652. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  8653. }
  8654. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  8655. {
  8656. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  8657. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8658. {
  8659. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  8660. }
  8661. else
  8662. {
  8663. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  8664. }
  8665. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  8666. }
  8667. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  8668. {
  8669. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  8670. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8671. {
  8672. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8673. }
  8674. else
  8675. {
  8676. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8677. }
  8678. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  8679. }
  8680. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  8681. {
  8682. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  8683. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8684. {
  8685. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8686. }
  8687. else
  8688. {
  8689. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8690. }
  8691. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  8692. }
  8693. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  8694. {
  8695. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  8696. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8697. {
  8698. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8699. }
  8700. else
  8701. {
  8702. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8703. }
  8704. //DEBUG_INFO("validToStr: %s\n", validToStr);
  8705. }
  8706. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  8707. {
  8708. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  8709. {
  8710. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  8711. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8712. {
  8713. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8714. }
  8715. else
  8716. {
  8717. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8718. }
  8719. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  8720. }
  8721. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  8722. {
  8723. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  8724. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8725. {
  8726. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8727. }
  8728. else
  8729. {
  8730. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8731. }
  8732. //DEBUG_INFO("durationInt: %d\n", durationInt);
  8733. }
  8734. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  8735. {
  8736. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  8737. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8738. {
  8739. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8740. }
  8741. else
  8742. {
  8743. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8744. }
  8745. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  8746. }
  8747. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  8748. {
  8749. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  8750. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8751. {
  8752. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8753. }
  8754. else
  8755. {
  8756. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8757. }
  8758. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  8759. }
  8760. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  8761. {
  8762. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  8763. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  8764. if(chargingSchedulePeriodCount <= 10)
  8765. {
  8766. 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++)
  8767. {
  8768. 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)
  8769. {
  8770. 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"));
  8771. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8772. {
  8773. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  8774. }
  8775. else
  8776. {
  8777. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  8778. }
  8779. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  8780. }
  8781. 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)
  8782. {
  8783. 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"));
  8784. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8785. {
  8786. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  8787. }
  8788. else
  8789. {
  8790. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  8791. }
  8792. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  8793. }
  8794. 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)
  8795. {
  8796. 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"));
  8797. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8798. {
  8799. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  8800. }
  8801. else
  8802. {
  8803. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  8804. }
  8805. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  8806. }
  8807. }
  8808. }
  8809. }
  8810. }
  8811. }
  8812. }
  8813. json_object_put(SetChargingProfile);
  8814. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8815. {
  8816. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8817. goto end;
  8818. }
  8819. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8820. {
  8821. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8822. if(connectorIdInt != 0)
  8823. {
  8824. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8825. goto end;
  8826. }
  8827. strcpy(filename, ChargePointMaxProfile_JSON );
  8828. fptr1 = fopen(filename, "r");
  8829. if (!fptr1)
  8830. {
  8831. //file not exist
  8832. DEBUG_INFO("Unable to open the input file!!\n");
  8833. fptr1 = fopen(filename, "w+");
  8834. }
  8835. else
  8836. {
  8837. //Check Charging Profile Count
  8838. while(fscanf(fptr1, "%s", word) != EOF)
  8839. {
  8840. //DEBUG_INFO("word=%s\n",word);
  8841. if(strstr(word, "chargingProfileId")!= NULL)
  8842. {
  8843. //DEBUG_INFO("test chargingProfileId \n");
  8844. n_chargingProfile = n_chargingProfile + 1;
  8845. //DEBUG_INFO("chargingProfileId Found\n");
  8846. }
  8847. }
  8848. }
  8849. fclose(fptr1);
  8850. }
  8851. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8852. {
  8853. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8854. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8855. {
  8856. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8857. goto end;
  8858. }
  8859. memset(filename, 0, ARRAY_SIZE(filename));
  8860. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8861. fptr1 = fopen(filename, "r");
  8862. if (!fptr1)
  8863. {
  8864. //file not exist
  8865. //DEBUG_INFO("Unable to open the input file!!\n");
  8866. fptr1 = fopen(filename, "w+");
  8867. }
  8868. else
  8869. {
  8870. //Check Charging Profile Count
  8871. while(fscanf(fptr1, "%s", word) != EOF)
  8872. {
  8873. //DEBUG_INFO("word=%s\n",word);
  8874. if(strstr(word, "chargingProfileId")!= NULL)
  8875. {
  8876. //DEBUG_INFO("test chargingProfileId \n");
  8877. n_chargingProfile = n_chargingProfile + 1;
  8878. //DEBUG_INFO("chargingProfileId Found\n");
  8879. }
  8880. }
  8881. }
  8882. fclose(fptr1);
  8883. }
  8884. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8885. {
  8886. //printf("set chargingProfile 1-4\n");
  8887. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8888. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  8889. if(connectorIdInt == 0)
  8890. {
  8891. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8892. goto end;
  8893. }
  8894. int tempIndex = 0;
  8895. //check Transaction active
  8896. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8897. {
  8898. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8899. {
  8900. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8901. }
  8902. else
  8903. {
  8904. tempIndex = connectorIdInt -1;
  8905. }
  8906. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8907. {
  8908. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8909. {
  8910. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8911. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  8912. {
  8913. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8914. {
  8915. meet = TRUE;
  8916. break;
  8917. }
  8918. }
  8919. }
  8920. }
  8921. }
  8922. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8923. {
  8924. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8925. {
  8926. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8927. }
  8928. else
  8929. {
  8930. tempIndex = connectorIdInt -1;
  8931. }
  8932. for (int index = 0; index < CCS_QUANTITY; index++)
  8933. {
  8934. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8935. {
  8936. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8937. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  8938. {
  8939. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8940. {
  8941. meet = TRUE;
  8942. break;
  8943. }
  8944. }
  8945. }
  8946. }
  8947. }
  8948. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8949. {
  8950. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8951. {
  8952. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8953. }
  8954. else
  8955. {
  8956. tempIndex = connectorIdInt -1;
  8957. }
  8958. for (int index = 0; index < GB_QUANTITY; index++)
  8959. {
  8960. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8961. {
  8962. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8963. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  8964. {
  8965. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8966. {
  8967. meet = TRUE;
  8968. break;
  8969. }
  8970. }
  8971. }
  8972. }
  8973. }
  8974. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8975. {
  8976. tempIndex = connectorIdInt -1;
  8977. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8978. {
  8979. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8980. {
  8981. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8982. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  8983. {
  8984. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8985. {
  8986. meet = TRUE;
  8987. break;
  8988. }
  8989. }
  8990. }
  8991. }
  8992. }
  8993. else
  8994. {
  8995. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8996. {
  8997. tempIndex = 2;
  8998. }
  8999. else
  9000. {
  9001. tempIndex = (connectorIdInt -1);
  9002. }
  9003. for (int index = 0; index < AC_QUANTITY; index++)
  9004. {
  9005. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9006. {
  9007. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9008. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9009. {
  9010. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9011. {
  9012. meet = TRUE;
  9013. break;
  9014. }
  9015. }
  9016. }
  9017. }
  9018. }
  9019. //check Transaction active
  9020. if(meet == FALSE)
  9021. {
  9022. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9023. goto end;
  9024. }
  9025. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9026. {
  9027. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9028. goto end;
  9029. }
  9030. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9031. fptr1 = fopen(filename, "r");
  9032. if (!fptr1)
  9033. {
  9034. //file not exist
  9035. DEBUG_INFO("Unable to open the input file!!\n");
  9036. fptr1 = fopen(filename, "w+");
  9037. }
  9038. else
  9039. {
  9040. //Check Charging Profile Count
  9041. while(fscanf(fptr1, "%s", word) != EOF)
  9042. {
  9043. //DEBUG_INFO("word=%s\n",word);
  9044. if(strstr(word, "chargingProfileId")!= NULL)
  9045. {
  9046. //DEBUG_INFO("test chargingProfileId \n");
  9047. n_chargingProfile = n_chargingProfile + 1;
  9048. //DEBUG_INFO("chargingProfileId Found\n");
  9049. }
  9050. }
  9051. }
  9052. fclose(fptr1);
  9053. }
  9054. // Check ChargeProfileMaxStackLevel
  9055. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  9056. {
  9057. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9058. goto end;
  9059. }
  9060. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9061. {
  9062. int i = 0;
  9063. char fnametemp[200]={0};
  9064. n_chargingProfile = 0;
  9065. //Check ChargePointMaxProfile.json exit
  9066. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9067. {
  9068. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  9069. //Check Charging Profile Count
  9070. while(fscanf(fptr1, "%s", word) != EOF)
  9071. {
  9072. //DEBUG_INFO("word=%s\n",word);
  9073. if(strstr(word, "chargingProfileId")!= NULL)
  9074. {
  9075. //DEBUG_INFO("test chargingProfileId \n");
  9076. n_chargingProfile = n_chargingProfile + 1;
  9077. i = i + 1;
  9078. //DEBUG_INFO("chargingProfileId Found\n");
  9079. }
  9080. memset(word, 0, ARRAY_SIZE(word));
  9081. }
  9082. fclose(fptr1);
  9083. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  9084. }
  9085. //Check TxDefaultProfile_0.json exit
  9086. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9087. {
  9088. i = 0;
  9089. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  9090. //Check Charging Profile Count
  9091. while(fscanf(fptr1, "%s", word) != EOF)
  9092. {
  9093. //DEBUG_INFO("word=%s\n",word);
  9094. if(strstr(word, "chargingProfileId")!= NULL)
  9095. {
  9096. //DEBUG_INFO("test chargingProfileId \n");
  9097. n_chargingProfile = n_chargingProfile + 1;
  9098. i = i + 1;
  9099. //DEBUG_INFO("chargingProfileId Found\n");
  9100. }
  9101. memset(word, 0, ARRAY_SIZE(word));
  9102. }
  9103. fclose(fptr1);
  9104. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  9105. }
  9106. //Check TxDefaultProfile_%d.json
  9107. for(int j=1; j <= gunTotalNumber; j++)
  9108. {
  9109. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9110. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9111. if((access(fnametemp,F_OK))!=-1)
  9112. {
  9113. i = 0;
  9114. fptr1 = fopen(fnametemp, "r");
  9115. //Check Charging Profile Count
  9116. while(fscanf(fptr1, "%s", word) != EOF)
  9117. {
  9118. //DEBUG_INFO("word=%s\n",word);
  9119. if(strstr(word, "chargingProfileId")!= NULL)
  9120. {
  9121. //DEBUG_INFO("test chargingProfileId \n");
  9122. n_chargingProfile = n_chargingProfile + 1;
  9123. i = i + 1;
  9124. //DEBUG_INFO("chargingProfileId Found\n");
  9125. }
  9126. memset(word, 0, ARRAY_SIZE(word));
  9127. }
  9128. fclose(fptr1);
  9129. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9130. }
  9131. }
  9132. //Check TxProfile_%d.json
  9133. for(int j=1; j <= gunTotalNumber; j++)
  9134. {
  9135. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9136. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9137. if((access(fnametemp,F_OK))!=-1)
  9138. {
  9139. i = 0;
  9140. fptr1 = fopen(fnametemp, "r");
  9141. //Check Charging Profile Count
  9142. while(fscanf(fptr1, "%s", word) != EOF)
  9143. {
  9144. //DEBUG_INFO("word=%s\n",word);
  9145. if(strstr(word, "chargingProfileId")!= NULL)
  9146. {
  9147. //DEBUG_INFO("test chargingProfileId \n");
  9148. n_chargingProfile = n_chargingProfile + 1;
  9149. i = i + 1;
  9150. //DEBUG_INFO("chargingProfileId Found\n");
  9151. }
  9152. memset(word, 0, ARRAY_SIZE(word));
  9153. }
  9154. fclose(fptr1);
  9155. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9156. }
  9157. }
  9158. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  9159. {
  9160. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9161. goto end;
  9162. }
  9163. }
  9164. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9165. //**********************************Write to File********************************************************/
  9166. FILE *infile;
  9167. FILE *outfile;
  9168. infile = fopen (filename, "r");
  9169. outfile = fopen (tempfile, "w");
  9170. int d =0;
  9171. d = fgetc(infile);
  9172. rewind(infile);
  9173. if(d == EOF)
  9174. {
  9175. // Profile is empty
  9176. fprintf(outfile,"%s\n",payload);
  9177. fclose(infile);
  9178. fclose(outfile);
  9179. sprintf(rmFileCmd,"rm -f %s",filename);
  9180. system(rmFileCmd);
  9181. rename(tempfile, filename);
  9182. }
  9183. else
  9184. {
  9185. // Profile is not empty
  9186. char buf[2048]={0};
  9187. int ChargingProfileAdded = FALSE;
  9188. while (fgets(buf, sizeof(buf), infile) != NULL)
  9189. {
  9190. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9191. json_object *tmpChargingProfile;
  9192. tmpChargingProfile = json_tokener_parse(buf);
  9193. if(!is_error(SetChargingProfile))
  9194. {
  9195. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  9196. {
  9197. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  9198. }
  9199. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  9200. {
  9201. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9202. {
  9203. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9204. }
  9205. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9206. {
  9207. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  9208. }
  9209. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9210. {
  9211. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9212. }
  9213. }
  9214. }
  9215. json_object_put(tmpChargingProfile);
  9216. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  9217. {
  9218. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9219. {
  9220. //DEBUG_INFO("update set chargingProfile to file -0\n");
  9221. if(ChargingProfileAdded == FALSE)
  9222. {
  9223. fprintf(outfile,"%s\n",payload);
  9224. ChargingProfileAdded = TRUE;
  9225. }
  9226. }
  9227. else
  9228. {
  9229. if(tempstackLevelInt < stackLevelInt)
  9230. {
  9231. if(ChargingProfileAdded == FALSE)
  9232. {
  9233. fprintf(outfile,"%s\n",buf);
  9234. fprintf(outfile,"%s\n",payload);
  9235. ChargingProfileAdded = TRUE;
  9236. }
  9237. else
  9238. {
  9239. fprintf(outfile,"%s\n",buf);
  9240. }
  9241. }
  9242. else
  9243. {
  9244. if(ChargingProfileAdded == FALSE)
  9245. {
  9246. fprintf(outfile,"%s\n",buf);
  9247. fprintf(outfile,"%s\n",payload);
  9248. ChargingProfileAdded = TRUE;
  9249. }
  9250. else
  9251. {
  9252. fprintf(outfile,"%s\n",buf);
  9253. }
  9254. }
  9255. }
  9256. }
  9257. else
  9258. {
  9259. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9260. {
  9261. if(ChargingProfileAdded == FALSE)
  9262. {
  9263. fprintf(outfile,"%s\n",buf);
  9264. fprintf(outfile,"%s\n",payload);
  9265. ChargingProfileAdded = TRUE;
  9266. }
  9267. else
  9268. {
  9269. fprintf(outfile,"%s\n",buf);
  9270. }
  9271. }
  9272. else if(tempstackLevelInt < stackLevelInt)
  9273. {
  9274. if(ChargingProfileAdded == FALSE)
  9275. {
  9276. fprintf(outfile,"%s\n",buf);
  9277. fprintf(outfile,"%s\n",payload);
  9278. ChargingProfileAdded = TRUE;
  9279. }
  9280. else
  9281. {
  9282. fprintf(outfile,"%s\n",buf);
  9283. }
  9284. }
  9285. else
  9286. {
  9287. if(ChargingProfileAdded == FALSE)
  9288. {
  9289. fprintf(outfile,"%s\n",buf);
  9290. fprintf(outfile,"%s\n",payload);
  9291. ChargingProfileAdded = TRUE;
  9292. }
  9293. else
  9294. {
  9295. fprintf(outfile,"%s\n",buf);
  9296. }
  9297. }
  9298. }
  9299. } // end of while loop
  9300. fclose(infile);
  9301. fclose(outfile);
  9302. sprintf(rmFileCmd,"rm -f %s",filename);
  9303. system(rmFileCmd);
  9304. rename(tempfile, filename);
  9305. }
  9306. sleep(1);
  9307. result = TRUE;
  9308. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9309. end:
  9310. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  9311. {
  9312. if(connectorIdInt == 0)
  9313. {
  9314. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9315. {
  9316. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9317. }
  9318. }
  9319. else
  9320. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9321. }
  9322. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  9323. return result;
  9324. }
  9325. int handleTriggerMessageRequest(char *uuid, char *payload)
  9326. {
  9327. mtrace();
  9328. int result = FAIL;
  9329. int connectorIdIsNULL = FALSE;
  9330. int connectorIdInt =0;
  9331. char sstr[40]={0},sstrtemp[100]={ 0 };
  9332. char requestedMessagestr[40]={0};
  9333. char comfirmstr[20]={0};
  9334. int c = 0;
  9335. char *loc;
  9336. DEBUG_INFO("handleTriggerMessageRequest\n");
  9337. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  9338. strcpy(sstrtemp, stringtrimspace(payload));
  9339. c = 0;
  9340. loc = strstr(sstrtemp, "requestedMessage");
  9341. while (loc[3+strlen("requestedMessage")+c] != '\"')
  9342. {
  9343. sstr[c] = loc[3+strlen("requestedMessage")+c];
  9344. c++;
  9345. }
  9346. sstr[c] = '\0';
  9347. strcpy(requestedMessagestr, sstr);
  9348. c = 0;
  9349. loc = strstr(sstrtemp, "connectorId");
  9350. if(loc == NULL)
  9351. {
  9352. connectorIdIsNULL = TRUE;
  9353. }
  9354. else
  9355. {
  9356. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9357. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  9358. {
  9359. sstr[c] = loc[strlen("connectorId")+2+c];
  9360. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9361. c++;
  9362. }
  9363. sstr[c] = '\0';
  9364. connectorIdInt = atoi(sstr);
  9365. }
  9366. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  9367. {
  9368. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  9369. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  9370. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  9371. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  9372. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  9373. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  9374. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  9375. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  9376. {
  9377. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  9378. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9379. return TRUE;
  9380. }
  9381. else
  9382. {
  9383. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9384. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9385. }
  9386. }
  9387. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  9388. {
  9389. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  9390. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9391. return TRUE;
  9392. }
  9393. //==========================
  9394. // Trigger message
  9395. //==========================
  9396. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  9397. {
  9398. if((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) &&
  9399. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) &&
  9400. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) &&
  9401. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING) )
  9402. {
  9403. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  9404. }
  9405. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  9406. }
  9407. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  9408. {
  9409. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  9410. }
  9411. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  9412. {
  9413. //sendBootNotificationRequest();
  9414. server_sign = FALSE;
  9415. }
  9416. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  9417. {
  9418. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  9419. }
  9420. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  9421. {
  9422. if(connectorIdIsNULL == FALSE)
  9423. {
  9424. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9425. {
  9426. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  9427. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  9428. }
  9429. }
  9430. else
  9431. {
  9432. for(int idx=0;idx< gunTotalNumber;idx++)
  9433. {
  9434. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  9435. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  9436. }
  9437. }
  9438. }
  9439. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  9440. {
  9441. if(connectorIdIsNULL == FALSE)
  9442. {
  9443. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9444. {
  9445. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  9446. }
  9447. }
  9448. else
  9449. {
  9450. for(int idx=0;idx< gunTotalNumber;idx++)
  9451. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  9452. }
  9453. }
  9454. return result;
  9455. }
  9456. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9457. {
  9458. mtrace();
  9459. int result = FAIL;
  9460. int connectorIdInt =0;
  9461. char comfirmstr[20]={0};
  9462. int tempIndex = 0;
  9463. json_object *UnlockConnector;
  9464. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9465. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9466. UnlockConnector = json_tokener_parse(payload);
  9467. if(!is_error(UnlockConnector))
  9468. {
  9469. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  9470. {
  9471. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  9472. }
  9473. }
  9474. json_object_put(UnlockConnector);
  9475. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  9476. if(gunTotalNumber == 0)
  9477. {
  9478. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9479. goto end;
  9480. }
  9481. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9482. {
  9483. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9484. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9485. goto end;
  9486. }
  9487. else
  9488. {
  9489. //check Transaction active
  9490. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  9491. {
  9492. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9493. {
  9494. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9495. }
  9496. else
  9497. {
  9498. tempIndex = connectorIdInt -1;
  9499. }
  9500. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9501. {
  9502. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9503. {
  9504. //stop Transaction
  9505. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9506. }
  9507. }
  9508. }
  9509. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  9510. {
  9511. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9512. {
  9513. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9514. }
  9515. else
  9516. {
  9517. tempIndex = connectorIdInt -1;
  9518. }
  9519. for (int index = 0; index < CCS_QUANTITY; index++)
  9520. {
  9521. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9522. {
  9523. //stop Transaction
  9524. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9525. }
  9526. }
  9527. }
  9528. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  9529. {
  9530. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9531. {
  9532. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9533. }
  9534. else
  9535. {
  9536. tempIndex = connectorIdInt -1;
  9537. }
  9538. for (int index = 0; index < GB_QUANTITY; index++)
  9539. {
  9540. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9541. {
  9542. //stop Transaction
  9543. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9544. }
  9545. }
  9546. }
  9547. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  9548. {
  9549. tempIndex = connectorIdInt -1;
  9550. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9551. {
  9552. 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)))
  9553. {
  9554. //stop Transaction
  9555. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9556. }
  9557. }
  9558. }
  9559. else
  9560. {
  9561. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9562. {
  9563. tempIndex = 2;
  9564. }
  9565. else
  9566. {
  9567. tempIndex = connectorIdInt-1;
  9568. }
  9569. for (int index = 0; index < AC_QUANTITY; index++)
  9570. {
  9571. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9572. {
  9573. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9574. }
  9575. }
  9576. }
  9577. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9578. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9579. result = TRUE;
  9580. return result;
  9581. }
  9582. end:
  9583. //json_object_put(obj); --- remove temporally
  9584. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9585. return result;
  9586. }
  9587. static char UpdateFirmwarepayloadData[300]={0};
  9588. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9589. {
  9590. mtrace();
  9591. int result = FAIL;
  9592. pthread_t t;
  9593. sendUpdateFirmwareConfirmation(uuid);
  9594. memset(UpdateFirmwarepayloadData, 0, 300);
  9595. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9596. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9597. ////pthread_join(t, NULL); //
  9598. //pthread_detach(t);
  9599. //sendUpdateFirmwareConfirmation(uuid);
  9600. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9601. return result;
  9602. }
  9603. void *UpdateFirmwareProcess(void *data)
  9604. {
  9605. pthread_detach(pthread_self());
  9606. mtrace();
  9607. int retriesInt =0, retryIntervalInt=0;
  9608. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9609. int port=0;
  9610. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9611. int isSuccess = 0;
  9612. char ftpbuf[200];
  9613. char temp[100];
  9614. char * pch;
  9615. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9616. json_object *UpdateFirmware;
  9617. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  9618. if(!is_error(UpdateFirmware))
  9619. {
  9620. // Required data
  9621. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  9622. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  9623. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  9624. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  9625. // Optional data
  9626. if(json_object_object_get(UpdateFirmware, "retries"))
  9627. {
  9628. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  9629. }
  9630. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  9631. {
  9632. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  9633. }
  9634. }
  9635. json_object_put(UpdateFirmware);
  9636. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9637. memset(path, 0, ARRAY_SIZE(path));
  9638. system("rm -f /mnt/*");
  9639. if(strncmp(locationstr,"http", 4) == 0)
  9640. {
  9641. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9642. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9643. // protocol, user, password, host, path);
  9644. sprintf(ftppath,"/%s", path);
  9645. DEBUG_INFO("locationstr: %s\n", locationstr);
  9646. DEBUG_INFO("protocol: %s\n",protocol);
  9647. DEBUG_INFO("host: %s\n",host);
  9648. DEBUG_INFO("path: %s\n",path);
  9649. DEBUG_INFO("ftppath: %s\n",ftppath);
  9650. int ftppathlen=strlen(ftppath);
  9651. int i=1;
  9652. char filenametemp[50];
  9653. while(i < ftppathlen)
  9654. {
  9655. int len=ftppathlen-i;
  9656. if(ftppath[len]== 47) // '/' ascll code: 47
  9657. {
  9658. DEBUG_INFO("compare '/' all right\n");
  9659. break;
  9660. }
  9661. i=i+1;
  9662. }
  9663. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9664. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9665. filenametemp[i+1] = 0;
  9666. do
  9667. {
  9668. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9669. sleep(3);
  9670. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9671. if(!isSuccess)
  9672. {
  9673. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9674. sleep(retryIntervalInt);
  9675. }
  9676. else
  9677. {
  9678. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9679. }
  9680. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9681. }
  9682. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9683. {
  9684. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9685. memset(temp, 0, ARRAY_SIZE(temp));
  9686. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9687. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9688. int ftppathlen=strlen(ftpbuf);
  9689. int i=1;
  9690. char filenametemp[50];
  9691. while(i < ftppathlen)
  9692. {
  9693. int len=ftppathlen-i;
  9694. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9695. {
  9696. DEBUG_INFO(" compare '/' all right\n");
  9697. break;
  9698. }
  9699. i=i+1;
  9700. }
  9701. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9702. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9703. filenametemp[i+1] = 0;
  9704. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9705. pch=strchr(temp,'@');
  9706. if(pch==NULL)
  9707. {
  9708. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9709. protocol, host, &port, path);
  9710. strcpy(user,"anonymous");
  9711. strcpy(password,"");
  9712. }
  9713. else
  9714. {
  9715. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9716. protocol, user, password, host, &port, path);
  9717. }
  9718. sscanf(host,"%[^/]%s",host1, path1);
  9719. sprintf(ftppath,"%s", path1);
  9720. //DEBUG_INFO("protocol =%s\n",protocol);
  9721. //DEBUG_INFO("user =%s\n",user);
  9722. //DEBUG_INFO("password =%s\n",password);
  9723. //DEBUG_INFO("host1 =%s\n",host1);
  9724. //DEBUG_INFO("port =%d\n",port);
  9725. //DEBUG_INFO("path1 =%s\n",path1);
  9726. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9727. //ftpFile(host, user, password, port, ftppath, fname);
  9728. //download firmware pthred
  9729. if(port == 0)
  9730. {
  9731. port = 21;
  9732. }
  9733. do
  9734. {
  9735. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9736. sleep(3);
  9737. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9738. if(!isSuccess)
  9739. {
  9740. //BulldogUtil.sleepMs(interval*1000);
  9741. DEBUG_INFO("Update firmware request and download file fail.\n");
  9742. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9743. sleep(retryIntervalInt);
  9744. }
  9745. else
  9746. {
  9747. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9748. }
  9749. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9750. }
  9751. else
  9752. {
  9753. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9754. }
  9755. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9756. pthread_exit(NULL);
  9757. }
  9758. //==========================================
  9759. // Handle server response routine
  9760. //==========================================
  9761. void handleAuthorizeResponse(char *payload, int gun_index)
  9762. {
  9763. mtrace();
  9764. char expiryDatestr[30]={0};
  9765. char parentIdTagstr[20]={0};
  9766. char statusstr[20]={0};
  9767. int expiryDateISNULL=FALSE;
  9768. int parentIdTagISNULL=FALSE;
  9769. DEBUG_INFO("handleAuthorizeResponse...\n");
  9770. json_object *Authorize;
  9771. Authorize = json_tokener_parse(payload);
  9772. if(!is_error(Authorize))
  9773. {
  9774. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  9775. {
  9776. // Required data
  9777. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  9778. // Optional data
  9779. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  9780. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  9781. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  9782. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  9783. }
  9784. }
  9785. json_object_put(Authorize);
  9786. if(expiryDateISNULL == FALSE)
  9787. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9788. if(parentIdTagISNULL == FALSE)
  9789. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9790. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9791. //Update idTag information to authorization cache if supproted
  9792. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9793. {
  9794. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  9795. }
  9796. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9797. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9798. authorizeRetryTimes = 0;
  9799. }
  9800. void handleBootNotificationResponse(char *payload, int gun_index)
  9801. {
  9802. mtrace();
  9803. char statusStr[12]={0};
  9804. char currentTimeStr[30]={0};
  9805. int intervalInt = 0;
  9806. struct tm tp;
  9807. char buf[28]={0};
  9808. char timebuf[50]={0};
  9809. DEBUG_INFO("handleBootNotificationResponse...\n");
  9810. json_object *BootNotification;
  9811. BootNotification = json_tokener_parse(payload);
  9812. if(!is_error(BootNotification))
  9813. {
  9814. // Required data
  9815. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  9816. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  9817. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  9818. }
  9819. json_object_put(BootNotification);
  9820. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9821. BootNotificationInterval = intervalInt;
  9822. HeartBeatWaitTime = intervalInt;
  9823. //write back to ShmOCPP16Data->BootNotification
  9824. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9825. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9826. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9827. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  9828. {
  9829. server_sign = TRUE;
  9830. server_pending =FALSE;
  9831. }
  9832. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9833. {
  9834. server_pending = TRUE;
  9835. }
  9836. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9837. tp.tm_isdst = -1;
  9838. //time_t utc = mktime(&tp);
  9839. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9840. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9841. sprintf(timebuf,"date -s '%s'",buf);
  9842. system(timebuf);
  9843. srand(time(NULL));
  9844. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  9845. //==============================================
  9846. // RTC sync
  9847. //==============================================
  9848. system("/sbin/hwclock -w --systohc");
  9849. SetOcppConnStatus(TRUE);
  9850. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9851. }
  9852. void handleDataTransferResponse(char *payload, int gun_index)
  9853. {
  9854. char sstr[160]={0};//sstr[200]={ 0 };
  9855. int c = 0;
  9856. char *loc;
  9857. DEBUG_INFO("handleDataTransferResponse ...\n");
  9858. loc = strstr(payload, "status");
  9859. printf("loc=%s\n",loc);
  9860. c = 0;
  9861. while (loc[3+strlen("status")+c] != '\"')
  9862. {
  9863. sstr[c] = loc[3+strlen("status")+c];
  9864. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9865. c++;
  9866. }
  9867. sstr[c] = '\0';
  9868. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  9869. }
  9870. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  9871. {
  9872. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  9873. //struct json_object *obj;
  9874. // obj = json_tokener_parse(payload);
  9875. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  9876. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  9877. //No fields are defined.
  9878. }
  9879. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  9880. {
  9881. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  9882. //struct json_object *obj;
  9883. // obj = json_tokener_parse(payload);
  9884. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  9885. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  9886. //No fields are defined.
  9887. }
  9888. void handleHeartbeatResponse(char *payload, int gun_index)
  9889. {
  9890. mtrace();
  9891. struct tm tp;
  9892. char buf[28]={0};
  9893. char timebuf[50]={0};
  9894. DEBUG_INFO("handleHeartbeatResponse...\n");
  9895. json_object *Heartbeat;
  9896. Heartbeat = json_tokener_parse(payload);
  9897. if(!is_error(Heartbeat))
  9898. {
  9899. // Required data
  9900. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  9901. }
  9902. json_object_put(Heartbeat);
  9903. if(FirstHeartBeat == 0)
  9904. {
  9905. FirstHeartBeat = 1;
  9906. DEBUG_INFO("FirstHeartBeat \n");
  9907. }
  9908. HeartBeatWithNOResponse = 0;
  9909. clientTime.Heartbeat=time((time_t*)NULL);
  9910. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9911. tp.tm_isdst = -1;
  9912. //time_t utc = mktime(&tp);
  9913. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9914. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9915. sprintf(timebuf,"date -s '%s'",buf);
  9916. system(timebuf);
  9917. //==============================================
  9918. // RTC sync
  9919. //==============================================
  9920. system("/sbin/hwclock -w --systohc");
  9921. }
  9922. void handleMeterValuesResponse(char *payload, int gun_index)
  9923. {
  9924. mtrace();
  9925. DEBUG_INFO("handleMeterValuesResponse...\n");
  9926. }
  9927. void handleStartTransactionResponse(char *payload, int gun_index)
  9928. {
  9929. mtrace();
  9930. //int transactionIdInt = 0;
  9931. FILE *outfile;
  9932. char data[100]={0};
  9933. DEBUG_INFO("handleStartTransactionResponse...\n");
  9934. json_object *StartTransaction;
  9935. StartTransaction = json_tokener_parse(payload);
  9936. if(!is_error(StartTransaction))
  9937. {
  9938. // Required data
  9939. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  9940. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  9941. // Optional data
  9942. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  9943. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  9944. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  9945. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  9946. }
  9947. json_object_put(StartTransaction);
  9948. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  9949. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  9950. //-----------Start : write to the Queue TransactionId file -----------------//
  9951. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  9952. {}
  9953. else
  9954. {
  9955. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  9956. if(log == NULL)
  9957. {
  9958. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  9959. return ;
  9960. }
  9961. else
  9962. {
  9963. fclose(log);
  9964. }
  9965. }
  9966. // open file for writing
  9967. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  9968. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  9969. {
  9970. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  9971. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  9972. fputs(data, outfile);
  9973. fclose (outfile);
  9974. }
  9975. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9976. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9977. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  9978. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  9979. }
  9980. void handleStatusNotificationResponse(char *payload, int gun_index)
  9981. {
  9982. mtrace();
  9983. DEBUG_INFO("handleStatusNotificationResponse...\n");
  9984. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  9985. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  9986. }
  9987. void handleStopTransactionnResponse(char *payload, int gun_index)
  9988. {
  9989. mtrace();
  9990. DEBUG_INFO("handleStopTransactionnResponse...\n");
  9991. json_object *StopTransaction;
  9992. StopTransaction = json_tokener_parse(payload);
  9993. if(!is_error(StopTransaction))
  9994. {
  9995. // Optional data
  9996. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  9997. {
  9998. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  9999. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  10000. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  10001. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10002. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  10003. }
  10004. }
  10005. json_object_put(StopTransaction);
  10006. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  10007. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  10008. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10009. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10010. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  10011. }
  10012. //==========================================
  10013. // Handle Error routine
  10014. //==========================================
  10015. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  10016. {
  10017. mtrace();
  10018. #ifdef SystemLogMessage
  10019. DEBUG_INFO("errorCode: %s\n", errorCode);
  10020. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  10021. DEBUG_INFO("errorDetails: %s\n", payload);
  10022. #endif
  10023. }
  10024. //===============================================
  10025. // Common routine
  10026. //===============================================
  10027. int initialConfigurationTable(void)
  10028. {
  10029. //clock_t start_t, end_t, total_t;
  10030. FILE *fp;
  10031. FILE *outfile;
  10032. char str[512]={0};
  10033. char sstr[256]={0};
  10034. int c = 0;
  10035. char *loc;
  10036. DEBUG_INFO("initialConfigurationTable...\n");
  10037. //start_t = clock();
  10038. //printf("Starting of the program, start_t = %ld\n", start_t);
  10039. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  10040. // Check configuration file size is correct
  10041. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  10042. {
  10043. struct stat st;
  10044. stat("/Storage/OCPP/OCPPConfiguration", &st);
  10045. if(st.st_size < 3100)
  10046. {
  10047. system("rm -f /Storage/OCPP/OCPPConfiguration");
  10048. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  10049. }
  10050. }
  10051. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  10052. {
  10053. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10054. if(outfile == NULL)
  10055. {
  10056. DEBUG_INFO("Error opening file\n");
  10057. return FALSE;
  10058. }
  10059. /*Core Profile*/
  10060. //AllowOfflineTxForUnknownId
  10061. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10062. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10063. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  10064. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10065. //AuthorizationCacheEnabled
  10066. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10067. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10068. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10069. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10070. //AuthorizeRemoteTxRequests
  10071. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10072. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10073. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  10074. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10075. //BlinkRepeat
  10076. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10077. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10078. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10079. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10080. //ClockAlignedDataInterval
  10081. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10082. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10084. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10085. //ConnectionTimeOut
  10086. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10087. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10088. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10089. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10090. //GetConfigurationMaxKeys
  10091. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10092. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10093. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "44" );
  10094. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10095. // HeartbeatInterval
  10096. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10097. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  10099. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10100. // LightIntensity
  10101. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10102. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10103. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10104. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10105. // LocalAuthorizeOffline
  10106. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  10107. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10108. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10109. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10110. // LocalPreAuthorize
  10111. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10114. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10115. // MaxEnergyOnInvalidId
  10116. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10117. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10119. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10120. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10121. // MeterValuesAlignedData
  10122. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  10123. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10124. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10126. else
  10127. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10128. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10129. // MeterValuesAlignedDataMaxLength
  10130. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10131. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10132. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  10134. else
  10135. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10136. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10137. // MeterValuesSampledData
  10138. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  10139. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10140. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10141. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10142. else
  10143. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10144. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10145. // MeterValuesSampledDataMaxLength
  10146. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10148. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10149. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  10150. else
  10151. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10152. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10153. // MeterValueSampleInterval
  10154. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10155. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10156. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  10157. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10158. // MinimumStatusDuration
  10159. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10160. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  10162. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  10163. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10164. // NumberOfConnectors
  10165. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10166. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10167. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10168. {
  10169. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10170. }
  10171. else
  10172. {
  10173. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10174. }
  10175. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10176. // ResetRetries
  10177. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10178. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10179. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10180. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10181. // ConnectorPhaseRotation
  10182. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10183. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10184. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10185. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10186. // ConnectorPhaseRotationMaxLength
  10187. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10188. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10189. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10190. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10191. // StopTransactionOnEVSideDisconnect
  10192. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10193. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10194. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10195. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10196. // StopTransactionOnInvalidId
  10197. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  10198. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10199. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10200. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10201. // StopTxnAlignedData
  10202. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10203. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10204. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10205. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10206. // StopTxnAlignedDataMaxLength
  10207. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10208. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10209. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10210. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10211. // StopTxnSampledData
  10212. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  10213. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10214. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10215. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10216. else
  10217. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10218. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10219. // StopTxnSampledDataMaxLength
  10220. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10221. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10222. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10223. {
  10224. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  10225. }
  10226. else
  10227. {
  10228. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  10229. }
  10230. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10231. // SupportedFeatureProfiles
  10232. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10233. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10234. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10235. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10236. // SupportedFeatureProfilesMaxLength
  10237. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10238. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10239. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10240. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10241. // TransactionMessageAttempts
  10242. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10243. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10244. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10245. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10246. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10247. // TransactionMessageRetryInterval
  10248. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10249. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10250. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10251. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10252. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10253. // UnlockConnectorOnEVSideDisconnect
  10254. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10255. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10256. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10257. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10258. // WebSocketPingInterval
  10259. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10260. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10261. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10262. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10263. // QueueOffLineStartTransactionMessage
  10264. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  10265. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10266. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10267. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10268. // AuthorizationKey
  10269. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  10270. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  10271. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "" );
  10272. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  10273. // SecurityProfile
  10274. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  10275. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  10276. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "0" );
  10277. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  10278. // DefaultPrice
  10279. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  10280. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  10281. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  10282. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  10283. // CustomDisplayCostAndPrice
  10284. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  10285. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  10286. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  10287. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  10288. // CustomIdleFeeAfterStop
  10289. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  10290. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  10291. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  10292. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  10293. //* Local Auth List Management Profile*/
  10294. #if 0
  10295. //For OCTT Test Case
  10296. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10297. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10298. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10299. #endif
  10300. #if 1
  10301. //LocalAuthListEnabled
  10302. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10303. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10304. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10305. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10306. #endif
  10307. //LocalAuthListMaxLength
  10308. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10309. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10311. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10312. //SendLocalListMaxLength
  10313. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10314. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10315. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  10316. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10317. //ReserveConnectorZeroSupported
  10318. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10319. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10320. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10321. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10322. //* Smart Charging Profile */
  10323. //ChargeProfileMaxStackLevel
  10324. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10325. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10326. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10327. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10328. // ChargingScheduleAllowedChargingRateUnit
  10329. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10330. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10331. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10332. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10333. // ChargingScheduleMaxPeriods
  10334. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10335. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10336. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10337. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10338. // ConnectorSwitch3to1PhaseSupported
  10339. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10340. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10341. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10342. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10343. // MaxChargingProfilesInstalled
  10344. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10345. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10346. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  10347. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10348. fclose(outfile);
  10349. }
  10350. else
  10351. {
  10352. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10353. char keystr[60]={0};
  10354. char readonlystr[10]={0};
  10355. char valuestr[256]={0};
  10356. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10357. if(fp == NULL) {
  10358. DEBUG_INFO("Error opening file");
  10359. return FALSE;
  10360. }
  10361. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  10362. {
  10363. //DEBUG_INFO("Get Configuration \n");
  10364. if(strlen(str) > 0)
  10365. {
  10366. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10367. //*************************key*********************************/
  10368. if(strstr(str, "key") != NULL)
  10369. {
  10370. loc = strstr(str, "key");
  10371. c = 0;
  10372. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10373. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  10374. {
  10375. sstr[c] = loc[strlen("key")+3+c];
  10376. c++;
  10377. }
  10378. sstr[c] = '\0';
  10379. strcpy(keystr,sstr);
  10380. }
  10381. //*************************readonly*********************************/
  10382. if(strstr(str, "readonly") != NULL)
  10383. {
  10384. loc = strstr(str, "readonly");
  10385. c = 0;
  10386. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10387. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  10388. {
  10389. sstr[c] = loc[strlen("readonly")+2+c];
  10390. c++;
  10391. }
  10392. sstr[c] = '\0';
  10393. strcpy(readonlystr,sstr);
  10394. }
  10395. //*************************value*********************************/
  10396. if(strstr(str, "value") != NULL)
  10397. {
  10398. loc = strstr(str, "value");
  10399. c = 0;
  10400. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10401. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  10402. {
  10403. sstr[c] = loc[strlen("value")+3+c];
  10404. c++;
  10405. }
  10406. sstr[c] = '\0';
  10407. strcpy(valuestr,sstr);
  10408. }
  10409. // DEBUG_INFO("keystr=%s\n",keystr);
  10410. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10411. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10412. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10413. {
  10414. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10415. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10416. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10417. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10418. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10419. }
  10420. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10421. {
  10422. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10423. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10424. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10425. }
  10426. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10427. {
  10428. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10429. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10430. }
  10431. if(strcmp(keystr, "BlinkRepeat") == 0)
  10432. {
  10433. //Charger.BlinkRepeat = Integer.parseInt(value);
  10434. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10435. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10436. }
  10437. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10438. {
  10439. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10440. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10441. }
  10442. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10443. {
  10444. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10445. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10446. }
  10447. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10448. {
  10449. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10450. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  10451. }
  10452. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10453. {
  10454. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10455. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10456. HeartBeatWaitTime = atoi(valuestr);
  10457. }
  10458. if(strcmp(keystr, "LightIntensity") == 0)
  10459. {
  10460. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10461. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10462. }
  10463. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10464. {
  10465. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10466. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10467. }
  10468. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10469. {
  10470. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10471. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10472. }
  10473. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10474. {
  10475. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10476. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10477. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10478. }
  10479. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10480. {
  10481. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10482. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10483. }
  10484. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10485. {
  10486. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10487. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10488. }
  10489. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10490. {
  10491. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10492. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10493. }
  10494. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10495. {
  10496. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10497. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10498. }
  10499. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10500. {
  10501. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10502. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10503. }
  10504. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10505. {
  10506. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10507. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10508. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10509. }
  10510. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10511. {
  10512. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10513. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10514. }
  10515. if(strcmp(keystr, "ResetRetries") == 0)
  10516. {
  10517. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10518. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10519. }
  10520. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10521. {
  10522. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10523. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10524. }
  10525. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10526. {
  10527. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10528. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10529. }
  10530. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10531. {
  10532. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10533. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10534. }
  10535. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10536. {
  10537. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10538. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10539. }
  10540. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10541. {
  10542. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10543. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10544. }
  10545. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10546. {
  10547. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10548. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10549. }
  10550. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10551. {
  10552. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10553. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10554. }
  10555. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10556. {
  10557. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10558. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10559. }
  10560. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10561. {
  10562. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10563. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10564. }
  10565. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10566. {
  10567. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10568. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10569. }
  10570. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10571. {
  10572. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10573. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10574. TransactionMessageAttemptsValue = atoi(valuestr);
  10575. }
  10576. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10577. {
  10578. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10579. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10580. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10581. }
  10582. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10583. {
  10584. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10585. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10586. }
  10587. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10588. {
  10589. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10590. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10591. }
  10592. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  10593. {
  10594. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10595. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  10596. }
  10597. if(strcmp(keystr, "AuthorizationKey") == 0)
  10598. {
  10599. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10600. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  10601. }
  10602. if(strcmp(keystr, "SecurityProfile") == 0)
  10603. {
  10604. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10605. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  10606. }
  10607. if(strcmp(keystr, "DefaultPrice") == 0)
  10608. {
  10609. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10610. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  10611. }
  10612. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  10613. {
  10614. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10615. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  10616. }
  10617. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  10618. {
  10619. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10620. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  10621. }
  10622. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10623. {
  10624. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10625. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10626. }
  10627. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10628. {
  10629. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10630. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10631. }
  10632. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10633. {
  10634. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10635. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10636. }
  10637. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10638. {
  10639. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10640. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10641. }
  10642. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10643. {
  10644. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10645. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10646. }
  10647. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10648. {
  10649. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10650. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10651. }
  10652. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10653. {
  10654. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10655. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10656. }
  10657. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10658. {
  10659. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10660. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10661. }
  10662. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10663. {
  10664. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10665. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10666. }
  10667. }
  10668. }
  10669. fclose(fp);
  10670. }
  10671. return 0;
  10672. }
  10673. void StoreConfigurationTable(void)
  10674. {
  10675. FILE *outfile;
  10676. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10677. if(outfile == NULL)
  10678. {
  10679. DEBUG_INFO("Error opening file");
  10680. return ;
  10681. }
  10682. /*Core Profile*/
  10683. //AllowOfflineTxForUnknownId
  10684. /*
  10685. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10686. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10687. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10688. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10689. */
  10690. //DEBUG_INFO("data=%s\n",data);
  10691. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10692. //AuthorizationCacheEnabled
  10693. /*
  10694. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10695. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10697. */
  10698. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10699. //AuthorizeRemoteTxRequests
  10700. /*
  10701. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10702. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10703. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10704. */
  10705. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10706. //BlinkRepeat
  10707. /*
  10708. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10709. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10710. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10711. */
  10712. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10713. //ClockAlignedDataInterval
  10714. /*
  10715. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10716. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10717. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10718. */
  10719. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10720. //ConnectionTimeOut
  10721. /*
  10722. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10723. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10724. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10725. */
  10726. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10727. //GetConfigurationMaxKeys
  10728. /*
  10729. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10730. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10731. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10732. */
  10733. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10734. // HeartbeatInterval
  10735. /*
  10736. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10737. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10738. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10739. */
  10740. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10741. // LightIntensity
  10742. /*
  10743. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10744. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10746. */
  10747. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10748. // LocalAuthorizeOffline
  10749. /*
  10750. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10751. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10752. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10753. */
  10754. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10755. // LocalPreAuthorize
  10756. /*
  10757. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10758. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10759. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10760. */
  10761. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10762. // MaxEnergyOnInvalidId
  10763. /*
  10764. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10765. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10766. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10767. */
  10768. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10769. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10770. // MeterValuesAlignedData
  10771. /*
  10772. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10775. */
  10776. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10777. // MeterValuesAlignedDataMaxLength
  10778. /*
  10779. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10780. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10781. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10782. */
  10783. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10784. // MeterValuesSampledData
  10785. /*
  10786. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10787. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10789. */
  10790. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10791. // MeterValuesSampledDataMaxLength
  10792. /*
  10793. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10794. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10796. */
  10797. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10798. // MeterValueSampleInterval
  10799. /*
  10800. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10801. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10803. */
  10804. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10805. // MinimumStatusDuration
  10806. /*
  10807. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10810. */
  10811. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10812. // NumberOfConnectors
  10813. /*
  10814. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10815. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10816. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10817. {
  10818. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10819. }
  10820. else
  10821. {
  10822. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10823. }
  10824. */
  10825. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10826. // ResetRetries
  10827. /*
  10828. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10829. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10830. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10831. */
  10832. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10833. // ConnectorPhaseRotation
  10834. /*
  10835. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10836. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10837. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10838. */
  10839. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10840. // ConnectorPhaseRotationMaxLength
  10841. /*
  10842. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10843. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10845. */
  10846. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10847. // StopTransactionOnEVSideDisconnect
  10848. /*
  10849. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10850. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10852. */
  10853. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10854. // StopTransactionOnInvalidId
  10855. /*
  10856. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  10857. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10859. */
  10860. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10861. // StopTxnAlignedData
  10862. /*
  10863. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10864. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10865. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10866. */
  10867. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10868. // StopTxnAlignedDataMaxLength
  10869. /*
  10870. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10871. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10872. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10873. */
  10874. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10875. // StopTxnSampledData
  10876. /*
  10877. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10878. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10879. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  10880. */
  10881. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10882. // StopTxnSampledDataMaxLength
  10883. /*
  10884. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10885. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10886. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10887. */
  10888. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10889. // SupportedFeatureProfiles
  10890. /*
  10891. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10892. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10893. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10894. */
  10895. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10896. // SupportedFeatureProfilesMaxLength
  10897. /*
  10898. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10899. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10900. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10901. */
  10902. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10903. // TransactionMessageAttempts
  10904. /*
  10905. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10906. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10907. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10908. */
  10909. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10910. // TransactionMessageRetryInterval
  10911. /*
  10912. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10913. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10914. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10915. */
  10916. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10917. // UnlockConnectorOnEVSideDisconnect
  10918. /*
  10919. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10920. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10921. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10922. */
  10923. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10924. // WebSocketPingInterval
  10925. /*
  10926. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10927. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10928. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10929. */
  10930. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10931. // QueueOffLineStartTransactionMessage
  10932. /*
  10933. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  10934. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10935. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10936. */
  10937. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10938. // AuthorizationKey
  10939. /*
  10940. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  10941. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  10942. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  10943. */
  10944. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  10945. // SecurityProfile
  10946. /*
  10947. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  10948. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  10949. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  10950. */
  10951. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  10952. // DefaultPrice
  10953. /*
  10954. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  10955. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  10956. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  10957. */
  10958. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  10959. // CustomDisplayCostAndPrice
  10960. /*
  10961. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  10962. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  10963. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  10964. */
  10965. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  10966. // CustomIdleFeeAfterStop
  10967. /*
  10968. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  10969. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  10970. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  10971. */
  10972. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  10973. //* Local Auth List Management Profile*/
  10974. //LocalAuthListEnabled
  10975. /*
  10976. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10977. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10978. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10979. */
  10980. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10981. //LocalAuthListMaxLength
  10982. /*
  10983. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10984. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10985. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10986. */
  10987. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10988. //SendLocalListMaxLength
  10989. /*
  10990. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10991. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10992. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10993. */
  10994. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10995. //ReserveConnectorZeroSupported
  10996. /*
  10997. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10998. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10999. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11000. */
  11001. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11002. //* Smart Charging Profile */
  11003. //ChargeProfileMaxStackLevel
  11004. /*
  11005. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11006. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11007. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11008. */
  11009. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11010. // ChargingScheduleAllowedChargingRateUnit
  11011. /*
  11012. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11013. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11014. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  11015. */
  11016. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11017. // ChargingScheduleMaxPeriods
  11018. /*
  11019. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11020. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11021. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11022. */
  11023. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11024. // ConnectorSwitch3to1PhaseSupported
  11025. /*
  11026. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11027. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11028. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  11029. */
  11030. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11031. // MaxChargingProfilesInstalled
  11032. /*
  11033. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11034. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11035. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  11036. */
  11037. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11038. fclose(outfile);
  11039. }
  11040. void getKeyValue(char *keyReq)
  11041. {
  11042. int isEmpty = FALSE;
  11043. int isKnowKey = FALSE;
  11044. DEBUG_INFO("keyReq = %s\n", keyReq);
  11045. if((keyReq == NULL) || (strlen(keyReq) == 0))
  11046. isEmpty = TRUE;
  11047. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  11048. {
  11049. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  11050. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  11051. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11052. {
  11053. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  11054. }
  11055. else
  11056. {
  11057. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  11058. }
  11059. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  11060. isKnowKey = TRUE;
  11061. }
  11062. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  11063. {
  11064. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  11065. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  11066. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11067. {
  11068. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  11069. }
  11070. else
  11071. {
  11072. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  11073. }
  11074. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  11075. isKnowKey = TRUE;
  11076. }
  11077. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  11078. {
  11079. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  11080. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  11081. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11082. {
  11083. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  11084. }
  11085. else
  11086. {
  11087. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  11088. }
  11089. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  11090. isKnowKey = TRUE;
  11091. }
  11092. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  11093. {
  11094. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  11095. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  11096. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11097. {
  11098. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  11099. }
  11100. else
  11101. {
  11102. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  11103. }
  11104. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  11105. isKnowKey = TRUE;
  11106. }
  11107. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  11108. {
  11109. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  11110. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  11111. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11112. {
  11113. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  11114. }
  11115. else
  11116. {
  11117. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  11118. }
  11119. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  11120. isKnowKey = TRUE;
  11121. }
  11122. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  11123. {
  11124. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  11125. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  11126. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11127. {
  11128. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  11129. }
  11130. else
  11131. {
  11132. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  11133. }
  11134. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  11135. isKnowKey = TRUE;
  11136. }
  11137. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  11138. {
  11139. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  11140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  11141. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11142. {
  11143. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  11144. }
  11145. else
  11146. {
  11147. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  11148. }
  11149. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  11150. isKnowKey = TRUE;
  11151. }
  11152. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  11153. {
  11154. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  11155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  11156. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11157. {
  11158. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  11159. }
  11160. else
  11161. {
  11162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  11163. }
  11164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  11165. isKnowKey = TRUE;
  11166. }
  11167. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  11168. {
  11169. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  11170. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  11171. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11172. {
  11173. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  11174. }
  11175. else
  11176. {
  11177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  11178. }
  11179. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  11180. isKnowKey = TRUE;
  11181. }
  11182. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  11183. {
  11184. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  11185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  11186. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11187. {
  11188. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  11189. }
  11190. else
  11191. {
  11192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  11193. }
  11194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  11195. isKnowKey = TRUE;
  11196. }
  11197. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  11198. {
  11199. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  11200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  11201. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11202. {
  11203. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  11204. }
  11205. else
  11206. {
  11207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  11208. }
  11209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  11210. isKnowKey = TRUE;
  11211. }
  11212. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  11213. {
  11214. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  11215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  11216. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11217. {
  11218. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11219. }
  11220. else
  11221. {
  11222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11223. }
  11224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  11225. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  11226. isKnowKey = TRUE;
  11227. }
  11228. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  11229. {
  11230. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  11231. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11232. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11233. {
  11234. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11235. }
  11236. else
  11237. {
  11238. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11239. }
  11240. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11241. isKnowKey = TRUE;
  11242. }
  11243. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11244. {
  11245. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11246. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11247. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11248. {
  11249. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11250. }
  11251. else
  11252. {
  11253. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11254. }
  11255. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11256. isKnowKey = TRUE;
  11257. }
  11258. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11259. {
  11260. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11261. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11262. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11263. {
  11264. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11265. }
  11266. else
  11267. {
  11268. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11269. }
  11270. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11271. isKnowKey = TRUE;
  11272. }
  11273. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11274. {
  11275. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11276. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11277. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11278. {
  11279. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11280. }
  11281. else
  11282. {
  11283. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11284. }
  11285. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11286. isKnowKey = TRUE;
  11287. }
  11288. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11289. {
  11290. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11291. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11292. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11293. {
  11294. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11295. }
  11296. else
  11297. {
  11298. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11299. }
  11300. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11301. isKnowKey = TRUE;
  11302. }
  11303. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11304. {
  11305. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11306. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11307. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11308. {
  11309. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11310. }
  11311. else
  11312. {
  11313. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11314. }
  11315. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11316. isKnowKey = TRUE;
  11317. }
  11318. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11319. {
  11320. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11321. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11322. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11323. {
  11324. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11325. }
  11326. else
  11327. {
  11328. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11329. }
  11330. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11331. isKnowKey = TRUE;
  11332. }
  11333. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11334. {
  11335. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11336. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11337. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11338. {
  11339. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11340. }
  11341. else
  11342. {
  11343. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11344. }
  11345. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11346. isKnowKey = TRUE;
  11347. }
  11348. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11349. {
  11350. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11352. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11353. {
  11354. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11355. }
  11356. else
  11357. {
  11358. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11359. }
  11360. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11361. isKnowKey = TRUE;
  11362. }
  11363. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11364. {
  11365. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11366. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11367. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11368. {
  11369. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11370. }
  11371. else
  11372. {
  11373. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11374. }
  11375. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11376. isKnowKey = TRUE;
  11377. }
  11378. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11379. {
  11380. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11381. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11382. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11383. {
  11384. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11385. }
  11386. else
  11387. {
  11388. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11389. }
  11390. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11391. isKnowKey = TRUE;
  11392. }
  11393. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11394. {
  11395. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11396. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11397. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11398. {
  11399. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11400. }
  11401. else
  11402. {
  11403. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11404. }
  11405. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11406. isKnowKey = TRUE;
  11407. }
  11408. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11409. {
  11410. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11411. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11412. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11413. {
  11414. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11415. }
  11416. else
  11417. {
  11418. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11419. }
  11420. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11421. isKnowKey = TRUE;
  11422. }
  11423. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11424. {
  11425. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11426. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11427. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11428. {
  11429. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11430. }
  11431. else
  11432. {
  11433. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11434. }
  11435. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11436. isKnowKey = TRUE;
  11437. }
  11438. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11439. {
  11440. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11441. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11442. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11443. {
  11444. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11445. }
  11446. else
  11447. {
  11448. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11449. }
  11450. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11451. isKnowKey = TRUE;
  11452. }
  11453. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11454. {
  11455. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11457. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11458. {
  11459. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11460. }
  11461. else
  11462. {
  11463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11464. }
  11465. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11466. isKnowKey = TRUE;
  11467. }
  11468. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11469. {
  11470. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11471. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11472. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11473. {
  11474. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11475. }
  11476. else
  11477. {
  11478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11479. }
  11480. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11481. isKnowKey = TRUE;
  11482. }
  11483. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11484. {
  11485. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11487. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11488. {
  11489. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11490. }
  11491. else
  11492. {
  11493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11494. }
  11495. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11496. isKnowKey = TRUE;
  11497. }
  11498. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11499. {
  11500. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11502. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11503. {
  11504. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11505. }
  11506. else
  11507. {
  11508. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11509. }
  11510. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11511. isKnowKey = TRUE;
  11512. }
  11513. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11514. {
  11515. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11517. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11518. {
  11519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11520. }
  11521. else
  11522. {
  11523. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11524. }
  11525. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11526. isKnowKey = TRUE;
  11527. }
  11528. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11529. {
  11530. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11531. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11532. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11533. {
  11534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11535. }
  11536. else
  11537. {
  11538. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11539. }
  11540. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11541. isKnowKey = TRUE;
  11542. }
  11543. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11544. {
  11545. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11546. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11547. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11548. {
  11549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11550. }
  11551. else
  11552. {
  11553. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11554. }
  11555. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11556. isKnowKey = TRUE;
  11557. }
  11558. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  11559. {
  11560. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  11561. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  11562. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  11563. {
  11564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  11565. }
  11566. else
  11567. {
  11568. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  11569. }
  11570. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  11571. isKnowKey = TRUE;
  11572. }
  11573. /*
  11574. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  11575. {
  11576. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  11577. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  11578. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  11579. {
  11580. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  11581. }
  11582. else
  11583. {
  11584. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  11585. }
  11586. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  11587. isKnowKey = TRUE;
  11588. }*/
  11589. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  11590. {
  11591. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  11592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  11593. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  11594. {
  11595. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  11596. }
  11597. else
  11598. {
  11599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  11600. }
  11601. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  11602. isKnowKey = TRUE;
  11603. }
  11604. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  11605. {
  11606. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  11607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  11608. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  11609. {
  11610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  11611. }
  11612. else
  11613. {
  11614. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  11615. }
  11616. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  11617. isKnowKey = TRUE;
  11618. }
  11619. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  11620. {
  11621. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  11622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  11623. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  11624. {
  11625. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  11626. }
  11627. else
  11628. {
  11629. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  11630. }
  11631. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  11632. isKnowKey = TRUE;
  11633. }
  11634. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  11635. {
  11636. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  11637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  11638. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  11639. {
  11640. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  11641. }
  11642. else
  11643. {
  11644. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  11645. }
  11646. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  11647. isKnowKey = TRUE;
  11648. }
  11649. #if 1
  11650. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11651. {
  11652. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11654. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11655. {
  11656. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11657. }
  11658. else
  11659. {
  11660. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11661. }
  11662. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11663. isKnowKey = TRUE;
  11664. }
  11665. #endif
  11666. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11667. {
  11668. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11669. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11670. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11671. {
  11672. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11673. }
  11674. else
  11675. {
  11676. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11677. }
  11678. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11679. isKnowKey = TRUE;
  11680. }
  11681. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11682. {
  11683. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11684. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11685. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11686. {
  11687. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11688. }
  11689. else
  11690. {
  11691. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11692. }
  11693. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11694. isKnowKey = TRUE;
  11695. }
  11696. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11697. {
  11698. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11699. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11700. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11701. {
  11702. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11703. }
  11704. else
  11705. {
  11706. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11707. }
  11708. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11709. isKnowKey = TRUE;
  11710. }
  11711. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11712. {
  11713. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11714. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11715. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11716. {
  11717. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11718. }
  11719. else
  11720. {
  11721. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11722. }
  11723. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11724. isKnowKey = TRUE;
  11725. }
  11726. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11727. {
  11728. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11729. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11730. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11731. {
  11732. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11733. }
  11734. else
  11735. {
  11736. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11737. }
  11738. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11739. isKnowKey = TRUE;
  11740. }
  11741. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11742. {
  11743. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11744. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11745. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11746. {
  11747. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11748. }
  11749. else
  11750. {
  11751. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11752. }
  11753. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11754. isKnowKey = TRUE;
  11755. }
  11756. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11757. {
  11758. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11759. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11760. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11761. {
  11762. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11763. }
  11764. else
  11765. {
  11766. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11767. }
  11768. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11769. isKnowKey = TRUE;
  11770. }
  11771. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11772. {
  11773. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11774. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11775. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11776. {
  11777. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11778. }
  11779. else
  11780. {
  11781. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11782. }
  11783. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11784. isKnowKey = TRUE;
  11785. }
  11786. //=========================================================
  11787. if(!isEmpty && !isKnowKey)
  11788. {
  11789. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11790. strcpy(unknownkey[UnknownKeynum], keyReq);
  11791. UnknownKeynum = UnknownKeynum + 1;
  11792. }
  11793. }
  11794. void processUnkownKey(void)
  11795. {
  11796. DEBUG_INFO("processUnkownKey...\n");
  11797. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11798. for(int index=0; index < UnknownKeynum; index++)
  11799. {
  11800. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11801. {
  11802. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11803. }
  11804. }
  11805. }
  11806. int setKeyValue(char *key, char *value)
  11807. {
  11808. int isSuccess = NotSupported;
  11809. int check_ascii=0;
  11810. char str[10]={0};
  11811. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  11812. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11813. {
  11814. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11815. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11816. {
  11817. strcpy(str, (const char*)value);
  11818. for(int i = 0; str[i]; i++){
  11819. str[i] = tolower(str[i]);
  11820. }
  11821. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11822. isSuccess = ConfigurationStatus_Accepted;
  11823. }
  11824. else
  11825. {
  11826. isSuccess = ConfigurationStatus_Rejected;
  11827. }
  11828. }
  11829. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11830. {
  11831. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11832. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11833. {
  11834. strcpy(str, (const char*)value);
  11835. for(int i = 0; str[i]; i++){
  11836. str[i] = tolower(str[i]);
  11837. }
  11838. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11839. isSuccess = ConfigurationStatus_Accepted;
  11840. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11841. }
  11842. else
  11843. {
  11844. isSuccess = ConfigurationStatus_Rejected;
  11845. }
  11846. }
  11847. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11848. {
  11849. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11850. {
  11851. strcpy(str, (const char*)value);
  11852. for(int i = 0; str[i]; i++)
  11853. {
  11854. str[i] = tolower(str[i]);
  11855. }
  11856. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11857. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11858. isSuccess = ConfigurationStatus_Accepted;
  11859. }
  11860. else
  11861. {
  11862. isSuccess = ConfigurationStatus_Rejected;
  11863. }
  11864. }
  11865. if(strcmp(key, "BlinkRepeat") == 0)
  11866. {
  11867. //Charger.BlinkRepeat = Integer.parseInt(value);
  11868. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11869. {
  11870. check_ascii = value[0];
  11871. if( (check_ascii < 48) || (check_ascii > 57) )
  11872. {
  11873. isSuccess = ConfigurationStatus_Rejected;
  11874. }
  11875. else
  11876. {
  11877. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11878. isSuccess = ConfigurationStatus_Accepted;
  11879. }
  11880. }
  11881. else
  11882. {
  11883. isSuccess = ConfigurationStatus_Rejected;
  11884. }
  11885. }
  11886. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11887. {
  11888. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11889. {
  11890. check_ascii = value[0];
  11891. if( (check_ascii < 48) || (check_ascii > 57) )
  11892. {
  11893. isSuccess = ConfigurationStatus_Rejected;
  11894. }
  11895. else
  11896. {
  11897. if((atoi(value) == 0) || (atoi(value) >= 10))
  11898. {
  11899. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11900. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11901. isSuccess = ConfigurationStatus_Accepted;
  11902. }
  11903. else
  11904. isSuccess = ConfigurationStatus_Rejected;
  11905. }
  11906. }
  11907. else
  11908. {
  11909. isSuccess = ConfigurationStatus_Rejected;
  11910. }
  11911. }
  11912. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11913. {
  11914. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11915. {
  11916. check_ascii = value[0];
  11917. if( (check_ascii < 48) || (check_ascii > 57) )
  11918. {
  11919. isSuccess = ConfigurationStatus_Rejected;
  11920. }
  11921. else
  11922. {
  11923. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11924. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11925. isSuccess = ConfigurationStatus_Accepted;
  11926. }
  11927. }
  11928. else
  11929. {
  11930. isSuccess = ConfigurationStatus_Rejected;
  11931. }
  11932. }
  11933. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11934. {
  11935. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11936. {
  11937. check_ascii = value[0];
  11938. if( (check_ascii < 48) || (check_ascii > 57) )
  11939. {
  11940. isSuccess = ConfigurationStatus_Rejected;
  11941. }
  11942. else
  11943. {
  11944. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11945. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11946. isSuccess = ConfigurationStatus_Accepted;
  11947. }
  11948. }
  11949. else
  11950. {
  11951. isSuccess = ConfigurationStatus_Rejected;
  11952. }
  11953. }
  11954. if(strcmp(key, "HeartbeatInterval") == 0)
  11955. {
  11956. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11957. {
  11958. check_ascii = value[0];
  11959. if( (check_ascii < 48) || (check_ascii > 57) )
  11960. {
  11961. isSuccess = ConfigurationStatus_Rejected;
  11962. }
  11963. else
  11964. {
  11965. if((atoi(value) == 0) || (atoi(value) >= 10))
  11966. {
  11967. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11968. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11969. HeartBeatWaitTime = atoi(value);
  11970. isSuccess = ConfigurationStatus_Accepted;
  11971. }
  11972. else
  11973. {
  11974. isSuccess = ConfigurationStatus_Rejected;
  11975. }
  11976. }
  11977. }
  11978. else
  11979. {
  11980. isSuccess = ConfigurationStatus_Rejected;
  11981. }
  11982. }
  11983. if(strcmp(key, "LightIntensity") == 0)
  11984. {
  11985. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11986. {
  11987. check_ascii = value[0];
  11988. if( (check_ascii < 48) || (check_ascii > 57) )
  11989. {
  11990. isSuccess = ConfigurationStatus_Rejected;
  11991. }
  11992. else
  11993. {
  11994. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  11995. isSuccess = ConfigurationStatus_Accepted;
  11996. }
  11997. }
  11998. else
  11999. {
  12000. isSuccess = ConfigurationStatus_Rejected;
  12001. }
  12002. }
  12003. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  12004. {
  12005. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  12006. {
  12007. strcpy(str, (const char*)value);
  12008. for(int i = 0; str[i]; i++)
  12009. {
  12010. str[i] = tolower(str[i]);
  12011. }
  12012. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12013. isSuccess = ConfigurationStatus_Accepted;
  12014. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12015. }
  12016. else
  12017. {
  12018. isSuccess = ConfigurationStatus_Rejected;
  12019. }
  12020. }
  12021. if(strcmp(key, "LocalPreAuthorize") == 0)
  12022. {
  12023. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12024. {
  12025. strcpy(str, (const char*)value);
  12026. for(int i = 0; str[i]; i++)
  12027. {
  12028. str[i] = tolower(str[i]);
  12029. }
  12030. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12031. isSuccess = ConfigurationStatus_Accepted;
  12032. }
  12033. else
  12034. {
  12035. isSuccess = ConfigurationStatus_Rejected;
  12036. }
  12037. }
  12038. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  12039. {
  12040. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  12041. {
  12042. check_ascii = value[0];
  12043. if( (check_ascii < 48) || (check_ascii > 57) )
  12044. {
  12045. isSuccess = ConfigurationStatus_Rejected;
  12046. }
  12047. else
  12048. {
  12049. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  12050. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  12051. isSuccess = ConfigurationStatus_Accepted;
  12052. }
  12053. }
  12054. else
  12055. {
  12056. isSuccess = ConfigurationStatus_Rejected;
  12057. }
  12058. }
  12059. if(strcmp(key, "MeterValuesAlignedData") == 0)
  12060. {
  12061. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12062. {
  12063. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  12064. isSuccess = ConfigurationStatus_Accepted;
  12065. }
  12066. else
  12067. {
  12068. isSuccess = ConfigurationStatus_Rejected;
  12069. }
  12070. }
  12071. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  12072. {
  12073. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12074. {
  12075. check_ascii = value[0];
  12076. if( (check_ascii < 48) || (check_ascii > 57) )
  12077. {
  12078. isSuccess = ConfigurationStatus_Rejected;
  12079. }
  12080. else
  12081. {
  12082. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12083. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  12084. isSuccess = ConfigurationStatus_Accepted;
  12085. }
  12086. }
  12087. else
  12088. {
  12089. isSuccess = ConfigurationStatus_Rejected;
  12090. }
  12091. }
  12092. if(strcmp(key, "MeterValuesSampledData") == 0 )
  12093. {
  12094. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12095. {
  12096. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  12097. isSuccess = ConfigurationStatus_Accepted;
  12098. }
  12099. else
  12100. {
  12101. isSuccess = ConfigurationStatus_Rejected;
  12102. }
  12103. }
  12104. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  12105. {
  12106. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12107. {
  12108. check_ascii = value[0];
  12109. if( (check_ascii < 48) || (check_ascii > 57) )
  12110. {
  12111. isSuccess = ConfigurationStatus_Rejected;
  12112. }
  12113. else
  12114. {
  12115. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12116. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  12117. isSuccess = ConfigurationStatus_Accepted;
  12118. }
  12119. }
  12120. else
  12121. {
  12122. isSuccess = ConfigurationStatus_Rejected;
  12123. }
  12124. }
  12125. if(strcmp(key, "MeterValueSampleInterval") == 0)
  12126. {
  12127. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12128. {
  12129. check_ascii = value[0];
  12130. if( (check_ascii < 48) || (check_ascii > 57) )
  12131. {
  12132. isSuccess = ConfigurationStatus_Rejected;
  12133. }
  12134. else
  12135. {
  12136. if((atoi(value) == 0) || (atoi(value) >= 10))
  12137. {
  12138. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12139. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  12140. isSuccess = ConfigurationStatus_Accepted;
  12141. }
  12142. else
  12143. {
  12144. isSuccess = ConfigurationStatus_Rejected;
  12145. }
  12146. }
  12147. }
  12148. else
  12149. {
  12150. isSuccess = ConfigurationStatus_Rejected;
  12151. }
  12152. }
  12153. if(strcmp(key, "MinimumStatusDuration") == 0)
  12154. {
  12155. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12156. {
  12157. check_ascii = value[0];
  12158. if( (check_ascii < 48) || (check_ascii > 57) )
  12159. {
  12160. isSuccess = ConfigurationStatus_Rejected;
  12161. }
  12162. else
  12163. {
  12164. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  12165. {
  12166. isSuccess = ConfigurationStatus_Rejected;
  12167. }
  12168. else
  12169. {
  12170. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  12171. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  12172. server_cycle_Status = atoi(value); //StatusNotification Cycle
  12173. isSuccess = ConfigurationStatus_Accepted;
  12174. }
  12175. }
  12176. }
  12177. else
  12178. {
  12179. isSuccess = ConfigurationStatus_Rejected;
  12180. }
  12181. }
  12182. if(strcmp(key, "NumberOfConnectors") == 0)
  12183. {
  12184. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12185. {
  12186. check_ascii = value[0];
  12187. if( (check_ascii < 48) || (check_ascii > 57) )
  12188. {
  12189. isSuccess = ConfigurationStatus_Rejected;
  12190. }
  12191. else
  12192. {
  12193. //Charger.ResetRetries = Integer.parseInt(value);
  12194. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  12195. isSuccess = ConfigurationStatus_Accepted;
  12196. }
  12197. }
  12198. else
  12199. {
  12200. isSuccess = ConfigurationStatus_Rejected;
  12201. }
  12202. }
  12203. if(strcmp(key, "ResetRetries") == 0)
  12204. {
  12205. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12206. {
  12207. check_ascii = value[0];
  12208. if( (check_ascii < 48) || (check_ascii > 57) )
  12209. {
  12210. isSuccess = ConfigurationStatus_Rejected;
  12211. }
  12212. else
  12213. {
  12214. //Charger.ResetRetries = Integer.parseInt(value);
  12215. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  12216. isSuccess = ConfigurationStatus_Accepted;
  12217. }
  12218. }
  12219. else
  12220. {
  12221. isSuccess = ConfigurationStatus_Rejected;
  12222. }
  12223. }
  12224. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  12225. {
  12226. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12227. {
  12228. strcpy(str, (const char*)value);
  12229. for(int i = 0; str[i]; i++)
  12230. {
  12231. str[i] = tolower(str[i]);
  12232. }
  12233. if(strcmp(str, "notapplicable")== 0)
  12234. {
  12235. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12236. isSuccess = ConfigurationStatus_Accepted;
  12237. }
  12238. else if(strcmp(str, "unknown")== 0)
  12239. {
  12240. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12241. isSuccess = ConfigurationStatus_Accepted;
  12242. }
  12243. else if(strcmp(str, "rst")== 0)
  12244. {
  12245. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12246. isSuccess = ConfigurationStatus_Accepted;
  12247. }
  12248. else if(strcmp(str, "rts")== 0)
  12249. {
  12250. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12251. isSuccess = ConfigurationStatus_Accepted;
  12252. }
  12253. else if(strcmp(str, "srt")== 0)
  12254. {
  12255. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12256. isSuccess = ConfigurationStatus_Accepted;
  12257. }
  12258. else if(strcmp(str, "str")== 0)
  12259. {
  12260. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12261. isSuccess = ConfigurationStatus_Accepted;
  12262. }
  12263. else if(strcmp(str, "trs")== 0)
  12264. {
  12265. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12266. isSuccess = ConfigurationStatus_Accepted;
  12267. }
  12268. else if(strcmp(str, "tsr")== 0)
  12269. {
  12270. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12271. isSuccess = ConfigurationStatus_Accepted;
  12272. }
  12273. else
  12274. {
  12275. isSuccess = ConfigurationStatus_Rejected;
  12276. }
  12277. }
  12278. else
  12279. {
  12280. isSuccess = ConfigurationStatus_Rejected;
  12281. }
  12282. }
  12283. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12284. {
  12285. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12286. {
  12287. check_ascii = value[0];
  12288. if( (check_ascii < 48) || (check_ascii > 57) )
  12289. {
  12290. isSuccess = ConfigurationStatus_Rejected;
  12291. }
  12292. else
  12293. {
  12294. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12295. isSuccess = ConfigurationStatus_Accepted;
  12296. }
  12297. }
  12298. else
  12299. {
  12300. isSuccess = ConfigurationStatus_Rejected;
  12301. }
  12302. }
  12303. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12304. {
  12305. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12306. {
  12307. strcpy(str, (const char*)value);
  12308. for(int i = 0; str[i]; i++)
  12309. {
  12310. str[i] = tolower(str[i]);
  12311. }
  12312. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12313. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12314. isSuccess = ConfigurationStatus_Accepted;
  12315. }
  12316. else
  12317. {
  12318. isSuccess = ConfigurationStatus_Rejected;
  12319. }
  12320. }
  12321. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12322. {
  12323. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12324. {
  12325. strcpy(str, (const char*)value);
  12326. for(int i = 0; str[i]; i++)
  12327. {
  12328. str[i] = tolower(str[i]);
  12329. }
  12330. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12331. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12332. isSuccess = ConfigurationStatus_Accepted;
  12333. }
  12334. else
  12335. {
  12336. isSuccess = ConfigurationStatus_Rejected;
  12337. }
  12338. }
  12339. if(strcmp(key, "StopTxnAlignedData") == 0)
  12340. {
  12341. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12342. {
  12343. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12344. isSuccess = ConfigurationStatus_Accepted;
  12345. }
  12346. else
  12347. {
  12348. isSuccess = ConfigurationStatus_Rejected;
  12349. }
  12350. }
  12351. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12352. {
  12353. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12354. {
  12355. check_ascii = value[0];
  12356. if( (check_ascii < 48) || (check_ascii > 57) )
  12357. {
  12358. isSuccess = ConfigurationStatus_Rejected;
  12359. }
  12360. else
  12361. {
  12362. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12363. isSuccess = ConfigurationStatus_Accepted;
  12364. }
  12365. }
  12366. else
  12367. {
  12368. isSuccess = ConfigurationStatus_Rejected;
  12369. }
  12370. }
  12371. if(strcmp(key, "StopTxnSampledData") == 0)
  12372. {
  12373. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12374. {
  12375. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12376. isSuccess = ConfigurationStatus_Accepted;
  12377. }
  12378. else
  12379. {
  12380. isSuccess = ConfigurationStatus_Rejected;
  12381. }
  12382. }
  12383. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12384. {
  12385. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12386. {
  12387. check_ascii = value[0];
  12388. if( (check_ascii < 48) || (check_ascii > 57) )
  12389. {
  12390. isSuccess = ConfigurationStatus_Rejected;
  12391. }
  12392. else
  12393. {
  12394. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12395. isSuccess = ConfigurationStatus_Accepted;
  12396. }
  12397. }
  12398. else
  12399. {
  12400. isSuccess = ConfigurationStatus_Rejected;
  12401. }
  12402. }
  12403. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12404. {
  12405. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12406. {
  12407. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12408. isSuccess = ConfigurationStatus_Accepted;
  12409. }
  12410. else
  12411. {
  12412. isSuccess = ConfigurationStatus_Rejected;
  12413. }
  12414. }
  12415. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12416. {
  12417. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12418. {
  12419. check_ascii = value[0];
  12420. if( (check_ascii < 48) || (check_ascii > 57) )
  12421. {
  12422. isSuccess = ConfigurationStatus_Rejected;
  12423. }
  12424. else
  12425. {
  12426. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12427. isSuccess = ConfigurationStatus_Accepted;
  12428. }
  12429. }
  12430. else
  12431. {
  12432. isSuccess = ConfigurationStatus_Rejected;
  12433. }
  12434. }
  12435. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12436. {
  12437. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12438. {
  12439. check_ascii = value[0];
  12440. if( (check_ascii < 48) || (check_ascii > 57) )
  12441. {
  12442. isSuccess = ConfigurationStatus_Rejected;
  12443. }
  12444. else
  12445. {
  12446. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12447. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12448. TransactionMessageAttemptsValue = atoi(value);
  12449. isSuccess = ConfigurationStatus_Accepted;
  12450. }
  12451. }
  12452. else
  12453. {
  12454. isSuccess = ConfigurationStatus_Rejected;
  12455. }
  12456. }
  12457. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12458. {
  12459. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12460. {
  12461. check_ascii = value[0];
  12462. if( (check_ascii < 48) || (check_ascii > 57) )
  12463. {
  12464. isSuccess = ConfigurationStatus_Rejected;
  12465. }
  12466. else
  12467. {
  12468. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12469. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12470. TransactionMessageRetryIntervalValue = atoi(value);
  12471. isSuccess = ConfigurationStatus_Accepted;
  12472. }
  12473. }
  12474. else
  12475. {
  12476. isSuccess = ConfigurationStatus_Rejected;
  12477. }
  12478. }
  12479. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12480. {
  12481. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12482. {
  12483. strcpy(str, (const char*)value);
  12484. for(int i = 0; str[i]; i++)
  12485. {
  12486. str[i] = tolower(str[i]);
  12487. }
  12488. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12489. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12490. isSuccess = ConfigurationStatus_Accepted;
  12491. }
  12492. else
  12493. {
  12494. isSuccess = ConfigurationStatus_Rejected;
  12495. }
  12496. }
  12497. if(strcmp(key, "WebSocketPingInterval") == 0)
  12498. {
  12499. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12500. {
  12501. check_ascii = value[0];
  12502. if( (check_ascii < 48) || (check_ascii > 57) )
  12503. {
  12504. isSuccess = ConfigurationStatus_Rejected;
  12505. }
  12506. else
  12507. {
  12508. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12509. isSuccess = ConfigurationStatus_Accepted;
  12510. }
  12511. }
  12512. else
  12513. {
  12514. isSuccess = ConfigurationStatus_Rejected;
  12515. }
  12516. }
  12517. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  12518. {
  12519. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12520. {
  12521. strcpy(str, (const char*)value);
  12522. for(int i = 0; str[i]; i++)
  12523. {
  12524. str[i] = tolower(str[i]);
  12525. }
  12526. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12527. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12528. isSuccess = ConfigurationStatus_Accepted;
  12529. }
  12530. else
  12531. {
  12532. isSuccess = ConfigurationStatus_Rejected;
  12533. }
  12534. }
  12535. if(strcmp(key, "AuthorizationKey") == 0)
  12536. {
  12537. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  12538. {
  12539. strcpy(str, (const char*)value);
  12540. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  12541. isSuccess = ConfigurationStatus_Accepted;
  12542. }
  12543. else
  12544. {
  12545. isSuccess = ConfigurationStatus_Rejected;
  12546. }
  12547. }
  12548. if(strcmp(key, "SecurityProfile") == 0)
  12549. {
  12550. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  12551. {
  12552. check_ascii = value[0];
  12553. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  12554. {
  12555. isSuccess = ConfigurationStatus_Rejected;
  12556. }
  12557. else if(check_ascii == 0x33)
  12558. {
  12559. isSuccess = NotSupported;
  12560. }
  12561. else
  12562. {
  12563. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  12564. {
  12565. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  12566. isSuccess = ConfigurationStatus_Accepted;
  12567. }
  12568. else
  12569. isSuccess = ConfigurationStatus_Rejected;
  12570. }
  12571. }
  12572. else
  12573. {
  12574. isSuccess = ConfigurationStatus_Rejected;
  12575. }
  12576. }
  12577. if(strcmp(key, "DefaultPrice") == 0)
  12578. {
  12579. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  12580. {
  12581. strcpy(str, (const char*)value);
  12582. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  12583. isSuccess = ConfigurationStatus_Accepted;
  12584. }
  12585. else
  12586. {
  12587. isSuccess = ConfigurationStatus_Rejected;
  12588. }
  12589. }
  12590. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  12591. {
  12592. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  12593. {
  12594. strcpy(str, (const char*)value);
  12595. for(int i = 0; str[i]; i++)
  12596. {
  12597. str[i] = tolower(str[i]);
  12598. }
  12599. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12600. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12601. isSuccess = ConfigurationStatus_Accepted;
  12602. }
  12603. else
  12604. {
  12605. isSuccess = ConfigurationStatus_Rejected;
  12606. }
  12607. }
  12608. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  12609. {
  12610. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  12611. {
  12612. strcpy(str, (const char*)value);
  12613. for(int i = 0; str[i]; i++)
  12614. {
  12615. str[i] = tolower(str[i]);
  12616. }
  12617. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12618. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12619. isSuccess = ConfigurationStatus_Accepted;
  12620. }
  12621. else
  12622. {
  12623. isSuccess = ConfigurationStatus_Rejected;
  12624. }
  12625. }
  12626. #if 0
  12627. //For OCPP Test Case
  12628. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12629. {
  12630. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12631. {
  12632. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12633. isSuccess = ConfigurationStatus_Accepted;
  12634. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12635. }
  12636. else
  12637. {
  12638. isSuccess = ConfigurationStatus_Rejected;
  12639. }
  12640. }
  12641. #endif
  12642. #if 1
  12643. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12644. {
  12645. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12646. {
  12647. strcpy(str, (const char*)value);
  12648. for(int i = 0; str[i]; i++)
  12649. {
  12650. str[i] = tolower(str[i]);
  12651. }
  12652. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12653. isSuccess = ConfigurationStatus_Accepted;
  12654. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12655. }
  12656. else
  12657. {
  12658. isSuccess = ConfigurationStatus_Rejected;
  12659. }
  12660. }
  12661. #endif
  12662. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12663. {
  12664. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12665. {
  12666. check_ascii = value[0];
  12667. if( (check_ascii < 48) || (check_ascii > 57) )
  12668. {
  12669. isSuccess = ConfigurationStatus_Rejected;
  12670. }
  12671. else
  12672. {
  12673. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12674. isSuccess = ConfigurationStatus_Accepted;
  12675. }
  12676. }
  12677. else
  12678. {
  12679. isSuccess = ConfigurationStatus_Rejected;
  12680. }
  12681. }
  12682. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12683. {
  12684. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12685. {
  12686. check_ascii = value[0];
  12687. if( (check_ascii < 48) || (check_ascii > 57) )
  12688. {
  12689. isSuccess = ConfigurationStatus_Rejected;
  12690. }
  12691. else
  12692. {
  12693. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12694. isSuccess = ConfigurationStatus_Accepted;
  12695. }
  12696. }
  12697. else
  12698. {
  12699. isSuccess = ConfigurationStatus_Rejected;
  12700. }
  12701. }
  12702. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12703. {
  12704. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12705. {
  12706. strcpy(str, (const char*)value);
  12707. for(int i = 0; str[i]; i++)
  12708. {
  12709. str[i] = tolower(str[i]);
  12710. }
  12711. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12712. isSuccess = ConfigurationStatus_Accepted;
  12713. }
  12714. else
  12715. {
  12716. isSuccess = ConfigurationStatus_Rejected;
  12717. }
  12718. }
  12719. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12720. {
  12721. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12722. {
  12723. check_ascii = value[0];
  12724. if( (check_ascii < 48) || (check_ascii > 57) )
  12725. {
  12726. isSuccess = ConfigurationStatus_Rejected;
  12727. }
  12728. else
  12729. {
  12730. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12731. isSuccess = ConfigurationStatus_Accepted;
  12732. }
  12733. }
  12734. else
  12735. {
  12736. isSuccess = ConfigurationStatus_Rejected;
  12737. }
  12738. }
  12739. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12740. {
  12741. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12742. {
  12743. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12744. isSuccess = ConfigurationStatus_Accepted;
  12745. }
  12746. else
  12747. {
  12748. isSuccess = ConfigurationStatus_Rejected;
  12749. }
  12750. }
  12751. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12752. {
  12753. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12754. {
  12755. check_ascii = value[0];
  12756. if( (check_ascii < 48) || (check_ascii > 57) )
  12757. {
  12758. isSuccess = ConfigurationStatus_Rejected;
  12759. }
  12760. else
  12761. {
  12762. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12763. isSuccess = ConfigurationStatus_Accepted;
  12764. }
  12765. }
  12766. else
  12767. {
  12768. isSuccess = ConfigurationStatus_Rejected;
  12769. }
  12770. }
  12771. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12772. {
  12773. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12774. {
  12775. strcpy(str, (const char*)value);
  12776. for(int i = 0; str[i]; i++)
  12777. {
  12778. str[i] = tolower(str[i]);
  12779. }
  12780. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12781. isSuccess = ConfigurationStatus_Accepted;
  12782. }
  12783. else
  12784. {
  12785. isSuccess = ConfigurationStatus_Rejected;
  12786. }
  12787. }
  12788. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12789. {
  12790. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12791. {
  12792. check_ascii = value[0];
  12793. if( (check_ascii < 48) || (check_ascii > 57) )
  12794. {
  12795. isSuccess = ConfigurationStatus_Rejected;
  12796. }
  12797. else
  12798. {
  12799. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12800. isSuccess = ConfigurationStatus_Accepted;
  12801. }
  12802. }
  12803. else
  12804. {
  12805. isSuccess = ConfigurationStatus_Rejected;
  12806. }
  12807. }
  12808. return isSuccess;
  12809. }
  12810. int TransactionMessageAttemptsGet(void)
  12811. {
  12812. return TransactionMessageAttemptsValue;
  12813. }
  12814. int FirstHeartBeatResponse(void)
  12815. {
  12816. return FirstHeartBeat;
  12817. }
  12818. int TransactionMessageRetryIntervalGet(void)
  12819. {
  12820. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12821. }
  12822. int ReadHttpStatus(int sock)
  12823. {
  12824. //char c;
  12825. char buff[1024]="",*ptr=buff+1;
  12826. int bytes_received, status;
  12827. DEBUG_INFO("Begin Response ..\n");
  12828. while((bytes_received = recv(sock, ptr, 1, 0))){
  12829. if(bytes_received==-1){
  12830. perror("ReadHttpStatus");
  12831. exit(1);
  12832. }
  12833. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12834. ptr++;
  12835. }
  12836. *ptr=0;
  12837. ptr=buff+1;
  12838. sscanf(ptr,"%*s %d ", &status);
  12839. DEBUG_INFO("%s\n",ptr);
  12840. DEBUG_INFO("status=%d\n",status);
  12841. DEBUG_INFO("End Response ..\n");
  12842. return (bytes_received>0)?status:0;
  12843. }
  12844. //the only filed that it parsed is 'Content-Length'
  12845. int ParseHeader(int sock)
  12846. {
  12847. //char c;
  12848. char buff[1024]="",*ptr=buff+4;
  12849. int bytes_received;
  12850. DEBUG_INFO("Begin HEADER ..\n");
  12851. while((bytes_received = recv(sock, ptr, 1, 0))){
  12852. if(bytes_received==-1){
  12853. perror("Parse Header");
  12854. exit(1);
  12855. }
  12856. if(
  12857. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12858. (ptr[-1]=='\r') && (*ptr=='\n' )
  12859. ) break;
  12860. ptr++;
  12861. }
  12862. *ptr=0;
  12863. ptr=buff+4;
  12864. //printf("%s",ptr);
  12865. if(bytes_received){
  12866. ptr=strstr(ptr,"Content-Length:");
  12867. if(ptr){
  12868. sscanf(ptr,"%*s %d",&bytes_received);
  12869. }else
  12870. bytes_received=-1; //unknown size
  12871. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12872. }
  12873. DEBUG_INFO("End HEADER ..\n");
  12874. return bytes_received ;
  12875. }
  12876. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12877. {
  12878. char rmFileCmd[100]={0};
  12879. char FilePath[100]={0};
  12880. char ftpbuf[200];
  12881. int systemresult;
  12882. //DEBUG_INFO("filename=%s\n",filename);
  12883. //DEBUG_INFO("url=%s\n",url);
  12884. sprintf(FilePath,"/mnt/%s",filename);
  12885. system("ping 8.8.8.8 &");
  12886. if((access(FilePath,F_OK))!=-1)
  12887. {
  12888. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12889. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12890. system(rmFileCmd);
  12891. }
  12892. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12893. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  12894. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12895. systemresult = system(ftpbuf);
  12896. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12897. if(systemresult != 0)
  12898. {
  12899. DEBUG_INFO("http DownLoad error!\n");
  12900. return FALSE;
  12901. }
  12902. system("pkill ping");
  12903. return TRUE;
  12904. }
  12905. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12906. {
  12907. char rmFileCmd[100]={0};
  12908. char FilePath[100]={0};
  12909. char ftpbuf[200];
  12910. int systemresult;
  12911. //char temp[100];
  12912. sprintf(FilePath,"/mnt/%s",filename);
  12913. system("ping 8.8.8.8 &");
  12914. if((access(FilePath,F_OK))!=-1)
  12915. {
  12916. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12917. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12918. system(rmFileCmd);
  12919. }
  12920. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12921. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  12922. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12923. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12924. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12925. systemresult = system(ftpbuf);
  12926. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12927. if(systemresult != 0)
  12928. {
  12929. printf("wget error!\n");
  12930. return FALSE;
  12931. }
  12932. system("pkill ping");
  12933. return TRUE;
  12934. }
  12935. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12936. {
  12937. char rmFileCmd[100]={0};
  12938. char FilePath[100]={0};
  12939. char ftpbuf[200];
  12940. int systemresult;
  12941. //DEBUG_INFO("filename=%s\n",filename);
  12942. //DEBUG_INFO("url=%s\n",url);
  12943. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12944. if((access(FilePath,F_OK))!=-1)
  12945. {
  12946. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12947. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12948. system(rmFileCmd);
  12949. }
  12950. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12951. if(fp == NULL)
  12952. {
  12953. DEBUG_INFO("log is NULL\n");
  12954. return FALSE;
  12955. }
  12956. else
  12957. {
  12958. fprintf(fp, "%s\n", url);
  12959. fprintf(fp, "%s\n", filename);
  12960. fclose(fp);
  12961. }
  12962. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12963. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12964. systemresult = system(ftpbuf);
  12965. DEBUG_INFO("systemresult = %d\n",systemresult);
  12966. if(systemresult != 0)
  12967. {
  12968. DEBUG_INFO("http upload error!\n");
  12969. return FALSE;
  12970. }
  12971. return TRUE;
  12972. }
  12973. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12974. {
  12975. struct hostent* server;
  12976. char *IPbuffer;
  12977. char ftpbuf[200];
  12978. int systemresult;
  12979. // To retrieve host information
  12980. server = gethostbyname(location);
  12981. // To convert an Internet network
  12982. // address into ASCII string
  12983. IPbuffer = inet_ntoa(*((struct in_addr*)
  12984. server->h_addr_list[0]));
  12985. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12986. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12987. /* format : ftpput -u username -p passwd IP target source*/
  12988. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12989. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12990. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12991. systemresult = system(ftpbuf);
  12992. DEBUG_INFO("systemresult=%d\n",systemresult);
  12993. if(systemresult != 0)
  12994. {
  12995. DEBUG_INFO("ftpput error!\n");
  12996. return FALSE;
  12997. }
  12998. return TRUE;
  12999. }
  13000. /**
  13001. * Place the contents of the specified file into a memory buffer
  13002. *
  13003. * @param[in] filename The path and name of the file to read
  13004. * @param[out] filebuffer A pointer to the contents in memory
  13005. * @return status 0 success, 1 on failure
  13006. */
  13007. int get_file_contents(const char* filename, char** outbuffer) {
  13008. FILE* file = NULL;
  13009. long filesize;
  13010. const int blocksize = 1;
  13011. size_t readsize;
  13012. char* filebuffer;
  13013. // Open the file
  13014. file = fopen(filename, "r");
  13015. if (NULL == file)
  13016. {
  13017. printf("'%s' not opened\n", filename);
  13018. exit(EXIT_FAILURE);
  13019. }
  13020. // Determine the file size
  13021. fseek(file, 0, SEEK_END);
  13022. filesize = ftell(file);
  13023. rewind (file);
  13024. // Allocate memory for the file contents
  13025. filebuffer = (char*) malloc(sizeof(char) * filesize);
  13026. *outbuffer = filebuffer;
  13027. if (filebuffer == NULL)
  13028. {
  13029. fputs ("malloc out-of-memory", stderr);
  13030. exit(EXIT_FAILURE);
  13031. }
  13032. // Read in the file
  13033. readsize = fread(filebuffer, blocksize, filesize, file);
  13034. if (readsize != filesize)
  13035. {
  13036. fputs ("didn't read file completely",stderr);
  13037. exit(EXIT_FAILURE);
  13038. }
  13039. // Clean exit
  13040. fclose(file);
  13041. return EXIT_SUCCESS;
  13042. }
  13043. static int selectSqlCount = 0;
  13044. static int callback(void *data, int argc, char **argv, char **azColName){
  13045. int i;
  13046. //printf("%s: ", (const char*)data);
  13047. selectSqlCount = argc;
  13048. for(i = 0; i<argc; i++){
  13049. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  13050. }
  13051. //printf("\n");
  13052. return 0;
  13053. }
  13054. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  13055. //int i;
  13056. //printf("%s:\n", (const char*)data);
  13057. localversion = argv[5] ? atoi(argv[5]) : 0;
  13058. //printf("localversion=%d\n", localversion);
  13059. return 0;
  13060. }
  13061. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  13062. //printf("%s:\n", (const char*)data);
  13063. //idTag
  13064. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  13065. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  13066. //parentIdTag
  13067. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  13068. //expir_date
  13069. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  13070. //status
  13071. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  13072. //version
  13073. if(columenCount > 5)
  13074. idTagQuery.listVersionInt = atoi(columnValue[5]);
  13075. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  13076. return 0;
  13077. }
  13078. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  13079. {
  13080. // localversion = argv[5] ? atoi(argv[5]) : 0;
  13081. // printf("localversion=%d\n", localversion);
  13082. return 0;
  13083. }
  13084. //=========================================
  13085. // Sqlite3 related function
  13086. //=========================================
  13087. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  13088. {
  13089. for (int i = 0; i < n_columns; i++)
  13090. {
  13091. DEBUG_INFO("%s\t", col_values[i]);
  13092. }
  13093. DEBUG_INFO("\n");
  13094. return 0;
  13095. }
  13096. int OCPP_cleanLocalCache()
  13097. {
  13098. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  13099. char *errMsg = 0;
  13100. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  13101. if (SQLITE_OK != rc)
  13102. {
  13103. DEBUG_INFO("SQL error: %s\n",errMsg);
  13104. return FALSE;
  13105. }
  13106. return TRUE;
  13107. }
  13108. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  13109. {
  13110. int isSuccess = TRUE;
  13111. int ret = 0;
  13112. //const char* data = "Callback function called";
  13113. char sql[300];
  13114. char zErrMsg[200];
  13115. memset(sql, 0, 300);
  13116. memset(zErrMsg, 0, 200);
  13117. 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);
  13118. //* Execute SQL statement */
  13119. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  13120. if( ret != SQLITE_OK )
  13121. {
  13122. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13123. isSuccess = FALSE;
  13124. }
  13125. return isSuccess;
  13126. }
  13127. void OCPP_getIdTagFromLocalCache(char idTag[])
  13128. {
  13129. int rc = 0;
  13130. char sql[100];
  13131. char zErrMsg[100];
  13132. memset(sql, 0, 100);
  13133. memset(zErrMsg, 0, 100);
  13134. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  13135. memset(&idTagQuery, 0, sizeof(idTagQuery));
  13136. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  13137. /* Execute SQL statement */
  13138. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  13139. if( rc != SQLITE_OK )
  13140. {
  13141. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13142. }
  13143. }
  13144. void OCPP_getListVerion()
  13145. {
  13146. int rc = 0;
  13147. // const char* data = "Callback function called";
  13148. char sql[100];
  13149. char zErrMsg[100];
  13150. memset(sql, 0, 100);
  13151. memset(zErrMsg, 0, 100);
  13152. strcpy(sql, "select * from ocpp_auth_local order by idx");
  13153. /* Execute SQL statement */
  13154. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  13155. if( rc != SQLITE_OK )
  13156. {
  13157. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13158. }
  13159. }
  13160. void OCPP_get_TableAuthlocalAllData(void)
  13161. {
  13162. int rc = 0;
  13163. char sql[100];
  13164. char zErrMsg[100];
  13165. memset(sql, 0, 100);
  13166. memset(zErrMsg, 0, 100);
  13167. sprintf(sql,"select * from ocpp_auth_local ");
  13168. /* Execute SQL statement */
  13169. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  13170. if( rc != SQLITE_OK )
  13171. {
  13172. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13173. }
  13174. //return ver;
  13175. }
  13176. int OCPP_cleanLocalList()
  13177. {
  13178. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  13179. char *errMsg = 0;
  13180. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  13181. if (SQLITE_OK != rc)
  13182. {
  13183. DEBUG_INFO("%s\n",errMsg);
  13184. return FALSE;
  13185. }
  13186. return TRUE;
  13187. }
  13188. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  13189. {
  13190. int isSuccess = FALSE;
  13191. int ret = 0;
  13192. //const char* data = "Callback function called";
  13193. char sql[300];
  13194. char zErrMsg[200];
  13195. memset(sql, 0, 300);
  13196. memset(zErrMsg, 0, 200);
  13197. 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);
  13198. //* Execute SQL statement */
  13199. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  13200. if( ret != SQLITE_OK )
  13201. {
  13202. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13203. return isSuccess;
  13204. }
  13205. memset(sql, 0, 300);
  13206. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  13207. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  13208. if( ret != SQLITE_OK )
  13209. {
  13210. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13211. return isSuccess;
  13212. }
  13213. isSuccess = TRUE;
  13214. return isSuccess;
  13215. }
  13216. void OCPP_getIdTagFromLocalList(char idTag[])
  13217. {
  13218. int rc = 0;
  13219. // const char* data = "Callback function called";
  13220. char sql[100];
  13221. char zErrMsg[100];
  13222. memset(sql, 0, 100);
  13223. memset(zErrMsg, 0, 100);
  13224. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  13225. memset(&idTagQuery, 0, sizeof(idTagQuery));
  13226. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  13227. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  13228. /* Execute SQL statement */
  13229. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  13230. if( rc != SQLITE_OK )
  13231. {
  13232. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13233. }
  13234. //return ver;
  13235. }
  13236. void OCPP_deleteIdTagFromLocalList(char idTag[])
  13237. {
  13238. //int ver = 0;
  13239. //int isSuccess = FALSE;
  13240. int rc = 0;
  13241. char sql[100];
  13242. char zErrMsg[100];
  13243. memset(sql, 0, 100);
  13244. memset(zErrMsg, 0, 100);
  13245. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  13246. //* Execute SQL statement */
  13247. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  13248. if( rc != SQLITE_OK )
  13249. {
  13250. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13251. }
  13252. }
  13253. int GetOcppServerURL()
  13254. {
  13255. int result = FALSE;
  13256. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  13257. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  13258. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  13259. struct yuarel url;
  13260. char urlStr[512];
  13261. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  13262. {
  13263. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  13264. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13265. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  13266. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  13267. if(yuarel_parse(&url, urlStr) != -1)
  13268. {
  13269. sprintf(OcppProtocol, "%s", url.scheme);
  13270. sprintf(OcppHost, "%s", url.host);
  13271. if(url.path == NULL)
  13272. OcppTempPath[0] = '\0';
  13273. else
  13274. {
  13275. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  13276. {
  13277. sprintf(OcppTempPath, "%s/", url.path);
  13278. }
  13279. else
  13280. {
  13281. sprintf(OcppTempPath, "%s", url.path);
  13282. }
  13283. }
  13284. if(url.port == 0)
  13285. {
  13286. if(strcmp(OcppProtocol, "wss") == 0)
  13287. OcppPort = 443;
  13288. else
  13289. OcppPort = 80;
  13290. }
  13291. else
  13292. OcppPort = url.port;
  13293. result = TRUE;
  13294. }
  13295. }
  13296. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  13297. {
  13298. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  13299. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13300. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  13301. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  13302. if(yuarel_parse(&url, urlStr) != -1)
  13303. {
  13304. sprintf(OcppProtocol, "%s", url.scheme);
  13305. sprintf(OcppHost, "%s", url.host);
  13306. if(url.path == NULL)
  13307. OcppTempPath[0] = '\0';
  13308. else
  13309. sprintf(OcppTempPath, "%s", url.path);
  13310. if(url.port == 0)
  13311. {
  13312. if(strcmp(OcppProtocol, "wss") == 0)
  13313. OcppPort = 443;
  13314. else
  13315. OcppPort = 80;
  13316. }
  13317. else
  13318. OcppPort = url.port;
  13319. result = TRUE;
  13320. }
  13321. }
  13322. else
  13323. {
  13324. strcpy(OcppHost,"");
  13325. }
  13326. return result;
  13327. }
  13328. int GetOcppPath()
  13329. {
  13330. int result = FALSE;
  13331. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  13332. {
  13333. if(OcppTempPath == NULL)
  13334. {
  13335. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13336. }
  13337. else
  13338. {
  13339. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13340. }
  13341. result = TRUE;
  13342. goto End;
  13343. }
  13344. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  13345. {
  13346. if(OcppTempPath == NULL)
  13347. {
  13348. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  13349. }
  13350. else
  13351. {
  13352. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  13353. }
  13354. result = TRUE;
  13355. goto End;
  13356. }
  13357. else
  13358. {
  13359. strcpy(OcppPath,"");
  13360. }
  13361. End:
  13362. return result;
  13363. }
  13364. int GetOcppPort()
  13365. {
  13366. return OcppPort;
  13367. }
  13368. int GetOcppConnStatus(void)
  13369. {
  13370. return ShmOCPP16Data->OcppConnStatus;
  13371. }
  13372. void SetOcppConnStatus(uint8_t status)
  13373. {
  13374. ShmOCPP16Data->OcppConnStatus = status;
  13375. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  13376. }
  13377. int GetHeartBeatWithNOResponse(void)
  13378. {
  13379. return HeartBeatWithNOResponse;
  13380. }
  13381. void SetHeartBeatWithNOResponse(void)
  13382. {
  13383. HeartBeatWithNOResponse = 0;
  13384. }
  13385. void GetStartTransactionIdTag(int gun_index)
  13386. {
  13387. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  13388. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13389. }
  13390. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  13391. {
  13392. char ch;
  13393. FILE *fptr1;
  13394. int temptransactionId;
  13395. char str[100]={0};
  13396. temptransactionId = 0;
  13397. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  13398. {
  13399. DEBUG_INFO("IdTag is empty.\n");
  13400. return temptransactionId;
  13401. }
  13402. /*------ Read the file ----------------*/
  13403. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  13404. if (!fptr1)
  13405. {
  13406. DEBUG_INFO("QueueTransactionId file open error.\n");
  13407. //printf(" File not found or unable to open the input file!!\n");
  13408. return temptransactionId;
  13409. }
  13410. ch=fgetc(fptr1);
  13411. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13412. rewind(fptr1);
  13413. if(ch!=EOF)
  13414. {
  13415. // printf("%c",ch);
  13416. while (fgets(str, 100, fptr1) != NULL)
  13417. {
  13418. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13419. if(str[0]=='\0')
  13420. {
  13421. break;
  13422. }
  13423. char *revbuf[8] = {0}; // Variable store string split
  13424. int num = 0;// Quantity after string split
  13425. DEBUG_INFO("Transaction queue data= %s\n", str);
  13426. splitstring(str,",",revbuf,&num); // String split
  13427. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  13428. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  13429. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  13430. DEBUG_INFO("------------------------------\n");
  13431. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13432. {
  13433. if(isStopTransaction)
  13434. {
  13435. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  13436. {
  13437. temptransactionId = atoi(revbuf[2]);
  13438. //break;
  13439. }
  13440. }
  13441. else
  13442. {
  13443. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13444. {
  13445. temptransactionId = atoi(revbuf[2]);
  13446. //break;
  13447. }
  13448. }
  13449. }
  13450. }
  13451. }
  13452. else
  13453. DEBUG_INFO("EOF\n");
  13454. fclose(fptr1);
  13455. /*------- End of reading ---------------*/
  13456. return temptransactionId;
  13457. }
  13458. void SetTransactionIdZero(int transactionId)
  13459. {
  13460. char ch;
  13461. FILE *fptr1, *fptr2;
  13462. int temptransactionId = 0;
  13463. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13464. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13465. if (!fptr1)
  13466. {
  13467. //printf(" File not found or unable to open the input file!!\n");
  13468. return ;
  13469. }
  13470. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13471. if (!fptr2)
  13472. {
  13473. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  13474. fclose(fptr1);
  13475. return ;
  13476. }
  13477. ch=fgetc(fptr1);
  13478. rewind(fptr1);
  13479. if(ch!=EOF)
  13480. {
  13481. // copy all contents to the temporary file except the specific line
  13482. while (fgets(str, 100, fptr1) != NULL)
  13483. {
  13484. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13485. if(str[0]=='\0')
  13486. {
  13487. break;
  13488. }
  13489. char *revbuf[8] = {0};
  13490. int num = 0;
  13491. strcpy(strtemp, str);
  13492. splitstring(str,",",revbuf,&num);
  13493. if(revbuf[2][0] != '\0')
  13494. {
  13495. temptransactionId = atoi(revbuf[2]);
  13496. if(transactionId != temptransactionId)
  13497. {
  13498. fprintf(fptr2, "%s\n", strtemp);
  13499. }
  13500. }
  13501. }
  13502. }
  13503. fclose(fptr1);
  13504. fclose(fptr2);
  13505. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13506. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13507. /*------ Read the file ----------------*/
  13508. }
  13509. int InternetDisconnect(void)
  13510. {
  13511. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13512. }
  13513. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  13514. void storeTempStopTransaction(int gun_index)
  13515. {
  13516. char guid[37]={0};
  13517. int tempIndex = 0;
  13518. char TempStopTransaction[256];
  13519. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  13520. DEBUG_INFO("storeTempStopTransaction...\n");
  13521. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  13522. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  13523. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  13524. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13525. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  13526. {
  13527. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13528. {
  13529. tempIndex = ((gun_index==2) ? 1: 0);
  13530. }
  13531. else
  13532. {
  13533. tempIndex = gun_index;
  13534. }
  13535. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13536. {
  13537. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13538. {
  13539. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  13540. }
  13541. }// END OF CHAdeMO_QUANTITY
  13542. }
  13543. else if(gunType[gun_index] == GUN_TYPE_CCS)
  13544. {
  13545. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13546. {
  13547. tempIndex = ((gun_index==2) ? 1: 0);
  13548. }
  13549. else
  13550. {
  13551. tempIndex = gun_index;
  13552. }
  13553. for (int index = 0; index < CCS_QUANTITY; index++)
  13554. {
  13555. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13556. {
  13557. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  13558. }
  13559. }// END OF CCS_QUANTITY
  13560. }
  13561. else if(gunType[gun_index] == GUN_TYPE_GBT)
  13562. {
  13563. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13564. {
  13565. tempIndex = ((gun_index==2) ? 1: 0);
  13566. }
  13567. else
  13568. {
  13569. tempIndex = gun_index;
  13570. }
  13571. for (int index = 0; index < GB_QUANTITY; index++)
  13572. {
  13573. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13574. {
  13575. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  13576. }
  13577. }// END OF GB_QUANTITY
  13578. }
  13579. else if(gunType[gun_index] == GUN_TYPE_DO)
  13580. {
  13581. tempIndex = gun_index;
  13582. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13583. {
  13584. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13585. {
  13586. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  13587. }
  13588. }
  13589. }
  13590. else
  13591. {
  13592. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13593. {
  13594. tempIndex = 2;
  13595. }
  13596. else
  13597. {
  13598. tempIndex = gun_index;
  13599. }
  13600. for (int index = 0; index < AC_QUANTITY; index++)
  13601. {
  13602. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13603. {
  13604. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  13605. }
  13606. }// END OF AC_QUANTITY
  13607. }
  13608. //Stop Transaction Time
  13609. struct timeval tmnow;
  13610. struct tm *tm;
  13611. char buf[28];//, usec_buf[6];
  13612. gettimeofday(&tmnow, NULL);
  13613. time_t t;
  13614. t = time(NULL);
  13615. /*UTC time and date*/
  13616. tm = gmtime(&t);
  13617. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  13618. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  13619. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  13620. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13621. random_uuid(guid);
  13622. /***********************************transactionData******************************************************/
  13623. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  13624. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  13625. //=================================
  13626. //1. Transaction_Begin
  13627. //=================================
  13628. //============================== Energy.Active.Import.Interval ===========================================
  13629. //idx_sample=0;
  13630. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  13631. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  13632. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  13633. 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*/]);
  13634. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13635. 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))
  13636. {
  13637. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  13638. }
  13639. else
  13640. {
  13641. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  13642. }
  13643. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  13644. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13645. //=================================
  13646. //2. Transaction_End
  13647. //=================================
  13648. //2.1====================================== Current.Import L1 ==============================================
  13649. //idx_sample=1;
  13650. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  13651. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  13652. {
  13653. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13654. {
  13655. tempIndex = ((gun_index==2) ? 1: 0);
  13656. }
  13657. else
  13658. {
  13659. tempIndex = gun_index;
  13660. }
  13661. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13662. {
  13663. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13664. {
  13665. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13666. }
  13667. }// End of for CHAdeMO_QUANTITY
  13668. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13669. }
  13670. else if(gunType[gun_index] == GUN_TYPE_CCS)
  13671. {
  13672. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13673. {
  13674. tempIndex = ((gun_index==2) ? 1: 0);
  13675. }
  13676. else
  13677. {
  13678. tempIndex = gun_index;
  13679. }
  13680. for (int index = 0; index < CCS_QUANTITY; index++)
  13681. {
  13682. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13683. {
  13684. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13685. }
  13686. }// End of for CCS_QUANTITY
  13687. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13688. }
  13689. else if(gunType[gun_index] == GUN_TYPE_GBT)
  13690. {
  13691. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13692. {
  13693. tempIndex = ((gun_index==2) ? 1: 0);
  13694. }
  13695. else
  13696. {
  13697. tempIndex = gun_index;
  13698. }
  13699. for (int index = 0; index < GB_QUANTITY; index++)
  13700. {
  13701. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13702. {
  13703. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13704. }
  13705. }// End of for GB_QUANTITY
  13706. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13707. }
  13708. else if(gunType[gun_index] == GUN_TYPE_DO)
  13709. {
  13710. tempIndex = gun_index;
  13711. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13712. {
  13713. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13714. {
  13715. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13716. }
  13717. }
  13718. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13719. }
  13720. else
  13721. {
  13722. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13723. {
  13724. tempIndex = 2;
  13725. }
  13726. else
  13727. {
  13728. tempIndex = gun_index;
  13729. }
  13730. for (int index = 0; index < AC_QUANTITY; index++)
  13731. {
  13732. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13733. {
  13734. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  13735. }
  13736. }// End of for AC_QUANTITY
  13737. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13738. }
  13739. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13740. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  13741. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  13742. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13743. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  13744. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13745. //2.2===================================== Energy.Active.Import.Interval ==========================================
  13746. //idx_sample=2;
  13747. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13748. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  13749. {
  13750. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13751. {
  13752. tempIndex = ((gun_index==2) ? 1: 0);
  13753. }
  13754. else
  13755. {
  13756. tempIndex = gun_index;
  13757. }
  13758. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13759. {
  13760. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13761. {
  13762. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13763. }
  13764. }// END OF CHAdeMO_QUANTITY
  13765. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13766. }
  13767. else if(gunType[gun_index] == GUN_TYPE_CCS)
  13768. {
  13769. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13770. {
  13771. tempIndex = ((gun_index==2) ? 1: 0);
  13772. }
  13773. else
  13774. {
  13775. tempIndex = gun_index;
  13776. }
  13777. for (int index = 0; index < CCS_QUANTITY; index++)
  13778. {
  13779. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13780. {
  13781. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13782. }
  13783. }// END OF CCS_QUANTITY
  13784. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13785. }
  13786. else if(gunType[gun_index] == GUN_TYPE_GBT)
  13787. {
  13788. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13789. {
  13790. tempIndex = ((gun_index==2) ? 1: 0);
  13791. }
  13792. else
  13793. {
  13794. tempIndex = gun_index;
  13795. }
  13796. for (int index = 0; index < GB_QUANTITY; index++)
  13797. {
  13798. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13799. {
  13800. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13801. }
  13802. }// END OF GB_QUANTITY
  13803. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13804. }
  13805. else if(gunType[gun_index] == GUN_TYPE_DO)
  13806. {
  13807. tempIndex = gun_index;
  13808. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13809. {
  13810. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13811. {
  13812. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13813. }
  13814. }
  13815. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13816. }
  13817. else
  13818. {
  13819. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13820. {
  13821. tempIndex = 2;
  13822. }
  13823. else
  13824. {
  13825. tempIndex = gun_index;
  13826. }
  13827. for (int index = 0; index < AC_QUANTITY; index++)
  13828. {
  13829. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13830. {
  13831. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13832. }
  13833. }// END OF AC_QUANTITY
  13834. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13835. }
  13836. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13837. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  13838. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  13839. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13840. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  13841. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13842. //2.3====================================== Power.Active.Import =========================================
  13843. //idx_sample=3;
  13844. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13845. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  13846. {
  13847. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13848. {
  13849. tempIndex = ((gun_index==2) ? 1: 0);
  13850. }
  13851. else
  13852. {
  13853. tempIndex = gun_index;
  13854. }
  13855. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13856. {
  13857. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13858. {
  13859. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13860. }
  13861. } // End for CHAdeMO_QUANTITY
  13862. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13863. }
  13864. else if(gunType[gun_index] == GUN_TYPE_CCS)
  13865. {
  13866. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13867. {
  13868. tempIndex = ((gun_index==2) ? 1: 0);
  13869. }
  13870. else
  13871. {
  13872. tempIndex = gun_index;
  13873. }
  13874. for (int index = 0; index < CCS_QUANTITY; index++)
  13875. {
  13876. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13877. {
  13878. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13879. }
  13880. } // END for CCS_QUANTITY
  13881. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13882. }
  13883. else if(gunType[gun_index] == GUN_TYPE_GBT)
  13884. {
  13885. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13886. {
  13887. tempIndex = ((gun_index==2) ? 1: 0);
  13888. }
  13889. else
  13890. {
  13891. tempIndex = gun_index;
  13892. }
  13893. for (int index = 0; index < GB_QUANTITY; index++)
  13894. {
  13895. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13896. {
  13897. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13898. }
  13899. }// END for GB_QUANTITY
  13900. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13901. }
  13902. else if(gunType[gun_index] == GUN_TYPE_DO)
  13903. {
  13904. tempIndex = gun_index;
  13905. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13906. {
  13907. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13908. {
  13909. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13910. }
  13911. }
  13912. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13913. }
  13914. else
  13915. {
  13916. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13917. {
  13918. tempIndex = 2;
  13919. }
  13920. else
  13921. {
  13922. tempIndex = gun_index;
  13923. }
  13924. for (int index = 0; index < AC_QUANTITY; index++)
  13925. {
  13926. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13927. {
  13928. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13929. }
  13930. } // END for AC_QUANTITY
  13931. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13932. }
  13933. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13934. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  13935. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  13936. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13937. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  13938. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  13939. //2.4====================================== Voltage L1 ====================================================
  13940. //idx_sample=4;
  13941. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13942. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  13943. {
  13944. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13945. {
  13946. tempIndex = ((gun_index==2) ? 1: 0);
  13947. }
  13948. else
  13949. {
  13950. tempIndex = gun_index;
  13951. }
  13952. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13953. {
  13954. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13955. {
  13956. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13957. }
  13958. } // END OF FOR CHAdeMO_QUANTITY
  13959. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13960. }
  13961. else if(gunType[gun_index] == GUN_TYPE_CCS)
  13962. {
  13963. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13964. {
  13965. tempIndex = ((gun_index==2) ? 1: 0);
  13966. }
  13967. else
  13968. {
  13969. tempIndex = gun_index;
  13970. }
  13971. for (int index = 0; index < CCS_QUANTITY; index++)
  13972. {
  13973. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13974. {
  13975. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13976. }
  13977. } // END OF FOR CCS_QUANTITY
  13978. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13979. }
  13980. else if(gunType[gun_index] == GUN_TYPE_GBT)
  13981. {
  13982. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13983. {
  13984. tempIndex = ((gun_index==2) ? 1: 0);
  13985. }
  13986. else
  13987. {
  13988. tempIndex = gun_index;
  13989. }
  13990. for (int index = 0; index < GB_QUANTITY; index++)
  13991. {
  13992. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13993. {
  13994. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13995. }
  13996. } // END OF FOR GB_QUANTITY
  13997. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13998. }
  13999. else if(gunType[gun_index] == GUN_TYPE_DO)
  14000. {
  14001. tempIndex = gun_index;
  14002. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14003. {
  14004. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14005. {
  14006. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14007. }
  14008. }
  14009. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14010. }
  14011. else
  14012. {
  14013. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14014. {
  14015. tempIndex = 2;
  14016. }
  14017. else
  14018. {
  14019. tempIndex = gun_index;
  14020. }
  14021. for (int index = 0; index < AC_QUANTITY; index++)
  14022. {
  14023. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14024. {
  14025. 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
  14026. }
  14027. } // END OF FOR AC_QUANTITY
  14028. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  14029. }
  14030. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14031. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  14032. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  14033. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  14034. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  14035. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14036. //2.5============================================== End SoC =========================================================
  14037. //idx_sample=5;
  14038. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14039. 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))
  14040. {
  14041. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  14042. {
  14043. tempIndex = ((gun_index==2) ? 1: 0);
  14044. }
  14045. else
  14046. {
  14047. tempIndex = gun_index;
  14048. }
  14049. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14050. {
  14051. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14052. {
  14053. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14054. {
  14055. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  14056. }
  14057. }
  14058. }
  14059. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14060. {
  14061. for (int index = 0; index < CCS_QUANTITY; index++)
  14062. {
  14063. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14064. {
  14065. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  14066. }
  14067. }
  14068. }
  14069. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14070. {
  14071. for (int index = 0; index < GB_QUANTITY; index++)
  14072. {
  14073. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14074. {
  14075. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  14076. }
  14077. }
  14078. }
  14079. else if(gunType[gun_index] == GUN_TYPE_DO)
  14080. {
  14081. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14082. {
  14083. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14084. {
  14085. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  14086. }
  14087. }
  14088. }
  14089. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14090. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  14091. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  14092. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  14093. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  14094. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  14095. } // END FOR DC CASE
  14096. //2.6====================================== Current.Import L2 ==============================================
  14097. // idx_sample=6;
  14098. // AC 3 phase L2 current
  14099. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14100. {
  14101. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14102. {
  14103. tempIndex = 2;
  14104. }
  14105. else
  14106. {
  14107. tempIndex = gun_index;
  14108. }
  14109. for (int index = 0; index < AC_QUANTITY; index++)
  14110. {
  14111. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14112. {
  14113. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  14114. }
  14115. }// End of for AC_QUANTITY
  14116. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  14117. }
  14118. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14119. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  14120. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  14121. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  14122. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14123. //2.7====================================== Current.Import L3 ==============================================
  14124. // idx_sample=7;
  14125. // AC 3 phase L3 current
  14126. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14127. {
  14128. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14129. {
  14130. tempIndex = 2;
  14131. }
  14132. else
  14133. {
  14134. tempIndex = gun_index;
  14135. }
  14136. for (int index = 0; index < AC_QUANTITY; index++)
  14137. {
  14138. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14139. {
  14140. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  14141. }
  14142. }// End of for AC_QUANTITY
  14143. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  14144. }
  14145. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14146. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  14147. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  14148. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  14149. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14150. //2.9====================================== Voltage L2 ====================================================
  14151. //idx_sample=8;
  14152. // AC 3 phase L2 volatge
  14153. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14154. {
  14155. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14156. {
  14157. tempIndex = 2;
  14158. }
  14159. else
  14160. {
  14161. tempIndex = gun_index;
  14162. }
  14163. for (int index = 0; index < AC_QUANTITY; index++)
  14164. {
  14165. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14166. {
  14167. 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
  14168. }
  14169. } // END OF FOR AC_QUANTITY
  14170. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  14171. }
  14172. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14173. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  14174. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  14175. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  14176. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14177. //2.10====================================== Voltage L3 ====================================================
  14178. //idx_sample=9;
  14179. // AC 3 phase L3 volatge
  14180. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14181. {
  14182. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14183. {
  14184. tempIndex = 2;
  14185. }
  14186. else
  14187. {
  14188. tempIndex = gun_index;
  14189. }
  14190. for (int index = 0; index < AC_QUANTITY; index++)
  14191. {
  14192. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14193. {
  14194. 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
  14195. }
  14196. } // END OF FOR AC_QUANTITY
  14197. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  14198. }
  14199. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14200. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  14201. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  14202. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  14203. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14204. //====================== Start SoC ================================
  14205. //idx_sample=10;
  14206. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14207. 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))
  14208. {
  14209. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  14210. {
  14211. tempIndex = ((gun_index==2) ? 1: 0);
  14212. }
  14213. else
  14214. {
  14215. tempIndex = gun_index;
  14216. }
  14217. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14218. {
  14219. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14220. {
  14221. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14222. {
  14223. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  14224. }
  14225. }
  14226. }
  14227. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14228. {
  14229. for (int index = 0; index < CCS_QUANTITY; index++)
  14230. {
  14231. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14232. {
  14233. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  14234. }
  14235. }
  14236. }
  14237. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14238. {
  14239. for (int index = 0; index < GB_QUANTITY; index++)
  14240. {
  14241. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14242. {
  14243. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  14244. }
  14245. }
  14246. }
  14247. else if(gunType[gun_index] == GUN_TYPE_DO)
  14248. {
  14249. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14250. {
  14251. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14252. {
  14253. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  14254. }
  14255. }
  14256. }
  14257. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  14258. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  14259. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  14260. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  14261. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  14262. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  14263. } // END FOR DC CASE
  14264. //======================================== Message create ==============================================
  14265. json_object *StopTransaction = json_object_new_object();
  14266. json_object *transactionDatas = json_object_new_array();
  14267. json_object *sampledValues = json_object_new_array();
  14268. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  14269. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  14270. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  14271. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  14272. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  14273. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  14274. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  14275. {
  14276. json_object *transactionData = json_object_new_object();
  14277. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  14278. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  14279. {
  14280. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  14281. {
  14282. json_object *sampledValue = json_object_new_object();
  14283. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  14284. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  14285. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  14286. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  14287. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  14288. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  14289. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  14290. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  14291. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  14292. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  14293. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  14294. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  14295. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  14296. json_object_array_add(sampledValues, sampledValue);
  14297. }
  14298. }
  14299. json_object_object_add(transactionData, "sampledValue", sampledValues);
  14300. json_object_array_add(transactionDatas, transactionData);
  14301. }
  14302. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  14303. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  14304. ,MESSAGE_TYPE_CALL
  14305. ,guid
  14306. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  14307. json_object_put(StopTransaction);
  14308. // Check File "TempStopTransaction" Exist
  14309. if((access(TempStopTransaction,F_OK))!=-1)
  14310. {
  14311. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  14312. fclose(fopen(TempStopTransaction, "w"));
  14313. }
  14314. else
  14315. {
  14316. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  14317. FILE *log = fopen(TempStopTransaction, "w+");
  14318. if(log == NULL)
  14319. {
  14320. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  14321. return ;
  14322. }
  14323. else
  14324. {
  14325. fclose(log);
  14326. }
  14327. }
  14328. //Add TempStopTransaction | Update TempStopTransaction
  14329. // open file for writing
  14330. FILE *outfile;
  14331. outfile = fopen (TempStopTransaction, "a");
  14332. //DEBUG_INFO("data = %s\n", queuedata);
  14333. fputs(queuedata, outfile);
  14334. fputs("\n", outfile);
  14335. fclose (outfile);
  14336. }
  14337. void checkTempStopTransaction(int gun_index)
  14338. {
  14339. FILE *fptr1;
  14340. char ch;
  14341. char str[QUEUE_MESSAGE_LENGTH]={0};
  14342. char guid[37]={0};
  14343. char tempdata[65]={0};
  14344. char connectorStr[2]={0};
  14345. char TempStopTransaction[256];
  14346. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  14347. fptr1 = fopen(TempStopTransaction, "r");
  14348. //TempStopTransaction格式: 槍號,StopTransaction封包
  14349. if (!fptr1)
  14350. {
  14351. //printf(" File not found or unable to open the input file!!\n");
  14352. return ;
  14353. }
  14354. ch=fgetc(fptr1);
  14355. //printf(" Now the content of the file %s is : \n",fname);
  14356. rewind(fptr1);
  14357. if(ch!=EOF)
  14358. {
  14359. // copy all contents to the temporary file except the specific line
  14360. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  14361. {
  14362. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14363. if(str[0]=='\0')
  14364. {
  14365. break;
  14366. }
  14367. //TempStopTransaction格式: 槍號,StopTransaction封包
  14368. strncpy(connectorStr, str, 1);
  14369. if(atoi(connectorStr) != (gun_index+1))
  14370. {
  14371. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  14372. fclose(fptr1);
  14373. return ;
  14374. }
  14375. //random_uuid(guid);
  14376. strncpy(guid, str+6, 36); //copy guid
  14377. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  14378. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  14379. {
  14380. //DEBUG_INFO("StopTransaction mapitem pass\n");
  14381. }
  14382. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  14383. memset(str,0,ARRAY_SIZE(str));
  14384. }
  14385. }
  14386. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  14387. fclose(fptr1);
  14388. remove(TempStopTransaction); // remove the original file
  14389. }
  14390. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  14391. {
  14392. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  14393. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  14394. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  14395. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  14396. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14397. }
  14398. int GetWebSocketPingInterval(void)
  14399. {
  14400. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14401. }
  14402. int GetServerSign(void)
  14403. {
  14404. return server_sign;
  14405. }
  14406. uint8_t GetOcppSecurityProfile()
  14407. {
  14408. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14409. }
  14410. void GetOcppChargerBoxId(uint8_t *data)
  14411. {
  14412. sprintf((char*)data, "%s", ShmOCPP16Data->ChargeBoxId);
  14413. }
  14414. void GetOcppSecurityPassword(uint8_t *data)
  14415. {
  14416. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14417. }
  14418. void SetOcppVersion(uint8_t *version)
  14419. {
  14420. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  14421. DEBUG_INFO("ocpp version: %s\n", version);
  14422. if(strstr((char*)version, "ocpp1.6") != NULL)
  14423. {
  14424. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  14425. }
  14426. else if(strstr((char*)version, "ocpp2.0") != NULL)
  14427. {
  14428. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  14429. system("pkill OcppBackend");
  14430. }
  14431. }
  14432. void SetServerSign(int value)
  14433. {
  14434. server_sign = value;
  14435. }
  14436. int GetBootNotificationInterval(void)
  14437. {
  14438. return BootNotificationInterval;
  14439. }
  14440. int GetInternetConn(void)
  14441. {
  14442. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  14443. }
  14444. int isConnectorInitMode(int gun_index)
  14445. {
  14446. int tempIndex = 0;
  14447. int result = TRUE;
  14448. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14449. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14450. {
  14451. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14452. {
  14453. tempIndex = ((gun_index==2) ? 1: 0);
  14454. }
  14455. else
  14456. {
  14457. tempIndex = gun_index;
  14458. }
  14459. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14460. {
  14461. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  14462. {
  14463. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  14464. } //end of the same index
  14465. }//end of for CHAdeMO_QUANTITY
  14466. }
  14467. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14468. {
  14469. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14470. {
  14471. tempIndex = ((gun_index==2) ? 1: 0);
  14472. }
  14473. else
  14474. {
  14475. tempIndex = gun_index;
  14476. }
  14477. for (int index = 0; index < CCS_QUANTITY; index++)
  14478. {
  14479. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14480. {
  14481. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  14482. } //end of the same index
  14483. } // end of for CCS_QUANTITY
  14484. }
  14485. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14486. {
  14487. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14488. {
  14489. tempIndex = ((gun_index==2) ? 1: 0);
  14490. }
  14491. else
  14492. {
  14493. tempIndex = gun_index;
  14494. }
  14495. for (int index = 0; index < GB_QUANTITY; index++)
  14496. {
  14497. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14498. {
  14499. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  14500. } //end of the same index
  14501. } // end of for GB_QUANTITY
  14502. }
  14503. else if(gunType[gun_index] == GUN_TYPE_DO)
  14504. {
  14505. tempIndex = gun_index;
  14506. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14507. {
  14508. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14509. {
  14510. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  14511. } //end of the same index
  14512. }
  14513. }
  14514. else
  14515. {
  14516. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14517. {
  14518. tempIndex = 2;
  14519. }
  14520. else
  14521. {
  14522. tempIndex = gun_index;
  14523. }
  14524. for (int index = 0; index < AC_QUANTITY; index++)
  14525. {
  14526. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14527. {
  14528. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  14529. }//end of the same index
  14530. }//end of for AC_QUANTITY
  14531. }
  14532. return result;
  14533. }
  14534. void InitialSystemValue(void)
  14535. {
  14536. int connectorIndex = 0;
  14537. //int valueASCII = 0;
  14538. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14539. gunTotalNumber=0;
  14540. SystemInitial = 0;
  14541. localversion=0;
  14542. BootNotificationInterval = 0;
  14543. authorizeRetryTimes = 0;
  14544. GunStatusInterval = 10;
  14545. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14546. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14547. //Hear Beat
  14548. HeartBeatWithNOResponse = 0;
  14549. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  14550. FirstHeartBeat = 0;
  14551. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  14552. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  14553. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  14554. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  14555. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  14556. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  14557. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  14558. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  14559. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  14560. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  14561. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  14562. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  14563. memset(gunType, 0, ARRAY_SIZE(gunType));
  14564. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14565. {
  14566. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O')
  14567. {
  14568. // DO series
  14569. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  14570. {
  14571. SystemInitial = SystemInitial + 1;
  14572. gunTotalNumber = gunTotalNumber + 1;
  14573. gunType[connectorIndex] = GUN_TYPE_DO;
  14574. connectorIndex = connectorIndex + 1;
  14575. }
  14576. }
  14577. else
  14578. {
  14579. // DM, DW, DS series
  14580. //check connector / socket type (index: 8, 9, 10)
  14581. for(int index=7; index <10 ; index++)
  14582. {
  14583. if(index != 8)
  14584. {
  14585. // DC Connector
  14586. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  14587. {
  14588. SystemInitial = SystemInitial + 1;
  14589. gunTotalNumber = gunTotalNumber + 1;
  14590. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  14591. connectorIndex = connectorIndex + 1;
  14592. }
  14593. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  14594. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  14595. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  14596. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  14597. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  14598. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  14599. {
  14600. SystemInitial = SystemInitial + 1;
  14601. gunTotalNumber = gunTotalNumber + 1;
  14602. gunType[connectorIndex] = GUN_TYPE_CCS;
  14603. connectorIndex = connectorIndex + 1;
  14604. }
  14605. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  14606. {
  14607. SystemInitial = SystemInitial + 1;
  14608. gunTotalNumber = gunTotalNumber + 1;
  14609. gunType[connectorIndex] = GUN_TYPE_GBT;
  14610. connectorIndex = connectorIndex + 1;
  14611. }
  14612. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  14613. {
  14614. SystemInitial = SystemInitial + 1;
  14615. gunTotalNumber = gunTotalNumber + 1;
  14616. gunType[connectorIndex] = GUN_TYPE_DO;
  14617. connectorIndex = connectorIndex + 1;
  14618. }
  14619. }
  14620. else
  14621. {
  14622. // AC Connector
  14623. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14624. {
  14625. SystemInitial = SystemInitial + 1;
  14626. gunTotalNumber = gunTotalNumber + 1;
  14627. gunType[connectorIndex] = GUN_TYPE_AC;
  14628. connectorIndex = connectorIndex + 1;
  14629. }
  14630. }
  14631. }
  14632. }
  14633. //DEBUG_INFO("DC ...\n");
  14634. }
  14635. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  14636. {
  14637. //check connector / socket type (index: 8, 9, 10)
  14638. for(int index=7; index <10 ; index++)
  14639. {
  14640. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14641. {
  14642. SystemInitial = SystemInitial + 1;
  14643. gunTotalNumber = gunTotalNumber + 1;
  14644. gunType[connectorIndex] = GUN_TYPE_AC;
  14645. connectorIndex = connectorIndex + 1;
  14646. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  14647. }
  14648. }
  14649. }
  14650. //Status && ConnectorPlugIn Setting
  14651. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14652. {
  14653. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  14654. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  14655. }
  14656. for (int index = 0; index < CCS_QUANTITY; index++)
  14657. {
  14658. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  14659. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  14660. }
  14661. for (int index = 0; index < GB_QUANTITY; index++)
  14662. {
  14663. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  14664. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  14665. }
  14666. for (int index = 0; index < AC_QUANTITY; index++)
  14667. {
  14668. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  14669. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  14670. }
  14671. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14672. {
  14673. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  14674. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  14675. }
  14676. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  14677. {
  14678. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14679. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  14680. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  14681. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  14682. }
  14683. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  14684. clientTime.Heartbeat=time((time_t*)NULL);
  14685. sleep(1);
  14686. }
  14687. void LWS_Send(char * str)
  14688. {
  14689. //=====================================================
  14690. // Check InternetConn 0: disconnected, 1: connected
  14691. //====================================================
  14692. if(GetOcppConnStatus() == 0)
  14693. {
  14694. DEBUG_INFO("offline now !!!\n");
  14695. return;
  14696. }
  14697. pthread_mutex_lock(&lock_send);
  14698. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14699. sprintf((char *)SendBuffer, "%s", str);
  14700. SendBufLen = strlen(str);
  14701. pthread_mutex_unlock(&lock_send);
  14702. lws_callback_on_writable(wsi_client);
  14703. //lws_service(context, 0);
  14704. //sleep(1);
  14705. }
  14706. void LWS_SendNow(char * str)
  14707. {
  14708. //=====================================================
  14709. // Check InternetConn 0: disconnected, 1: connected
  14710. //====================================================
  14711. if(GetOcppConnStatus() == 0)
  14712. {
  14713. DEBUG_INFO("offline now !!!\n");
  14714. return;
  14715. }
  14716. pthread_mutex_lock(&lock_send);
  14717. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14718. sprintf((char *)SendBuffer, "%s", str);
  14719. SendBufLen = strlen(str);
  14720. pthread_mutex_unlock(&lock_send);
  14721. lws_callback_on_writable(wsi_client);
  14722. lws_service(context, 0);
  14723. //sleep(1);
  14724. }