MessageHandler.c 764 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. //ConfigurationMaxKeys
  12. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  13. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  14. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  15. //=================================
  16. // StatusNotification cycle
  17. //=================================
  18. static int server_cycle_Status = 120;
  19. //===============================
  20. // Configuration: unknownkey
  21. //===============================
  22. static char unknownkey[10][20] = {0};
  23. static int UnknownKeynum = 0;
  24. //===============================
  25. // Gun Total Numbers
  26. //===============================
  27. static int gunTotalNumber = 0;
  28. static uint8_t gunType[4] = {0};
  29. //===============================
  30. // Local List Version
  31. //===============================
  32. static int localversion=0;
  33. static char idTagAuthorization[32] = {0};
  34. //===============================
  35. // OCPP sign variable
  36. //===============================
  37. static int server_sign = FALSE;
  38. int server_pending = FALSE;
  39. static int BootNotificationInterval = 0;
  40. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  41. //===============================
  42. // OCPP auth variable
  43. //===============================
  44. static int authorizeRetryTimes = 0; //number of Retry times
  45. //===============================
  46. // OCPP other variables
  47. //===============================
  48. static int HeartBeatWaitTime = 10;
  49. static int FirstHeartBeat = 0;
  50. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  51. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  52. static char CurrentChargingProfileScheduleStr[30] = {0};
  53. //========================================
  54. // OCPP status/previous related variables
  55. //========================================
  56. static int GunStatusInterval = 10;
  57. static uint8_t statusModeChage[CONNECTOR_QUANTITY] = {FALSE};
  58. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  59. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  60. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  61. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  62. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  63. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  64. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  65. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  66. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  67. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  68. static int TransactionMessageAttemptsValue = 0;
  69. static int TransactionMessageRetryIntervalValue = 0;
  70. static int TempMeterValueInterval = 0;
  71. static struct OCPPAuthLocalElemet
  72. {
  73. int listVersionInt;
  74. char idTagstr[21];
  75. char parentIdTag[21];
  76. char expiryDate[36];
  77. char idTagstatus[16];
  78. }idTagQuery;
  79. //=============================================
  80. // OCPP HeartBeat Response Not Receive Counts
  81. //============================================
  82. static int HeartBeatWithNOResponse = 0;
  83. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  84. extern sqlite3 *db;
  85. int TransactionMessageAttemptsGet(void);
  86. int TransactionMessageRetryIntervalGet(void);
  87. int GetOcppConnStatus(void);
  88. void SetOcppConnStatus(uint8_t status);
  89. int setKeyValue(char *key, char *value);
  90. void OCPP_get_TableAuthlocalAllData(void);
  91. void processUnkownKey(void);
  92. struct StructOCPPMeterValue
  93. {
  94. unsigned char TimeStamp[28];
  95. struct StructSampledValue SampledValue[10];
  96. };
  97. struct ClientTime
  98. {
  99. unsigned int Heartbeat;
  100. unsigned int StatusNotification[CONNECTOR_QUANTITY];
  101. unsigned int StartTransaction;
  102. unsigned int StopTransaction;
  103. unsigned int MeterValues[CONNECTOR_QUANTITY];
  104. }clientTime;
  105. typedef union
  106. {
  107. //Operations Initiated by Central System
  108. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  109. struct
  110. {
  111. //CsMsgValue[0]
  112. unsigned char StatusNotificationReq:1; //bit 0,
  113. unsigned char StatusNotificationConf:1; //bit 1,
  114. unsigned char TriggerMeterValue:1; //bit 2,
  115. unsigned char :5; //bit 5~7
  116. }bits[CONNECTOR_QUANTITY];
  117. }CpinitiateMsg;
  118. CpinitiateMsg cpinitateMsg;
  119. //GetConfiguration Array
  120. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  121. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  122. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  123. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  124. #if 0
  125. static char *ChargePointErrorCodeStr[] = {
  126. MACROSTR(ConnectorLockFailure),
  127. MACROSTR(EVCommunicationError),
  128. MACROSTR(GroundFailure),
  129. MACROSTR(HighTemperature),
  130. MACROSTR(InternalError),
  131. MACROSTR(LocalListConflict),
  132. MACROSTR(NoError),
  133. MACROSTR(OtherError),
  134. MACROSTR(OverCurrentFailure),
  135. MACROSTR(OverVoltage),
  136. MACROSTR(PowerMeterFailure),
  137. MACROSTR(PowerSwitchFailure),
  138. MACROSTR(ReaderFailure),
  139. MACROSTR(ResetFailure),
  140. MACROSTR(UnderVoltage),
  141. MACROSTR(WeakSignal)
  142. };
  143. #endif
  144. static char * ChargePointStatusStr[] = {
  145. MACROSTR(Available),
  146. MACROSTR(Preparing),
  147. MACROSTR(Charging),
  148. MACROSTR(SuspendedEVSE),
  149. MACROSTR(SuspendedEV),
  150. MACROSTR(Finishing),
  151. MACROSTR(Reserved),
  152. MACROSTR(Unavailable),
  153. MACROSTR(Faulted)
  154. };
  155. static char *RegistrationStatusStr[] = {
  156. MACROSTR(Accepted),
  157. MACROSTR(Pending),
  158. MACROSTR(Rejected)
  159. };
  160. static char *AvailabilityTypeStr[] = {
  161. MACROSTR(Inoperative),
  162. MACROSTR(Operative)
  163. };
  164. static char *AvailabilityStatusStr[] = {
  165. MACROSTR(Accepted),
  166. MACROSTR(Rejected),
  167. MACROSTR(Scheduled)
  168. };
  169. static char *ConfigurationStatusStr[] = {
  170. MACROSTR(Accepted),
  171. MACROSTR(Rejected),
  172. MACROSTR(RebootRequired),
  173. MACROSTR(NotSupported)
  174. };
  175. static char *ClearCacheStatusStr[] = {
  176. MACROSTR(Accepted),
  177. MACROSTR(Rejected)
  178. };
  179. static char *ChargingProfilePurposeTypeStr[] = {
  180. MACROSTR(ChargePointMaxProfile),
  181. MACROSTR(TxDefaultProfile),
  182. MACROSTR(TxProfile)
  183. };
  184. static char *ChargingProfileStatusStr[] = {
  185. MACROSTR(Accepted),
  186. MACROSTR(Rejected),
  187. MACROSTR(NotSupported)
  188. };
  189. static char *ClearChargingProfileStatusStr[] = {
  190. MACROSTR(Accepted),
  191. MACROSTR(Unknown)
  192. };
  193. static char *GetCompositeScheduleStatusStr[] = {
  194. MACROSTR(Accepted),
  195. MACROSTR(Rejected)
  196. };
  197. static char *UpdateTypeStr[] = {
  198. MACROSTR(Differential),
  199. MACROSTR(Full)
  200. };
  201. static char *UpdateStatusStr[] = {
  202. MACROSTR(Accepted),
  203. MACROSTR(Failed),
  204. MACROSTR(NotSupported),
  205. MACROSTR(VersionMismatch)
  206. };
  207. static char *RemoteStartStopStatusStr[] = {
  208. MACROSTR(Accepted),
  209. MACROSTR(Rejected)
  210. };
  211. static char *ReservationStatusStr[] = {
  212. MACROSTR(Accepted),
  213. MACROSTR(Faulted),
  214. MACROSTR(Occupied),
  215. MACROSTR(Rejected),
  216. MACROSTR(Unavailable)
  217. };
  218. static char *ResetTypeStr[] = {
  219. MACROSTR(Hard),
  220. MACROSTR(Soft)
  221. };
  222. static char *ResetStatusStr[] = {
  223. MACROSTR(Accepted),
  224. MACROSTR(Rejected)
  225. };
  226. static char * DiagnosticsStatusStr[] = {
  227. MACROSTR(Idle),
  228. MACROSTR(Uploaded),
  229. MACROSTR(UploadFailed),
  230. MACROSTR(Uploading)
  231. };
  232. static char * FirmwareStatusStr[] = {
  233. MACROSTR(Downloaded),
  234. MACROSTR(DownloadFailed),
  235. MACROSTR(Downloading),
  236. MACROSTR(Idle),
  237. MACROSTR(InstallationFailed),
  238. MACROSTR(Installing),
  239. MACROSTR(Installed)
  240. };
  241. static char * MessageTriggerStr[] = {
  242. MACROSTR(BootNotification),
  243. MACROSTR(DiagnosticsStatusNotification),
  244. MACROSTR(FirmwareStatusNotification),
  245. MACROSTR(Heartbeat),
  246. MACROSTR(MeterValues),
  247. MACROSTR(StatusNotification)
  248. };
  249. static char * TriggerMessageStatusStr[] = {
  250. MACROSTR(Accepted),
  251. MACROSTR(Rejected),
  252. MACROSTR(NotImplemented)
  253. };
  254. static char * UnlockStatusStr[] = {
  255. MACROSTR(Unlocked),
  256. MACROSTR(UnlockFailed),
  257. MACROSTR(NotSupported)
  258. };
  259. #if 0
  260. static char * StopTransactionReasonStr[] = {
  261. MACROSTR(EmergencyStop),
  262. MACROSTR(EVDisconnected),
  263. MACROSTR(HardReset),
  264. MACROSTR(Local),
  265. MACROSTR(Other),
  266. MACROSTR(PowerLoss),
  267. MACROSTR(Reboot),
  268. MACROSTR(Remote),
  269. MACROSTR(SoftReset),
  270. MACROSTR(UnlockCommand),
  271. MACROSTR(DeAuthorized)
  272. };
  273. #endif
  274. static char * CancelReservationStatusStr[] = {
  275. MACROSTR(Accepted),
  276. MACROSTR(Rejected)
  277. };
  278. static char * ReadingContextStr[] = {
  279. MACROSTR(Interruption.Begin),
  280. MACROSTR(Interruption.End),
  281. MACROSTR(Other),
  282. MACROSTR(Sample.Clock),
  283. MACROSTR(Sample.Periodic),
  284. MACROSTR(Transaction.Begin),
  285. MACROSTR(Transaction.End),
  286. MACROSTR(Trigger)
  287. };
  288. static char * ValueFormatStr[] = {
  289. MACROSTR(Raw),
  290. MACROSTR(SignedData)
  291. };
  292. static char * MeasurandStr[] = {
  293. MACROSTR(Current.Export),
  294. MACROSTR(Current.Import),
  295. MACROSTR(Current.Offered),
  296. MACROSTR(Energy.Active.Export.Register),
  297. MACROSTR(Energy.Active.Import.Register),
  298. MACROSTR(Energy.Reactive.Export.Register),
  299. MACROSTR(Energy.Reactive.Import.Register),
  300. MACROSTR(Energy.Active.Export.Interval),
  301. MACROSTR(Energy.Active.Import.Interval),
  302. MACROSTR(Energy.Reactive.Export.Interval),
  303. MACROSTR(Energy.Reactive.Import.Interval),
  304. MACROSTR(Frequency),
  305. MACROSTR(Power.Active.Export),
  306. MACROSTR(Power.Active.Import),
  307. MACROSTR(Power.Factor),
  308. MACROSTR(Power.Offered),
  309. MACROSTR(Power.Reactive.ExportMACROSTR),
  310. MACROSTR(Power.Reactive.Import),
  311. MACROSTR(RPM),
  312. MACROSTR(SoC),
  313. MACROSTR(Temperature),
  314. MACROSTR(Voltage)
  315. };
  316. static char * LocationStr[] = {
  317. MACROSTR(Body),
  318. MACROSTR(Cable),
  319. MACROSTR(EV),
  320. MACROSTR(Inlet),
  321. MACROSTR(Outlet)
  322. };
  323. static char * PhaseStr[] = {
  324. MACROSTR(L1),
  325. MACROSTR(L2),
  326. MACROSTR(L3),
  327. MACROSTR(N),
  328. MACROSTR(L1-N),
  329. MACROSTR(L2-N),
  330. MACROSTR(L3-N),
  331. MACROSTR(L1-L2),
  332. MACROSTR(L2-L3),
  333. MACROSTR(L3-L1)
  334. };
  335. static char * UnitOfMeasureStr[] = {
  336. MACROSTR(Wh),
  337. MACROSTR(kWh),
  338. MACROSTR(varh),
  339. MACROSTR(kvarh),
  340. MACROSTR(W),
  341. MACROSTR(kW),
  342. MACROSTR(VA),
  343. MACROSTR(kVA),
  344. MACROSTR(var),
  345. MACROSTR(kvar),
  346. MACROSTR(A),
  347. MACROSTR(V),
  348. MACROSTR(Celsius),
  349. MACROSTR(Fahrenheit),
  350. MACROSTR(K),
  351. MACROSTR(Percent)
  352. };
  353. //=========================================
  354. // Sqlite3 related function
  355. //=========================================
  356. static int selectSqlCount = 0;
  357. static int callback(void *data, int argc, char **argv, char **azColName){
  358. int i;
  359. //printf("%s: ", (const char*)data);
  360. selectSqlCount = argc;
  361. for(i = 0; i<argc; i++){
  362. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  363. }
  364. //printf("\n");
  365. return 0;
  366. }
  367. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  368. //int i;
  369. //printf("%s:\n", (const char*)data);
  370. localversion = argv[5] ? atoi(argv[5]) : 0;
  371. //printf("localversion=%d\n", localversion);
  372. return 0;
  373. }
  374. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  375. //printf("%s:\n", (const char*)data);
  376. //idTag
  377. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  378. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  379. //parentIdTag
  380. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  381. //expir_date
  382. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  383. //status
  384. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  385. //version
  386. if(columenCount > 5)
  387. idTagQuery.listVersionInt = atoi(columnValue[5]);
  388. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  389. return 0;
  390. }
  391. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  392. {
  393. // localversion = argv[5] ? atoi(argv[5]) : 0;
  394. // printf("localversion=%d\n", localversion);
  395. return 0;
  396. }
  397. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  398. {
  399. for (int i = 0; i < n_columns; i++)
  400. {
  401. DEBUG_INFO("%s\t", col_values[i]);
  402. }
  403. DEBUG_INFO("\n");
  404. return 0;
  405. }
  406. int OCPP_cleanLocalCache()
  407. {
  408. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  409. char *errMsg = 0;
  410. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  411. if (SQLITE_OK != rc)
  412. {
  413. DEBUG_INFO("SQL error: %s\n",errMsg);
  414. return FALSE;
  415. }
  416. return TRUE;
  417. }
  418. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  419. {
  420. int isSuccess = TRUE;
  421. int ret = 0;
  422. //const char* data = "Callback function called";
  423. char sql[300];
  424. char zErrMsg[200];
  425. memset(sql, 0, 300);
  426. memset(zErrMsg, 0, 200);
  427. sprintf(sql, "insert or replace into ocpp_auth_cache (idtag, parent_idtag, expir_date, status) " "VALUES ('%s', '%s', '%s', '%s'); ""SELECT * from ocpp_auth_cache", idTag, parentTage, expiryDate, status);
  428. //* Execute SQL statement */
  429. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  430. if( ret != SQLITE_OK )
  431. {
  432. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  433. isSuccess = FALSE;
  434. }
  435. return isSuccess;
  436. }
  437. void OCPP_getIdTagFromLocalCache(char idTag[])
  438. {
  439. int rc = 0;
  440. char sql[100];
  441. char zErrMsg[100];
  442. memset(sql, 0, 100);
  443. memset(zErrMsg, 0, 100);
  444. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  445. memset(&idTagQuery, 0, sizeof(idTagQuery));
  446. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  447. /* Execute SQL statement */
  448. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  449. if( rc != SQLITE_OK )
  450. {
  451. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  452. }
  453. }
  454. void OCPP_getListVerion()
  455. {
  456. int rc = 0;
  457. // const char* data = "Callback function called";
  458. char sql[100];
  459. char zErrMsg[100];
  460. memset(sql, 0, 100);
  461. memset(zErrMsg, 0, 100);
  462. strcpy(sql, "select * from ocpp_auth_local order by idx");
  463. /* Execute SQL statement */
  464. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  465. if( rc != SQLITE_OK )
  466. {
  467. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  468. }
  469. }
  470. void OCPP_get_TableAuthlocalAllData(void)
  471. {
  472. int rc = 0;
  473. char sql[100];
  474. char zErrMsg[100];
  475. memset(sql, 0, 100);
  476. memset(zErrMsg, 0, 100);
  477. sprintf(sql,"select * from ocpp_auth_local ");
  478. /* Execute SQL statement */
  479. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  480. if( rc != SQLITE_OK )
  481. {
  482. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  483. }
  484. //return ver;
  485. }
  486. int OCPP_cleanLocalList()
  487. {
  488. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  489. char *errMsg = 0;
  490. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  491. if (SQLITE_OK != rc)
  492. {
  493. DEBUG_INFO("%s\n",errMsg);
  494. return FALSE;
  495. }
  496. return TRUE;
  497. }
  498. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  499. {
  500. int isSuccess = FALSE;
  501. int ret = 0;
  502. //const char* data = "Callback function called";
  503. char sql[300];
  504. char zErrMsg[200];
  505. memset(sql, 0, 300);
  506. memset(zErrMsg, 0, 200);
  507. sprintf(sql,"insert or replace into ocpp_auth_local (idtag, parent_idtag, expir_date, status, version) " "VALUES ('%s', '%s', '%s', '%s', %d ); ""SELECT * from ocpp_auth_local", idTag, parentTage, expiryDate, status, version);
  508. //* Execute SQL statement */
  509. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  510. if( ret != SQLITE_OK )
  511. {
  512. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  513. return isSuccess;
  514. }
  515. memset(sql, 0, 300);
  516. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  517. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  518. if( ret != SQLITE_OK )
  519. {
  520. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  521. return isSuccess;
  522. }
  523. isSuccess = TRUE;
  524. return isSuccess;
  525. }
  526. void OCPP_getIdTagFromLocalList(char idTag[])
  527. {
  528. int rc = 0;
  529. // const char* data = "Callback function called";
  530. char sql[100];
  531. char zErrMsg[100];
  532. memset(sql, 0, 100);
  533. memset(zErrMsg, 0, 100);
  534. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  535. memset(&idTagQuery, 0, sizeof(idTagQuery));
  536. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  537. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  538. /* Execute SQL statement */
  539. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  540. if( rc != SQLITE_OK )
  541. {
  542. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  543. }
  544. //return ver;
  545. }
  546. void OCPP_deleteIdTagFromLocalList(char idTag[])
  547. {
  548. //int ver = 0;
  549. //int isSuccess = FALSE;
  550. int rc = 0;
  551. char sql[100];
  552. char zErrMsg[100];
  553. memset(sql, 0, 100);
  554. memset(zErrMsg, 0, 100);
  555. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  556. //* Execute SQL statement */
  557. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  558. if( rc != SQLITE_OK )
  559. {
  560. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  561. }
  562. }
  563. int getCurrentYear()
  564. {
  565. int result = 0;
  566. time_t CurrentTime;
  567. struct tm *tm;
  568. CurrentTime = time(NULL);
  569. tm=localtime(&CurrentTime);
  570. result = (tm->tm_year + 1900);
  571. return result;
  572. }
  573. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  574. {
  575. int result = PASS;
  576. char* errMsg = NULL;
  577. char sqlStr[8192];
  578. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  579. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  580. {
  581. result = FAIL;
  582. DEBUG_INFO( "Insert local transaction record error message: %s\n", errMsg);
  583. }
  584. sprintf(sqlStr, "delete from ocpp_transaction_record where (idx < (select idx from ocpp_transaction_record order by idx desc limit 1)-2000) and (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  585. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  586. {
  587. result = FAIL;
  588. DEBUG_INFO( "delete local transaction record error message: %s\n", errMsg);
  589. }
  590. return result;
  591. }
  592. //==========================================
  593. // Check time passed since today
  594. //==========================================
  595. long long DiffTimebWithNow(struct timeb ST)
  596. {
  597. //return milli-second
  598. struct timeb ET;
  599. long long StartTime,StopTime;
  600. ftime(&ET);
  601. StartTime=(long long)ST.time;
  602. StopTime=(long long)ET.time;
  603. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  604. }
  605. int getTimePassSinceToday()
  606. {
  607. int result = -1;
  608. static time_t lastTime;
  609. time_t t;
  610. struct tm *tmStartToday;
  611. struct timeb tbStartToday;
  612. t=time(NULL);
  613. if(difftime(t, lastTime)>0)
  614. {
  615. tmStartToday=localtime(&t);
  616. tmStartToday->tm_hour = 0;
  617. tmStartToday->tm_min = 0;
  618. tmStartToday->tm_sec = 0;
  619. tbStartToday.time = mktime(tmStartToday);
  620. tbStartToday.millitm = 0;
  621. result = DiffTimebWithNow(tbStartToday)/1000;
  622. lastTime = t;
  623. }
  624. return result;
  625. }
  626. void getNowDatetime(uint8_t *data)
  627. {
  628. time_t t = time(NULL);
  629. struct tm tm = *localtime(&t);
  630. sprintf((char*)data, "%04d-%02d-%02dT%02d:%02d:%02dZ", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
  631. }
  632. int syncDateTimeRTC(uint8_t *data)
  633. {
  634. struct ParsingResult
  635. {
  636. int result;
  637. int scanedElement;
  638. int year;
  639. int month;
  640. int mday;
  641. int hour;
  642. int min;
  643. int sec;
  644. int tz_hour;
  645. int tz_min;
  646. float minSec;
  647. }result;
  648. struct tm tmOrg;
  649. struct tm *tmTarget;
  650. struct timeb tbTarget;
  651. char buf[128];
  652. memset(&result, 0x00, sizeof(struct ParsingResult));
  653. result.result = PASS;
  654. if(strstr((char*)data, ".") != NULL)
  655. {
  656. // Original data with mini second
  657. if(strstr((char*)data, "Z") != NULL)
  658. {
  659. // Original data with Z
  660. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  661. &result.year,
  662. &result.month,
  663. &result.mday,
  664. &result.hour,
  665. &result.min,
  666. &result.sec,
  667. &result.minSec);
  668. }
  669. else
  670. {
  671. // Original data without Z
  672. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  673. &result.year,
  674. &result.month,
  675. &result.mday,
  676. &result.hour,
  677. &result.min,
  678. &result.sec,
  679. &result.minSec,
  680. &result.tz_hour,
  681. &result.tz_min);
  682. }
  683. }
  684. else
  685. {
  686. // Original data without mini second
  687. if(strstr((char*)data, "Z") != NULL)
  688. {
  689. // Original data with Z
  690. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  691. &result.year,
  692. &result.month,
  693. &result.mday,
  694. &result.hour,
  695. &result.min,
  696. &result.sec);
  697. }
  698. else
  699. {
  700. // Original data without Z
  701. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  702. &result.year,
  703. &result.month,
  704. &result.mday,
  705. &result.hour,
  706. &result.min,
  707. &result.sec,
  708. &result.tz_hour,
  709. &result.tz_min);
  710. }
  711. }
  712. tmOrg.tm_year = result.year - 1900;
  713. tmOrg.tm_mon = result.month - 1;
  714. tmOrg.tm_mday = result.mday;
  715. tmOrg.tm_hour = result.hour;
  716. tmOrg.tm_min = result.min;
  717. tmOrg.tm_sec = result.sec;
  718. tmOrg.tm_gmtoff = 0;
  719. tbTarget.time = mktime(&tmOrg);
  720. tbTarget.timezone = 0;
  721. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  722. tmTarget = gmtime(&tbTarget.time);
  723. sprintf(buf, "date -s '%04d-%02d-%02d %02d:%02d:%02d'", (tmTarget->tm_year+1900), (tmTarget->tm_mon+1), tmTarget->tm_mday, tmTarget->tm_hour, tmTarget->tm_min, tmTarget->tm_sec);
  724. //DEBUG_INFO(" org date time: %s\n", data);
  725. //DEBUG_INFO("parse date time: %s\n", buf);
  726. system(buf);
  727. system("/sbin/hwclock -w --systohc");
  728. if(result.scanedElement < 6)
  729. result.result = FAIL;
  730. return result.result;
  731. }
  732. //==========================================
  733. // GetCompositeSchedule logic related function
  734. //==========================================
  735. int DiffTimebSec(struct timeb ST, struct timeb ET)
  736. {
  737. //return milli-second
  738. unsigned int StartTime,StopTime;
  739. StartTime=(unsigned int)ST.time;
  740. StopTime=(unsigned int)ET.time;
  741. return (StopTime-StartTime);
  742. }
  743. int DiffTimebWithNowSec(struct timeb ST)
  744. {
  745. //return milli-second
  746. struct timeb ET;
  747. unsigned int StartTime,StopTime;
  748. ftime(&ET);
  749. StartTime=(unsigned int)ST.time;
  750. StopTime=(unsigned int)ET.time;
  751. return (StopTime-StartTime);
  752. }
  753. int getStartStop(uint8_t *start, uint8_t *stop)
  754. {
  755. int result = -1;
  756. struct tm tmStart;
  757. struct timeb tbStart;
  758. struct tm tmStop;
  759. struct timeb tbStop;
  760. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  761. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  762. {
  763. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  764. //DEBUG_INFO("Stop: %d-%d-%d %d:%d:%d\n", tmStop.tm_year, tmStop.tm_mon, tmStop.tm_mday, tmStop.tm_hour, tmStop.tm_min, tmStop.tm_sec);
  765. tmStart.tm_year -= 1900;
  766. tmStart.tm_mon -= 1;
  767. tbStart.time = mktime(&tmStart);
  768. tbStart.millitm = 0;
  769. tmStop.tm_year -= 1900;
  770. tmStop.tm_mon -= 1;
  771. tbStop.time = mktime(&tmStop);
  772. tbStop.millitm = 0;
  773. result = DiffTimebSec(tbStart, tbStop);
  774. //DEBUG_INFO("getStartStop(): %d\n", result);
  775. }
  776. else
  777. {
  778. DEBUG_WARN("Start or stop date parsing error.\r\n");
  779. }
  780. return result;
  781. }
  782. int isOvertNow(uint8_t *start)
  783. {
  784. int result = NO;
  785. struct tm tmStart;
  786. struct timeb tbStart;
  787. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6))
  788. {
  789. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  790. tmStart.tm_year -= 1900;
  791. tmStart.tm_mon -= 1;
  792. tbStart.time = mktime(&tmStart);
  793. tbStart.millitm = 0;
  794. if(DiffTimebWithNowSec(tbStart) <= 0)
  795. result = NO;
  796. else
  797. result = YES;
  798. }
  799. else
  800. {
  801. DEBUG_WARN("Start date parsing error.\n");
  802. }
  803. return result;
  804. }
  805. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  806. {
  807. int result = -1;
  808. struct tm tmStart;
  809. struct timeb tbStart;
  810. struct tm tmStop;
  811. struct timeb tbStop;
  812. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  813. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  814. {
  815. tmStart.tm_year -= 1900;
  816. tmStart.tm_mon -= 1;
  817. tbStart.time = mktime(&tmStart);
  818. tbStart.millitm = 0;
  819. tmStop.tm_year -= 1900;
  820. tmStop.tm_mon -= 1;
  821. tbStop.time = mktime(&tmStop);
  822. tbStop.millitm = 0;
  823. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  824. }
  825. return result;
  826. }
  827. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  828. {
  829. FILE *fp;
  830. char profileFileName[128];
  831. char *line = NULL;
  832. size_t len = 0;
  833. time_t CurrentTime;
  834. struct tm *tmComposite;
  835. struct StructChargingProfile maxProfile;
  836. struct StructChargingProfile defaultTxProfile;
  837. struct StructChargingProfile txProfile;
  838. struct StructChargingSchedulePeriod tmpPeriod;
  839. uint8_t limitMax=0;
  840. uint8_t limitDef=0;
  841. uint8_t limitTx=0;
  842. int compositePeriodIdx = 0;
  843. CurrentTime = time(NULL);
  844. tmComposite=localtime(&CurrentTime);
  845. sprintf((char*)compositeProfile->ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec);
  846. if(isUnitA)
  847. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  848. else
  849. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  850. compositeProfile->ChargingSchedule.Duration = durationReq;
  851. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  852. {
  853. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  854. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  855. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  856. }
  857. compositeProfile->ChargingProfileId = 0;
  858. compositeProfile->StackLevel = 99 ;
  859. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  860. maxProfile.ChargingProfileId = -1;
  861. defaultTxProfile.ChargingProfileId = -1;
  862. txProfile.ChargingProfileId = -1;
  863. maxProfile.ChargingSchedule.Duration = -1;
  864. defaultTxProfile.ChargingSchedule.Duration = -1;
  865. txProfile.ChargingSchedule.Duration = -1;
  866. system("yes|rm /tmp/*.json");
  867. system("cp /Storage/OCPP/*.json /tmp");
  868. /*
  869. * Search valid charging profile
  870. */
  871. //DEBUG_INFO("====================================\n");
  872. // Search tx profile
  873. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  874. if((access(profileFileName, F_OK))!=-1)
  875. {
  876. fp = fopen(profileFileName, "r");
  877. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  878. {
  879. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  880. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  881. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  882. }
  883. txProfile.ChargingProfileId = -1;
  884. txProfile.StackLevel = -1;
  885. while(getline(&line, &len, fp) != -1)
  886. {
  887. json_object *obj = NULL;
  888. obj = json_tokener_parse(line);
  889. if(is_error(obj))
  890. {
  891. DEBUG_ERROR("Parse txProfile from file error.\n");
  892. }
  893. else
  894. {
  895. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  896. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  897. )
  898. {
  899. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  900. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  901. )
  902. {
  903. struct tm tmFrom, tmTo;
  904. struct timeb tbFrom, tbTo;
  905. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  906. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  907. {
  908. tmFrom.tm_year -= 1900;
  909. tmFrom.tm_mon -= 1;
  910. tbFrom.time = mktime(&tmFrom);
  911. tmTo.tm_year -= 1900;
  912. tmTo.tm_mon -= 1;
  913. tbTo.time = mktime(&tmTo);
  914. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  915. {
  916. if(txProfile.ChargingProfileId == -1)
  917. DEBUG_INFO("TxProfile found.\n");
  918. else
  919. DEBUG_INFO("TxProfile updated.\n");
  920. // Required item
  921. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  922. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  923. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  924. if(isUnitA)
  925. {
  926. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  927. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  928. {
  929. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  930. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  931. 3:
  932. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  933. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  934. }
  935. }
  936. else
  937. {
  938. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  939. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  940. {
  941. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  942. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  943. 3:
  944. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  945. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  946. }
  947. }
  948. // Optional item
  949. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  950. {
  951. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  952. }
  953. else
  954. {
  955. sprintf((char*)txProfile.ValidFrom, " ");
  956. }
  957. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  958. {
  959. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  960. }
  961. else
  962. {
  963. sprintf((char*)txProfile.ValidTo, " ");
  964. }
  965. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  966. {
  967. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  968. }
  969. else
  970. {
  971. sprintf((char*)txProfile.RecurrencyKind, " ");
  972. }
  973. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  974. {
  975. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  976. }
  977. else
  978. {
  979. txProfile.TransactionId = -1;
  980. }
  981. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  982. {
  983. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  984. }
  985. else
  986. {
  987. txProfile.ChargingSchedule.Duration = 86400;
  988. }
  989. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  990. {
  991. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  992. }
  993. else
  994. {
  995. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  996. }
  997. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  998. {
  999. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1000. }
  1001. else
  1002. {
  1003. txProfile.ChargingSchedule.MinChargingRate = -1;
  1004. }
  1005. }
  1006. }
  1007. }
  1008. else
  1009. {
  1010. if(txProfile.ChargingProfileId == -1)
  1011. DEBUG_INFO("TxProfile found.\n");
  1012. else
  1013. DEBUG_INFO("TxProfile updated.\n");
  1014. // Required item
  1015. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1016. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1017. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1018. if(isUnitA)
  1019. {
  1020. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1021. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1022. {
  1023. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1024. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1025. 3:
  1026. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1027. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1028. }
  1029. }
  1030. else
  1031. {
  1032. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1033. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1034. {
  1035. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1036. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1037. 3:
  1038. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1039. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1040. }
  1041. }
  1042. // Optional item
  1043. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1044. {
  1045. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1046. }
  1047. else
  1048. {
  1049. sprintf((char*)txProfile.ValidFrom, " ");
  1050. }
  1051. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1052. {
  1053. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1054. }
  1055. else
  1056. {
  1057. sprintf((char*)txProfile.ValidTo, " ");
  1058. }
  1059. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1060. {
  1061. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1062. }
  1063. else
  1064. {
  1065. sprintf((char*)txProfile.RecurrencyKind, " ");
  1066. }
  1067. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1068. {
  1069. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1070. }
  1071. else
  1072. {
  1073. txProfile.TransactionId = -1;
  1074. }
  1075. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1076. {
  1077. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1078. }
  1079. else
  1080. {
  1081. txProfile.ChargingSchedule.Duration = 86400;
  1082. }
  1083. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1084. {
  1085. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1086. }
  1087. else
  1088. {
  1089. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1090. }
  1091. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1092. {
  1093. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1094. }
  1095. else
  1096. {
  1097. txProfile.ChargingSchedule.MinChargingRate = -1;
  1098. }
  1099. }
  1100. }
  1101. }
  1102. json_object_put(obj);
  1103. }
  1104. fclose(fp);
  1105. /*
  1106. if(txProfile.ChargingProfileId != -1)
  1107. {
  1108. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1109. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1110. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1111. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1112. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1113. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1114. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1115. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1116. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1117. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1118. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1119. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1120. {
  1121. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1122. {
  1123. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1124. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1125. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1126. }
  1127. }
  1128. }
  1129. else
  1130. DEBUG_INFO("TxProfile not found.\n");*/
  1131. }
  1132. // Search default tx profile
  1133. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1134. if((access(profileFileName, F_OK))==-1)
  1135. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1136. if((access(profileFileName, F_OK))!=-1)
  1137. {
  1138. fp = fopen(profileFileName, "r");
  1139. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1140. {
  1141. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1142. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1143. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1144. }
  1145. defaultTxProfile.ChargingProfileId = -1;
  1146. defaultTxProfile.StackLevel = -1;
  1147. while(getline(&line, &len, fp) != -1)
  1148. {
  1149. json_object *obj = NULL;
  1150. obj = json_tokener_parse(line);
  1151. if(is_error(obj))
  1152. {
  1153. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1154. }
  1155. else
  1156. {
  1157. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1158. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1159. )
  1160. {
  1161. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1162. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1163. )
  1164. {
  1165. struct tm tmFrom, tmTo;
  1166. struct timeb tbFrom, tbTo;
  1167. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  1168. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  1169. {
  1170. tmFrom.tm_year -= 1900;
  1171. tmFrom.tm_mon -= 1;
  1172. tbFrom.time = mktime(&tmFrom);
  1173. tmTo.tm_year -= 1900;
  1174. tmTo.tm_mon -= 1;
  1175. tbTo.time = mktime(&tmTo);
  1176. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1177. {
  1178. if(defaultTxProfile.ChargingProfileId == -1)
  1179. DEBUG_INFO("TxDefaultProfile found.\n");
  1180. else
  1181. DEBUG_INFO("TxDefaultProfile updated.\n");
  1182. // Required item
  1183. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1184. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1185. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1186. if(isUnitA)
  1187. {
  1188. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1189. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1190. {
  1191. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1192. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1193. 3:
  1194. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1195. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1196. }
  1197. }
  1198. else
  1199. {
  1200. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1201. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1202. {
  1203. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1204. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1205. 3:
  1206. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1207. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1208. }
  1209. }
  1210. // Optional item
  1211. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1212. {
  1213. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1214. }
  1215. else
  1216. {
  1217. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1218. }
  1219. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1220. {
  1221. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1222. }
  1223. else
  1224. {
  1225. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1226. }
  1227. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1228. {
  1229. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1230. }
  1231. else
  1232. {
  1233. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1234. }
  1235. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1236. {
  1237. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1238. }
  1239. else
  1240. {
  1241. defaultTxProfile.TransactionId = -1;
  1242. }
  1243. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1244. {
  1245. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1246. }
  1247. else
  1248. {
  1249. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1250. }
  1251. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1252. {
  1253. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1254. }
  1255. else
  1256. {
  1257. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1258. }
  1259. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1260. {
  1261. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1262. }
  1263. else
  1264. {
  1265. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1266. }
  1267. }
  1268. }
  1269. }
  1270. else
  1271. {
  1272. if(defaultTxProfile.ChargingProfileId == -1)
  1273. DEBUG_INFO("TxDefaultProfile found.\n");
  1274. else
  1275. DEBUG_INFO("TxDefaultProfile updated.\n");
  1276. // Required item
  1277. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1278. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1279. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1280. if(isUnitA)
  1281. {
  1282. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1283. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1284. {
  1285. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1286. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1287. 3:
  1288. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1289. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1290. }
  1291. }
  1292. else
  1293. {
  1294. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1295. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1296. {
  1297. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1298. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1299. 3:
  1300. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1301. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1302. }
  1303. }
  1304. // Optional item
  1305. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1306. {
  1307. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1308. }
  1309. else
  1310. {
  1311. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1312. }
  1313. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1314. {
  1315. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1316. }
  1317. else
  1318. {
  1319. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1320. }
  1321. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1322. {
  1323. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1324. }
  1325. else
  1326. {
  1327. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1328. }
  1329. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1330. {
  1331. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1332. }
  1333. else
  1334. {
  1335. defaultTxProfile.TransactionId = -1;
  1336. }
  1337. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1338. {
  1339. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1340. }
  1341. else
  1342. {
  1343. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1344. }
  1345. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1346. {
  1347. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1348. }
  1349. else
  1350. {
  1351. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1352. }
  1353. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1354. {
  1355. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1356. }
  1357. else
  1358. {
  1359. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1360. }
  1361. }
  1362. }
  1363. }
  1364. json_object_put(obj);
  1365. }
  1366. fclose(fp);
  1367. /*
  1368. if(defaultTxProfile.ChargingProfileId != -1)
  1369. {
  1370. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1371. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1372. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1373. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1374. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1375. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1376. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1377. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  1378. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1379. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1380. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1381. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1382. {
  1383. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1384. {
  1385. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1386. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1387. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1388. }
  1389. }
  1390. }
  1391. else
  1392. DEBUG_INFO("TxDefaultProfile not found.\n");
  1393. DEBUG_INFO("------------------------------------\n");*/
  1394. }
  1395. // Search max profile
  1396. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1397. if((access(profileFileName, F_OK))!=-1)
  1398. {
  1399. fp = fopen(profileFileName, "r");
  1400. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1401. {
  1402. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1403. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1404. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1405. }
  1406. maxProfile.ChargingProfileId = -1;
  1407. maxProfile.StackLevel = -1;
  1408. while(getline(&line, &len, fp) != -1)
  1409. {
  1410. json_object *obj = NULL;
  1411. obj = json_tokener_parse(line);
  1412. if(is_error(obj))
  1413. {
  1414. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1415. }
  1416. else
  1417. {
  1418. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1419. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1420. )
  1421. {
  1422. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1423. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1424. )
  1425. {
  1426. struct tm tmFrom, tmTo;
  1427. struct timeb tbFrom, tbTo;
  1428. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  1429. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  1430. {
  1431. tmFrom.tm_year -= 1900;
  1432. tmFrom.tm_mon -= 1;
  1433. tbFrom.time = mktime(&tmFrom);
  1434. tmTo.tm_year -= 1900;
  1435. tmTo.tm_mon -= 1;
  1436. tbTo.time = mktime(&tmTo);
  1437. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1438. {
  1439. if(maxProfile.ChargingProfileId == -1)
  1440. DEBUG_INFO("MaxProfile found.\n");
  1441. else
  1442. DEBUG_INFO("MaxProfile updated.\n");
  1443. // Required item
  1444. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1445. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1446. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1447. if(isUnitA)
  1448. {
  1449. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1450. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1451. {
  1452. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1453. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1454. 3:
  1455. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1456. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1457. }
  1458. }
  1459. else
  1460. {
  1461. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1462. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1463. {
  1464. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1465. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1466. 3:
  1467. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1468. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1469. }
  1470. }
  1471. // Optional item
  1472. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1473. {
  1474. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1475. }
  1476. else
  1477. {
  1478. sprintf((char*)maxProfile.ValidFrom, " ");
  1479. }
  1480. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1481. {
  1482. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1483. }
  1484. else
  1485. {
  1486. sprintf((char*)maxProfile.ValidTo, " ");
  1487. }
  1488. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1489. {
  1490. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1491. }
  1492. else
  1493. {
  1494. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1495. }
  1496. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1497. {
  1498. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1499. }
  1500. else
  1501. {
  1502. maxProfile.TransactionId = -1;
  1503. }
  1504. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1505. {
  1506. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1507. }
  1508. else
  1509. {
  1510. maxProfile.ChargingSchedule.Duration = 86400;
  1511. }
  1512. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1513. {
  1514. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1515. }
  1516. else
  1517. {
  1518. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1519. }
  1520. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1521. {
  1522. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1523. }
  1524. else
  1525. {
  1526. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1527. }
  1528. }
  1529. }
  1530. }
  1531. else
  1532. {
  1533. if(maxProfile.ChargingProfileId == -1)
  1534. DEBUG_INFO("MaxProfile found.\n");
  1535. else
  1536. DEBUG_INFO("MaxProfile updated.\n");
  1537. // Required item
  1538. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1539. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1540. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1541. if(isUnitA)
  1542. {
  1543. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1544. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1545. {
  1546. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1547. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1548. 3:
  1549. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1550. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1551. }
  1552. }
  1553. else
  1554. {
  1555. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1556. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1557. {
  1558. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1559. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1560. 3:
  1561. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1562. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1563. }
  1564. }
  1565. // Optional item
  1566. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1567. {
  1568. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1569. }
  1570. else
  1571. {
  1572. sprintf((char*)maxProfile.ValidFrom, " ");
  1573. }
  1574. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1575. {
  1576. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1577. }
  1578. else
  1579. {
  1580. sprintf((char*)maxProfile.ValidTo, " ");
  1581. }
  1582. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1583. {
  1584. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1585. }
  1586. else
  1587. {
  1588. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1589. }
  1590. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1591. {
  1592. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1593. }
  1594. else
  1595. {
  1596. maxProfile.TransactionId = -1;
  1597. }
  1598. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1599. {
  1600. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1601. }
  1602. else
  1603. {
  1604. maxProfile.ChargingSchedule.Duration = 86400;
  1605. }
  1606. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1607. {
  1608. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1609. }
  1610. else
  1611. {
  1612. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1613. }
  1614. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1615. {
  1616. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1617. }
  1618. else
  1619. {
  1620. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1621. }
  1622. }
  1623. }
  1624. }
  1625. json_object_put(obj);
  1626. }
  1627. fclose(fp);
  1628. /*
  1629. if(maxProfile.ChargingProfileId !=-1)
  1630. {
  1631. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1632. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1633. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1634. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1635. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1636. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1637. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1638. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1639. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1640. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1641. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1642. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1643. {
  1644. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1645. {
  1646. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1647. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1648. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1649. }
  1650. }
  1651. }
  1652. else
  1653. DEBUG_INFO("MaxProfile not found.\n");
  1654. DEBUG_INFO("------------------------------------\n");*/
  1655. }
  1656. /*
  1657. * Align found profile start schedule & periods
  1658. */
  1659. //DEBUG_INFO("====================================\n");
  1660. /*
  1661. // For local test usage, force modify found profile start schedule info
  1662. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-10);
  1663. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-5);
  1664. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-3);
  1665. */
  1666. if(txProfile.ChargingProfileId != -1)
  1667. {
  1668. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1669. {
  1670. if(txProfile.ChargingSchedule.Duration != -1)
  1671. {
  1672. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1673. 0:
  1674. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1675. }
  1676. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1677. {
  1678. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1679. {
  1680. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1681. 0:
  1682. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1683. if(idxPeriod > 0)
  1684. {
  1685. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1686. {
  1687. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1688. }
  1689. }
  1690. }
  1691. }
  1692. }
  1693. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1694. {
  1695. if(txProfile.ChargingSchedule.Duration != -1)
  1696. {
  1697. txProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1698. 0:
  1699. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1700. }
  1701. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1702. {
  1703. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1704. {
  1705. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1706. 0:
  1707. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1708. if(idxPeriod > 0)
  1709. {
  1710. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1711. {
  1712. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1713. }
  1714. }
  1715. }
  1716. }
  1717. }
  1718. else
  1719. {
  1720. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1721. {
  1722. if(txProfile.ChargingSchedule.Duration != -1)
  1723. {
  1724. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1725. 0:
  1726. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1727. }
  1728. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1729. {
  1730. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1731. {
  1732. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1733. 0:
  1734. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1735. if(idxPeriod > 0)
  1736. {
  1737. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1738. {
  1739. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1740. }
  1741. }
  1742. }
  1743. }
  1744. }
  1745. else
  1746. {
  1747. if(txProfile.ChargingSchedule.Duration != -1)
  1748. {
  1749. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1750. 0:
  1751. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1752. }
  1753. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1754. {
  1755. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1756. {
  1757. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1758. 0:
  1759. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1760. if(idxPeriod > 0)
  1761. {
  1762. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1763. {
  1764. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1765. }
  1766. }
  1767. }
  1768. }
  1769. }
  1770. }
  1771. /*
  1772. DEBUG_INFO("txProfile after align.\n");
  1773. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1774. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1775. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1776. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1777. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1778. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1779. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1780. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1781. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1782. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1783. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1784. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1785. {
  1786. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1787. {
  1788. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1789. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1790. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1791. }
  1792. }*/
  1793. }
  1794. if(defaultTxProfile.ChargingProfileId != -1)
  1795. {
  1796. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1797. {
  1798. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1799. {
  1800. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1801. 0:
  1802. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1803. }
  1804. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1805. {
  1806. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1807. {
  1808. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1809. 0:
  1810. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1811. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1812. {
  1813. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1814. }
  1815. if(idxPeriod > 0)
  1816. {
  1817. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1818. {
  1819. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1820. }
  1821. }
  1822. }
  1823. }
  1824. }
  1825. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1826. {
  1827. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1828. {
  1829. defaultTxProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1830. 0:
  1831. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1832. }
  1833. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1834. {
  1835. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1836. {
  1837. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1838. 0:
  1839. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1840. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1841. {
  1842. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1843. }
  1844. if(idxPeriod > 0)
  1845. {
  1846. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1847. {
  1848. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1849. }
  1850. }
  1851. }
  1852. }
  1853. }
  1854. else
  1855. {
  1856. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1857. {
  1858. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1859. {
  1860. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1861. 0:
  1862. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1863. }
  1864. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1865. {
  1866. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1867. {
  1868. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1869. 0:
  1870. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1871. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1872. {
  1873. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1874. }
  1875. if(idxPeriod > 0)
  1876. {
  1877. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1878. {
  1879. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1880. }
  1881. }
  1882. }
  1883. }
  1884. }
  1885. else
  1886. {
  1887. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1888. {
  1889. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1890. 0:
  1891. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1892. }
  1893. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1894. {
  1895. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1896. {
  1897. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1898. 0:
  1899. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1900. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1901. {
  1902. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1903. }
  1904. if(idxPeriod > 0)
  1905. {
  1906. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1907. {
  1908. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1909. }
  1910. }
  1911. }
  1912. }
  1913. }
  1914. }
  1915. /*
  1916. DEBUG_INFO("defaultTxProfile after align.\n");
  1917. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1918. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1919. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1920. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1921. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1922. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1923. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1924. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1925. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1926. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1927. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1928. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1929. {
  1930. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1931. {
  1932. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1933. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1934. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1935. }
  1936. }
  1937. DEBUG_INFO("------------------------------------\n");*/
  1938. }
  1939. if(maxProfile.ChargingProfileId != -1)
  1940. {
  1941. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1942. {
  1943. if(maxProfile.ChargingSchedule.Duration != -1)
  1944. {
  1945. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1946. 0:
  1947. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1948. }
  1949. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1950. {
  1951. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1952. {
  1953. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1954. 0:
  1955. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1956. if(idxPeriod > 0)
  1957. {
  1958. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1959. {
  1960. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1961. }
  1962. }
  1963. }
  1964. }
  1965. }
  1966. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1967. {
  1968. if(maxProfile.ChargingSchedule.Duration != -1)
  1969. {
  1970. maxProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1971. 0:
  1972. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1973. }
  1974. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1975. {
  1976. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1977. {
  1978. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1979. 0:
  1980. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1981. if(idxPeriod > 0)
  1982. {
  1983. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1984. {
  1985. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1986. }
  1987. }
  1988. }
  1989. }
  1990. }
  1991. else
  1992. {
  1993. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1994. {
  1995. if(maxProfile.ChargingSchedule.Duration != -1)
  1996. {
  1997. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1998. 0:
  1999. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2000. }
  2001. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2002. {
  2003. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2004. {
  2005. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2006. 0:
  2007. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2008. if(idxPeriod > 0)
  2009. {
  2010. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2011. {
  2012. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2013. }
  2014. }
  2015. }
  2016. }
  2017. }
  2018. else
  2019. {
  2020. if(maxProfile.ChargingSchedule.Duration != -1)
  2021. {
  2022. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2023. 0:
  2024. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2025. }
  2026. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2027. {
  2028. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2029. {
  2030. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2031. 0:
  2032. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2033. if(idxPeriod > 0)
  2034. {
  2035. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2036. {
  2037. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2038. }
  2039. }
  2040. }
  2041. }
  2042. }
  2043. }
  2044. /*
  2045. DEBUG_INFO("MaxProfile after align.\n");
  2046. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2047. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2048. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2049. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2050. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2051. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2052. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2053. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2054. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2055. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2056. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2057. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2058. {
  2059. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2060. {
  2061. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2062. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2063. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2064. }
  2065. }
  2066. DEBUG_INFO("------------------------------------\n");*/
  2067. }
  2068. /*
  2069. * Merge to conposite schedule
  2070. */
  2071. //DEBUG_INFO("====================================\n");
  2072. // Find each profile period quantity
  2073. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2074. {
  2075. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2076. limitMax = idx+1;
  2077. }
  2078. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2079. {
  2080. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2081. limitDef = idx+1;
  2082. }
  2083. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2084. {
  2085. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2086. limitTx = idx+1;
  2087. }
  2088. // TxProfile found, composite schedule based on it
  2089. if(txProfile.ChargingProfileId != -1)
  2090. {
  2091. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2092. {
  2093. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2094. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2095. (txProfile.ChargingSchedule.Duration > 0))
  2096. {
  2097. if(maxProfile.ChargingProfileId != -1)
  2098. {
  2099. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2100. {
  2101. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2102. {
  2103. if((maxProfile.ChargingSchedule.Duration > 0))
  2104. {
  2105. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2106. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2107. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2108. }
  2109. else
  2110. {
  2111. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2112. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2113. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2114. }
  2115. }
  2116. if(idxMaxPeriod == (limitMax-1))
  2117. {
  2118. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2119. {
  2120. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2121. {
  2122. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2123. compositePeriodIdx++;
  2124. }
  2125. else
  2126. {
  2127. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2128. }
  2129. }
  2130. }
  2131. }
  2132. }
  2133. else
  2134. {
  2135. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2136. {
  2137. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2138. compositePeriodIdx++;
  2139. }
  2140. else
  2141. {
  2142. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2143. }
  2144. }
  2145. }
  2146. if(idxTxPeriod == (limitTx-1))
  2147. {
  2148. if(defaultTxProfile.ChargingProfileId != -1)
  2149. {
  2150. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2151. {
  2152. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  2153. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2154. (defaultTxProfile.ChargingSchedule.Duration>0))
  2155. {
  2156. if(maxProfile.ChargingProfileId != -1)
  2157. {
  2158. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2159. {
  2160. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2161. {
  2162. if((maxProfile.ChargingSchedule.Duration > 0))
  2163. {
  2164. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2165. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2166. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2167. }
  2168. else
  2169. {
  2170. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2171. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2172. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2173. }
  2174. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2175. {
  2176. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2177. {
  2178. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2179. compositePeriodIdx++;
  2180. }
  2181. else
  2182. {
  2183. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2184. }
  2185. }
  2186. break;
  2187. }
  2188. }
  2189. }
  2190. else
  2191. {
  2192. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2193. {
  2194. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2195. compositePeriodIdx++;
  2196. }
  2197. else
  2198. {
  2199. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2200. }
  2201. }
  2202. }
  2203. }
  2204. }
  2205. }
  2206. }
  2207. }
  2208. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2209. else if(defaultTxProfile.ChargingProfileId != -1)
  2210. {
  2211. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2212. {
  2213. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2214. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2215. (defaultTxProfile.ChargingSchedule.Duration > 0))
  2216. {
  2217. if(maxProfile.ChargingProfileId != -1)
  2218. {
  2219. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2220. {
  2221. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2222. {
  2223. if((maxProfile.ChargingSchedule.Duration > 0))
  2224. {
  2225. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2226. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2227. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  2228. }
  2229. else
  2230. {
  2231. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2232. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2233. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2234. }
  2235. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2236. {
  2237. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2238. {
  2239. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2240. compositePeriodIdx++;
  2241. }
  2242. else
  2243. {
  2244. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2245. }
  2246. }
  2247. break;
  2248. }
  2249. }
  2250. }
  2251. else
  2252. {
  2253. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2254. {
  2255. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2256. compositePeriodIdx++;
  2257. }
  2258. else
  2259. {
  2260. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2261. }
  2262. }
  2263. }
  2264. }
  2265. }
  2266. // Fill other period by MaxProfile
  2267. if(maxProfile.ChargingProfileId != -1)
  2268. {
  2269. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2270. {
  2271. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2272. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2273. (maxProfile.ChargingSchedule.Duration > 0))
  2274. {
  2275. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  2276. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2277. {
  2278. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  2279. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  2280. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2281. }
  2282. if((maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2283. {
  2284. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.Duration;
  2285. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  2286. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2287. }
  2288. if(tmpPeriod.Limit != -1)
  2289. {
  2290. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2291. {
  2292. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2293. {
  2294. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2295. compositePeriodIdx++;
  2296. }
  2297. else
  2298. {
  2299. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2300. }
  2301. }
  2302. }
  2303. }
  2304. }
  2305. }
  2306. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  2307. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2308. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  2309. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  2310. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2311. {
  2312. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2313. {
  2314. compositeProfile->ChargingProfileId = 1;
  2315. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2316. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2317. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2318. }
  2319. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2320. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2321. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2322. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2323. }
  2324. if(line)
  2325. free(line);
  2326. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  2327. }
  2328. //==========================================
  2329. // Init all share memory
  2330. //==========================================
  2331. int InitShareMemory()
  2332. {
  2333. int result = PASS;
  2334. int MeterSMId;
  2335. //creat ShmSysConfigAndInfo
  2336. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  2337. {
  2338. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  2339. result = FAIL;
  2340. }
  2341. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2342. {
  2343. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  2344. result = FAIL;
  2345. }
  2346. else
  2347. {}
  2348. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  2349. {
  2350. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  2351. result = FAIL;
  2352. }
  2353. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2354. {
  2355. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  2356. result = FAIL;
  2357. }
  2358. else
  2359. {}
  2360. //creat ShmPsuData
  2361. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  2362. {
  2363. DEBUG_ERROR("shmget ShmPsuData NG\n");
  2364. result = FAIL;
  2365. }
  2366. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2367. {
  2368. DEBUG_ERROR("shmat ShmPsuData NG\n");
  2369. result = FAIL;
  2370. }
  2371. else
  2372. {}
  2373. //creat ShmOCPP16Data
  2374. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  2375. {
  2376. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  2377. result = FAIL;
  2378. }
  2379. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2380. {
  2381. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  2382. result = FAIL;
  2383. }
  2384. else
  2385. {}
  2386. /****************************** For Initial Settings************************************************/
  2387. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  2388. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  2389. // allocate Configuration memory address
  2390. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  2391. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  2392. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  2393. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  2394. //offline MeterValue Interval
  2395. TempMeterValueInterval = 0;
  2396. return result;
  2397. }
  2398. int ProcessShareMemory()
  2399. {
  2400. if(InitShareMemory() == FAIL)
  2401. {
  2402. DEBUG_ERROR("InitShareMemory NG\n");
  2403. if(ShmStatusCodeData!=NULL)
  2404. {
  2405. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  2406. }
  2407. sleep(5);
  2408. return FAIL;
  2409. }
  2410. return PASS;
  2411. }
  2412. void CheckSystemValue(void)
  2413. {
  2414. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  2415. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  2416. char filenmae[100]={0};
  2417. char str[100]={0};
  2418. int tempIndex = 0;
  2419. //===============================
  2420. // send Heartbeat
  2421. //===============================
  2422. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2423. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2424. {
  2425. clientTime.Heartbeat=time((time_t*)NULL);
  2426. if(server_sign == TRUE)
  2427. {
  2428. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2429. }
  2430. else
  2431. {
  2432. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2433. }
  2434. }
  2435. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  2436. {
  2437. //parameter for test
  2438. sendHeartbeatRequest(0);
  2439. //==============================================
  2440. // Reset Waiting Time
  2441. //==============================================
  2442. HeartBeatWithNOResponse += 1;
  2443. }
  2444. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2445. {
  2446. //==========================================
  2447. // csu trigger DataTransferReq
  2448. //==========================================
  2449. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2450. {
  2451. sendDataTransferRequest(gun_index);
  2452. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2453. }
  2454. //===============================
  2455. // CSU Trigger Authorize Request
  2456. //===============================
  2457. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2458. {
  2459. sendAuthorizeRequest(0);
  2460. authorizeRetryTimes = authorizeRetryTimes + 1;
  2461. if(authorizeRetryTimes < 3)
  2462. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2463. }
  2464. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  2465. {
  2466. authorizeRetryTimes = 0;
  2467. SetOcppConnStatus(FALSE);
  2468. server_sign = FALSE;
  2469. }
  2470. 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))
  2471. {
  2472. sendAuthorizeRequest(0);
  2473. }
  2474. //==============================================
  2475. // CSU Trigger Smart Charging Profilw
  2476. //==============================================
  2477. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2478. {
  2479. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  2480. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2481. }
  2482. //==============================================
  2483. // Charger start transaction
  2484. //==============================================
  2485. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2486. {
  2487. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  2488. sendStartTransactionRequest(gun_index);
  2489. clientTime.StartTransaction = time((time_t*)NULL);
  2490. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2491. storeTempStopTransaction(gun_index);
  2492. }
  2493. //==============================================
  2494. // Charger stop transaction
  2495. //==============================================
  2496. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2497. {
  2498. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2499. sendStopTransactionRequest(gun_index);
  2500. clientTime.StopTransaction = time((time_t*)NULL);
  2501. }
  2502. //==============================================
  2503. // Charger status report
  2504. //==============================================
  2505. //--- Check Mode Change ---//
  2506. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2507. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2508. {
  2509. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2510. {
  2511. tempIndex = ((gun_index==2) ? 1: 0);
  2512. }
  2513. else
  2514. {
  2515. tempIndex = gun_index;
  2516. }
  2517. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2518. {
  2519. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2520. {
  2521. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  2522. {
  2523. // Sent unplug message for California pricing logic
  2524. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  2525. {
  2526. uint8_t ts[20];
  2527. getNowDatetime(ts);
  2528. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2529. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2530. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2531. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2532. }
  2533. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2534. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2535. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2536. statusModeChage[gun_index] = TRUE;
  2537. }
  2538. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2539. {
  2540. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2541. if((access(filenmae,F_OK))!=-1)
  2542. {
  2543. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2544. sprintf(str,"rm -f %s",filenmae);
  2545. system(str);
  2546. }
  2547. }
  2548. #if 1 // for TempStopTransaction
  2549. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2550. {
  2551. checkTempStopTransaction(gun_index);
  2552. }
  2553. #endif
  2554. }
  2555. }
  2556. }
  2557. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2558. {
  2559. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2560. {
  2561. tempIndex = ((gun_index==2) ? 1: 0);
  2562. }
  2563. else
  2564. {
  2565. tempIndex = gun_index;
  2566. }
  2567. for (int index = 0; index < CCS_QUANTITY; index++)
  2568. {
  2569. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2570. {
  2571. 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]*/ )
  2572. {
  2573. // Sent unplug message for California pricing logic
  2574. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  2575. {
  2576. uint8_t ts[20];
  2577. getNowDatetime(ts);
  2578. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2579. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2580. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2581. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2582. }
  2583. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2584. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2585. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2586. statusModeChage[gun_index] = TRUE;
  2587. }
  2588. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2589. {
  2590. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2591. if((access(filenmae,F_OK))!=-1)
  2592. {
  2593. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2594. sprintf(str,"rm -f %s",filenmae);
  2595. system(str);
  2596. }
  2597. }
  2598. #if 1 // for TempStopTransaction
  2599. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2600. {
  2601. checkTempStopTransaction(gun_index);
  2602. }
  2603. #endif
  2604. }
  2605. }
  2606. }
  2607. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2608. {
  2609. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2610. {
  2611. tempIndex = ((gun_index==2) ? 1: 0);
  2612. }
  2613. else
  2614. {
  2615. tempIndex = gun_index;
  2616. }
  2617. for (int index = 0; index < GB_QUANTITY; index++)
  2618. {
  2619. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2620. {
  2621. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2622. {
  2623. // Sent unplug message for California pricing logic
  2624. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  2625. {
  2626. uint8_t ts[20];
  2627. getNowDatetime(ts);
  2628. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2629. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2630. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2631. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2632. }
  2633. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2634. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2635. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2636. statusModeChage[gun_index] = TRUE;
  2637. }
  2638. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2639. {
  2640. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2641. if((access(filenmae,F_OK))!=-1)
  2642. {
  2643. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2644. sprintf(str,"rm -f %s",filenmae);
  2645. system(str);
  2646. }
  2647. }
  2648. #if 1 // for TempStopTransaction
  2649. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2650. {
  2651. checkTempStopTransaction(gun_index);
  2652. }
  2653. #endif
  2654. }
  2655. }
  2656. }
  2657. else if(gunType[gun_index] == GUN_TYPE_DO)
  2658. {
  2659. tempIndex = gun_index;
  2660. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2661. {
  2662. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2663. {
  2664. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  2665. {
  2666. // Sent unplug message for California pricing logic
  2667. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  2668. {
  2669. uint8_t ts[20];
  2670. getNowDatetime(ts);
  2671. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2672. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2673. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2674. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2675. }
  2676. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  2677. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  2678. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2679. statusModeChage[gun_index] = TRUE;
  2680. }
  2681. 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
  2682. {
  2683. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2684. if((access(filenmae,F_OK))!=-1)
  2685. {
  2686. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2687. sprintf(str,"rm -f %s",filenmae);
  2688. system(str);
  2689. }
  2690. }
  2691. #if 1 // for TempStopTransaction
  2692. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2693. {
  2694. checkTempStopTransaction(gun_index);
  2695. }
  2696. #endif
  2697. }
  2698. }
  2699. }
  2700. else
  2701. {
  2702. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2703. {
  2704. tempIndex = 2;
  2705. }
  2706. else
  2707. {
  2708. tempIndex = gun_index;
  2709. }
  2710. for (int index = 0; index < AC_QUANTITY; index++)
  2711. {
  2712. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2713. {
  2714. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2715. {
  2716. // Sent unplug message for California pricing logic
  2717. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)
  2718. {
  2719. uint8_t ts[20];
  2720. getNowDatetime(ts);
  2721. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2722. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2723. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2724. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2725. }
  2726. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2727. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2728. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2729. statusModeChage[gun_index] = TRUE;
  2730. }
  2731. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2732. {
  2733. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2734. if((access(filenmae,F_OK))!=-1)
  2735. {
  2736. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2737. sprintf(str,"rm -f %s",filenmae);
  2738. system(str);
  2739. }
  2740. }
  2741. #if 1 // for TempStopTransaction
  2742. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2743. {
  2744. checkTempStopTransaction(gun_index);
  2745. }
  2746. #endif
  2747. }
  2748. }// END
  2749. }
  2750. if(isWebsocketSendable && (server_sign == TRUE) &&
  2751. (
  2752. (statusModeChage[gun_index] == TRUE) ||
  2753. //((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index))) ||
  2754. ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 5))
  2755. )
  2756. )
  2757. {
  2758. if(SystemInitial > 0)
  2759. SystemInitial -= 1;
  2760. sendStatusNotificationRequest(gun_index);
  2761. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2762. statusModeChage[gun_index] = FALSE;
  2763. }
  2764. //==============================================
  2765. // Meter report
  2766. //==============================================
  2767. // Trigger MeterValue
  2768. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  2769. {
  2770. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  2771. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  2772. }
  2773. // ClockAlign MeterValue
  2774. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  2775. {
  2776. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2777. {
  2778. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2779. {
  2780. tempIndex = ((gun_index==2) ? 1: 0);
  2781. }
  2782. else
  2783. {
  2784. tempIndex = gun_index;
  2785. }
  2786. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2787. {
  2788. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2789. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2790. {
  2791. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2792. {
  2793. reqClockAlignMeter[gun_index] = 1;
  2794. }
  2795. }
  2796. }// End for CHAdeMO
  2797. }
  2798. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2799. {
  2800. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2801. {
  2802. tempIndex = ((gun_index==2) ? 1: 0);
  2803. }
  2804. else
  2805. {
  2806. tempIndex = gun_index;
  2807. }
  2808. for (int index = 0; index < CCS_QUANTITY; index++)
  2809. {
  2810. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2811. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2812. {
  2813. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2814. {
  2815. reqClockAlignMeter[gun_index] = 1;
  2816. }
  2817. }
  2818. } // End for CCS
  2819. }
  2820. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2821. {
  2822. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2823. {
  2824. tempIndex = ((gun_index==2) ? 1: 0);
  2825. }
  2826. else
  2827. {
  2828. tempIndex = gun_index;
  2829. }
  2830. for (int index = 0; index < GB_QUANTITY; index++)
  2831. {
  2832. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2833. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2834. {
  2835. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2836. {
  2837. reqClockAlignMeter[gun_index] = 1;
  2838. }
  2839. }
  2840. }// End for GB
  2841. }
  2842. else if(gunType[gun_index] == GUN_TYPE_DO)
  2843. {
  2844. tempIndex = gun_index;
  2845. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2846. {
  2847. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2848. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2849. {
  2850. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_CHARGING)
  2851. {
  2852. reqClockAlignMeter[gun_index] = 1;
  2853. }
  2854. }
  2855. }
  2856. }
  2857. else
  2858. {
  2859. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2860. {
  2861. tempIndex = 2;
  2862. }
  2863. else
  2864. {
  2865. tempIndex = gun_index;
  2866. }
  2867. for (int index = 0; index < AC_QUANTITY; index++)
  2868. {
  2869. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2870. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2871. {
  2872. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2873. {
  2874. reqClockAlignMeter[gun_index] = 1;
  2875. }
  2876. }
  2877. }//End for AC
  2878. }
  2879. if(reqClockAlignMeter[gun_index] == 1)
  2880. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2881. }
  2882. // Sample period MeterValue
  2883. if((((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1))))
  2884. {
  2885. //check Transaction active
  2886. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2887. {
  2888. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2889. {
  2890. tempIndex = ((gun_index==2) ? 1: 0);
  2891. }
  2892. else
  2893. {
  2894. tempIndex = gun_index;
  2895. }
  2896. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2897. {
  2898. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2899. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2900. {
  2901. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2902. {
  2903. reqSampleMeter[gun_index] = 1;
  2904. }
  2905. }
  2906. }// End for CHAdeMO
  2907. }
  2908. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2909. {
  2910. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2911. {
  2912. tempIndex = ((gun_index==2) ? 1: 0);
  2913. }
  2914. else
  2915. {
  2916. tempIndex = gun_index;
  2917. }
  2918. for (int index = 0; index < CCS_QUANTITY; index++)
  2919. {
  2920. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2921. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2922. {
  2923. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2924. {
  2925. reqSampleMeter[gun_index] = 1;
  2926. }
  2927. }
  2928. } // End for CCS
  2929. }
  2930. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2931. {
  2932. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2933. {
  2934. tempIndex = ((gun_index==2) ? 1: 0);
  2935. }
  2936. else
  2937. {
  2938. tempIndex = gun_index;
  2939. }
  2940. for (int index = 0; index < GB_QUANTITY; index++)
  2941. {
  2942. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2943. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2944. {
  2945. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2946. {
  2947. reqSampleMeter[gun_index] = 1;
  2948. }
  2949. }
  2950. }// End for GB
  2951. }
  2952. else if(gunType[gun_index] == GUN_TYPE_DO)
  2953. {
  2954. tempIndex = gun_index;
  2955. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2956. {
  2957. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2958. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2959. {
  2960. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  2961. {
  2962. reqSampleMeter[gun_index] = 1;
  2963. }
  2964. }
  2965. }
  2966. }
  2967. else
  2968. {
  2969. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2970. {
  2971. tempIndex = 2;
  2972. }
  2973. else
  2974. {
  2975. tempIndex = gun_index;
  2976. }
  2977. for (int index = 0; index < AC_QUANTITY; index++)
  2978. {
  2979. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2980. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2981. {
  2982. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  2983. {
  2984. reqSampleMeter[gun_index] = 1;
  2985. }
  2986. }
  2987. }//End for AC
  2988. }
  2989. if(reqSampleMeter[gun_index] == 1)
  2990. {
  2991. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  2992. storeTempStopTransaction(gun_index);
  2993. }
  2994. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2995. }
  2996. //==============================================
  2997. // Check Connector reserved
  2998. //==============================================
  2999. //===============================
  3000. // Check if Reserve is expired
  3001. //===============================
  3002. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  3003. {
  3004. double diff_t;
  3005. struct tm tp;
  3006. // current time
  3007. time_t t = time(NULL);
  3008. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  3009. tp.tm_isdst = -1;
  3010. time_t utc = mktime(&tp);
  3011. diff_t = difftime(utc, t);
  3012. if(diff_t <= 0)
  3013. {
  3014. DEBUG_INFO("reserve expired.\n");
  3015. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  3016. }
  3017. }//END OF Check if Reserve is expired
  3018. //==========================================
  3019. // csu trigger FirmwareStatusNotificationReq
  3020. //==========================================
  3021. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  3022. {
  3023. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  3024. }
  3025. //==========================================
  3026. // csu trigger DiagnosticsStatusNotificationReq
  3027. //==========================================
  3028. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  3029. {
  3030. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  3031. }
  3032. //==========================================
  3033. // csu trigger CancelReservationConf
  3034. //==========================================
  3035. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  3036. {
  3037. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  3038. }
  3039. //==========================================
  3040. // csu trigger ChangeAvailabilityConf
  3041. //==========================================
  3042. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  3043. {
  3044. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  3045. }
  3046. //==========================================
  3047. // csu trigger UnlockConnectorConf
  3048. //==========================================
  3049. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  3050. {
  3051. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  3052. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  3053. }
  3054. //==========================================
  3055. // csu trigger ReserveNowConf
  3056. //==========================================
  3057. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  3058. {
  3059. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  3060. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  3061. }
  3062. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  3063. {
  3064. sendSignCertificateRequest();
  3065. }
  3066. }
  3067. }
  3068. //==========================================
  3069. // send request routine
  3070. //==========================================
  3071. int sendAuthorizeRequest(int gun_index)
  3072. {
  3073. mtrace();
  3074. int result = FAIL;
  3075. char message[100]={0};
  3076. char guid[37];
  3077. char tempdata[65]={0};
  3078. DEBUG_INFO("sendAuthorizeRequest...\n");
  3079. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  3080. //Local Authorize
  3081. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  3082. {
  3083. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  3084. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  3085. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  3086. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  3087. result = PASS;
  3088. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3089. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3090. authorizeRetryTimes = 0;
  3091. return result;
  3092. }
  3093. 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))||
  3094. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  3095. {
  3096. // Query from cache
  3097. DEBUG_INFO("Authorize from cache.\n");
  3098. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3099. // Query from list
  3100. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3101. {
  3102. DEBUG_INFO("Authorize from list.\n");
  3103. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3104. }
  3105. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3106. {
  3107. if(strcmp(idTagQuery.idTagstr,"") == 0)
  3108. {
  3109. DEBUG_INFO("off-line Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  3110. }
  3111. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  3112. {
  3113. DEBUG_INFO("off-line Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  3114. }
  3115. DEBUG_INFO("off-line Local Authorization Fail !!!!\n");
  3116. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3117. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3118. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  3119. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3120. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3121. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3122. authorizeRetryTimes = 0;
  3123. return result;
  3124. }
  3125. else
  3126. {
  3127. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  3128. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3129. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3130. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  3131. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  3132. else
  3133. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  3134. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3135. result = PASS;
  3136. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3137. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3138. authorizeRetryTimes = 0;
  3139. return result;
  3140. }
  3141. }
  3142. //initialize struct Authorize
  3143. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  3144. //get data from shared memory
  3145. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3146. random_uuid(guid);
  3147. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  3148. LWS_Send(message);
  3149. sprintf(tempdata, "Authorize,%d", gun_index);
  3150. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3151. {
  3152. result = PASS;
  3153. DEBUG_INFO("Authorize mapItem pass\n");
  3154. }
  3155. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3156. return result;
  3157. }
  3158. int sendBootNotificationRequest(void)
  3159. {
  3160. mtrace();
  3161. int result = FAIL;
  3162. char message[500]={0}, payload[700]={0};
  3163. char guid[37]={0};
  3164. char tempdata[65]={0};
  3165. // Fill BootNotification fields
  3166. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  3167. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  3168. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  3169. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3170. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  3171. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  3172. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  3173. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  3174. ShmOCPP16Data->ChargeBoxId
  3175. ,ShmSysConfigAndInfo->SysConfig.ModelName
  3176. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  3177. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  3178. ,ShmOCPP16Data->BootNotification.CpFwVersion
  3179. ,ShmOCPP16Data->BootNotification.CpIccid
  3180. ,ShmOCPP16Data->BootNotification.CpImsi);
  3181. random_uuid(guid);
  3182. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  3183. LWS_Send(message);
  3184. sprintf(tempdata, "BootNotification,0");
  3185. 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*/)
  3186. {
  3187. result = PASS;
  3188. }
  3189. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3190. strcpy(queuedata,message);
  3191. return result;
  3192. }
  3193. int sendDataTransferRequest(int gun_index)
  3194. {
  3195. mtrace();
  3196. char message[1000]={0};
  3197. char guid[37]={0};
  3198. char tempdata[65]={0};
  3199. int result = FAIL;
  3200. random_uuid(guid);
  3201. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  3202. MESSAGE_TYPE_CALL,
  3203. guid,
  3204. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  3205. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  3206. ShmOCPP16Data->DataTransfer[gun_index].Data);
  3207. LWS_Send(message);
  3208. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  3209. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3210. {
  3211. result = PASS;
  3212. DEBUG_INFO("DataTransfer mapItem pass\n");
  3213. }
  3214. return result;
  3215. }
  3216. int sendDiagnosticsStatusNotificationRequest(char *status)
  3217. {
  3218. mtrace();
  3219. int result = FAIL;
  3220. char message[110]={0};
  3221. char guid[37]={0};
  3222. char tempdata[65]={0};
  3223. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  3224. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  3225. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  3226. random_uuid(guid);
  3227. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  3228. LWS_SendNow(message);
  3229. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  3230. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3231. {
  3232. result = PASS;
  3233. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  3234. }
  3235. //#ifdef SystemLogMessage
  3236. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  3237. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3238. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  3239. //#endif
  3240. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  3241. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  3242. //record status
  3243. if(strcmp(status,"Idle")==0)
  3244. {
  3245. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  3246. }
  3247. else if(strcmp(status,"Uploaded")==0)
  3248. {
  3249. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  3250. }
  3251. else if(strcmp(status,"UploadFailed")==0)
  3252. {
  3253. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  3254. }
  3255. else if(strcmp(status,"Uploading")==0)
  3256. {
  3257. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  3258. }
  3259. return result;
  3260. }
  3261. int sendFirmwareStatusNotificationRequest(char *status)
  3262. {
  3263. mtrace();
  3264. int result = FAIL;
  3265. char message[110]={0};
  3266. char guid[37]={0};
  3267. char tempdata[65]={0};
  3268. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  3269. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  3270. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  3271. random_uuid(guid);
  3272. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  3273. LWS_SendNow(message);
  3274. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  3275. 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*/)
  3276. {
  3277. result = PASS;
  3278. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  3279. }
  3280. //#ifdef SystemLogMessage
  3281. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  3282. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3283. //#endif
  3284. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  3285. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  3286. //record status
  3287. if(strcmp(status,"Downloaded")==0)
  3288. {
  3289. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  3290. }
  3291. else if(strcmp(status,"DownloadFailed")==0)
  3292. {
  3293. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  3294. }
  3295. else if(strcmp(status,"Downloading")==0)
  3296. {
  3297. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  3298. }
  3299. else if(strcmp(status,"Idle")==0)
  3300. {
  3301. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  3302. }
  3303. else if(strcmp(status,"InstallationFailed")==0)
  3304. {
  3305. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  3306. }
  3307. else if(strcmp(status,"Installing")==0)
  3308. {
  3309. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  3310. }
  3311. else if(strcmp(status,"Installed")==0)
  3312. {
  3313. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  3314. }
  3315. return result;
  3316. }
  3317. int sendHeartbeatRequest(int gun_index)
  3318. {
  3319. mtrace();
  3320. int result = FAIL;
  3321. char message[80]={0};
  3322. char guid[37]={0};
  3323. char tempdata[65]={0};
  3324. random_uuid(guid);
  3325. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  3326. , MESSAGE_TYPE_CALL
  3327. , guid );
  3328. LWS_Send(message);
  3329. sprintf(tempdata, "Heartbeat,%d", 0);
  3330. 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*/)
  3331. {
  3332. result = PASS;
  3333. }
  3334. return result;
  3335. }
  3336. int sendStartTransactionRequest(int gun_index)
  3337. {
  3338. mtrace();
  3339. int result = FAIL;
  3340. char message[250]={0};
  3341. char guid[37]={0};
  3342. struct timeval tmnow;
  3343. struct tm *tm;
  3344. char buf[28];//, usec_buf[6];
  3345. char tempdata[65]={0};
  3346. int tempIndex = 0;
  3347. DEBUG_INFO("sendStartTransactionRequest...\n");
  3348. gettimeofday(&tmnow, NULL);
  3349. time_t t;
  3350. t = time(NULL);
  3351. /*UTC time and date*/
  3352. tm = gmtime(&t);
  3353. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3354. #if 0 // remove temporally
  3355. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3356. strcat(buf,".");
  3357. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3358. strcat(buf,usec_buf);
  3359. #endif
  3360. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  3361. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  3362. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3363. // clear StartTransaction Response
  3364. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  3365. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  3366. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  3367. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  3368. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3369. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3370. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3371. {
  3372. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3373. {
  3374. tempIndex = ((gun_index==2) ? 1: 0);
  3375. }
  3376. else
  3377. {
  3378. tempIndex = gun_index;
  3379. }
  3380. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3381. {
  3382. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3383. {
  3384. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3385. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  3386. }
  3387. }
  3388. }
  3389. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3390. {
  3391. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3392. {
  3393. tempIndex = ((gun_index==2) ? 1: 0);
  3394. }
  3395. else
  3396. {
  3397. tempIndex = gun_index;
  3398. }
  3399. for (int index = 0; index < CCS_QUANTITY; index++)
  3400. {
  3401. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3402. {
  3403. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3404. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  3405. }
  3406. }
  3407. }
  3408. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3409. {
  3410. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3411. {
  3412. tempIndex = ((gun_index==2) ? 1: 0);
  3413. }
  3414. else
  3415. {
  3416. tempIndex = gun_index;
  3417. }
  3418. for (int index = 0; index < GB_QUANTITY; index++)
  3419. {
  3420. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3421. {
  3422. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3423. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  3424. }
  3425. }
  3426. }
  3427. else if(gunType[gun_index] == GUN_TYPE_DO)
  3428. {
  3429. tempIndex = gun_index;
  3430. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3431. {
  3432. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3433. {
  3434. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3435. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  3436. }
  3437. }
  3438. }
  3439. else
  3440. {
  3441. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3442. {
  3443. tempIndex = 2;
  3444. }
  3445. else
  3446. {
  3447. tempIndex = gun_index;
  3448. }
  3449. for (int index = 0; index < AC_QUANTITY; index++)
  3450. {
  3451. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3452. {
  3453. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3454. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  3455. }
  3456. }
  3457. }
  3458. random_uuid(guid);
  3459. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  3460. {
  3461. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  3462. , gun_index +1
  3463. , MESSAGE_TYPE_CALL
  3464. , guid
  3465. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3466. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3467. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3468. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3469. }
  3470. else
  3471. {
  3472. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  3473. , gun_index +1
  3474. , MESSAGE_TYPE_CALL
  3475. , guid
  3476. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3477. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3478. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3479. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  3480. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3481. }
  3482. #if 1
  3483. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  3484. 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*/)
  3485. {
  3486. result = PASS;
  3487. }
  3488. #endif
  3489. strcpy(queuedata, message);
  3490. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3491. OCPP_insert_transaction_msg(YES, queuedata);
  3492. return result;
  3493. }
  3494. int sendStatusNotificationRequest(int gun_index)
  3495. {
  3496. mtrace();
  3497. int result = FAIL;
  3498. char message[600]={0};
  3499. char guid[37];
  3500. int currentStatus = 0;
  3501. struct timeval tmnow;
  3502. struct tm *tm;
  3503. char buf[28];//, usec_buf[6];
  3504. char tempdata[65]={0};
  3505. int tempIndex = 0;
  3506. uint8_t isStateChanged = TRUE;
  3507. DEBUG_INFO("sendStatusNotificationRequest...\n");
  3508. gettimeofday(&tmnow, NULL);
  3509. time_t t;
  3510. t = time(NULL);
  3511. /*UTC time and date*/
  3512. tm = gmtime(&t);
  3513. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3514. #if 0 // remove temporally
  3515. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3516. strcat(buf,".");
  3517. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3518. strcat(buf,usec_buf);
  3519. #endif
  3520. printf("%s",buf);
  3521. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  3522. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  3523. // it's option
  3524. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  3525. /*
  3526. enum _SYSTEM_STATUS
  3527. {
  3528. S_BOOTING = 0,
  3529. S_IDLE, = 1
  3530. S_AUTHORIZING, =2
  3531. S_REASSIGN_CHECK, =3
  3532. S_REASSIGN, =4
  3533. S_PRECHARGE, =5
  3534. S_PREPARING_FOR_EV, =6
  3535. S_PREPARING_FOR_EVSE, =7
  3536. S_CHARGING, =8
  3537. S_TERMINATING, =9
  3538. S_COMPLETE, =10
  3539. S_ALARM, =11
  3540. S_FAULT =12
  3541. }
  3542. */
  3543. //check Transaction active
  3544. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3545. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3546. {
  3547. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3548. {
  3549. tempIndex = ((gun_index==2) ? 1: 0);
  3550. }
  3551. else
  3552. {
  3553. tempIndex = gun_index;
  3554. }
  3555. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3556. {
  3557. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  3558. {
  3559. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  3560. {
  3561. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3562. {
  3563. currentStatus = Preparing; //OCPP Status: Preparing
  3564. }
  3565. else
  3566. {
  3567. currentStatus = Available; //OCPP Status: Available
  3568. }
  3569. }
  3570. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3571. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3572. ) //S_PRECHARGE
  3573. {
  3574. currentStatus = Preparing; //OCPP Status: Preparing
  3575. }
  3576. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3577. {
  3578. currentStatus = Charging; //OCPP Status: Charging
  3579. }
  3580. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3581. {
  3582. currentStatus = Finishing; //OCPP Status: Finishing
  3583. }
  3584. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3585. {
  3586. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3587. }
  3588. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  3589. {
  3590. currentStatus = Unavailable; //OCPP Status: Unavailable
  3591. }
  3592. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3593. {
  3594. currentStatus = Faulted; //OCPP Status: Faulted
  3595. }
  3596. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3597. {
  3598. currentStatus = Reserved; //OCPP Status: Reserved
  3599. }
  3600. } //end of the same index
  3601. }//end of for CHAdeMO_QUANTITY
  3602. }
  3603. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3604. {
  3605. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3606. {
  3607. tempIndex = ((gun_index==2) ? 1: 0);
  3608. }
  3609. else
  3610. {
  3611. tempIndex = gun_index;
  3612. }
  3613. for (int index = 0; index < CCS_QUANTITY; index++)
  3614. {
  3615. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3616. {
  3617. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3618. {
  3619. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3620. {
  3621. currentStatus = Preparing; //OCPP Status: Preparing
  3622. }
  3623. else
  3624. {
  3625. currentStatus = Available; //OCPP Status: Available
  3626. }
  3627. }
  3628. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3629. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3630. ) //S_PRECHARGE
  3631. {
  3632. currentStatus = Preparing; //OCPP Status: Preparing
  3633. }
  3634. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3635. {
  3636. currentStatus = Charging; //OCPP Status: Charging
  3637. }
  3638. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3639. {
  3640. currentStatus = Finishing; //OCPP Status: Finishing
  3641. }
  3642. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3643. {
  3644. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3645. }
  3646. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  3647. {
  3648. currentStatus = Unavailable; //OCPP Status : Unavailable
  3649. }
  3650. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3651. {
  3652. currentStatus = Faulted; //OCPP Status: Faulted
  3653. }
  3654. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3655. {
  3656. currentStatus = Reserved; //OCPP Status: Reserved
  3657. }
  3658. } //end of the same index
  3659. } // end of for CCS_QUANTITY
  3660. }
  3661. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3662. {
  3663. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3664. {
  3665. tempIndex = ((gun_index==2) ? 1: 0);
  3666. }
  3667. else
  3668. {
  3669. tempIndex = gun_index;
  3670. }
  3671. for (int index = 0; index < GB_QUANTITY; index++)
  3672. {
  3673. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3674. {
  3675. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3676. {
  3677. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3678. {
  3679. currentStatus = Preparing; //OCPP Status: Preparing
  3680. }
  3681. else
  3682. {
  3683. currentStatus = Available; //OCPP Status: Available
  3684. }
  3685. }
  3686. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3687. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3688. ) //S_PRECHARGE
  3689. {
  3690. currentStatus = Preparing; //OCPP Status: Preparing
  3691. }
  3692. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3693. {
  3694. currentStatus = Charging; //OCPP Status: Charging
  3695. }
  3696. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3697. {
  3698. currentStatus = Finishing; //OCPP Status: Finishing
  3699. }
  3700. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3701. {
  3702. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3703. }
  3704. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  3705. {
  3706. currentStatus = Unavailable; //OCPP Status: Unavailable
  3707. }
  3708. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3709. {
  3710. currentStatus = Faulted; //OCPP Status: Faulted
  3711. }
  3712. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3713. {
  3714. currentStatus = Reserved; //OCPP Status: Reserved
  3715. }
  3716. } //end of the same index
  3717. } // end of for GB_QUANTITY
  3718. }
  3719. else if(gunType[gun_index] == GUN_TYPE_DO)
  3720. {
  3721. tempIndex = gun_index;
  3722. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3723. {
  3724. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3725. {
  3726. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3727. {
  3728. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3729. {
  3730. currentStatus = Preparing; //OCPP Status: Preparing
  3731. }
  3732. else
  3733. {
  3734. currentStatus = Available; //OCPP Status: Available
  3735. }
  3736. }
  3737. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3738. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3739. ) //S_PRECHARGE
  3740. {
  3741. currentStatus = Preparing; //OCPP Status: Preparing
  3742. }
  3743. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3744. {
  3745. currentStatus = Charging; //OCPP Status: Charging
  3746. }
  3747. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3748. {
  3749. currentStatus = Finishing; //OCPP Status: Finishing
  3750. }
  3751. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3752. {
  3753. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3754. }
  3755. else if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  3756. {
  3757. currentStatus = Unavailable; //OCPP Status: Unavailable
  3758. }
  3759. 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
  3760. {
  3761. currentStatus = Faulted; //OCPP Status: Faulted
  3762. }
  3763. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3764. {
  3765. currentStatus = Reserved; //OCPP Status: Reserved
  3766. }
  3767. } //end of the same index
  3768. }
  3769. }
  3770. else
  3771. {
  3772. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3773. {
  3774. tempIndex = 2;
  3775. }
  3776. else
  3777. {
  3778. tempIndex = gun_index;
  3779. }
  3780. for (int index = 0; index < AC_QUANTITY; index++)
  3781. {
  3782. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3783. {
  3784. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3785. {
  3786. 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))
  3787. {
  3788. currentStatus = Preparing; //OCPP Status: Preparing
  3789. }
  3790. else
  3791. {
  3792. currentStatus = Available; //OCPP Status: Available
  3793. }
  3794. }
  3795. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3796. {
  3797. currentStatus = Preparing; //OCPP Status: Preparing
  3798. }
  3799. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3800. {
  3801. currentStatus = Charging; //OCPP Status: Charging
  3802. }
  3803. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3804. {
  3805. currentStatus = Finishing; //OCPP Status: Finishing
  3806. }
  3807. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3808. {
  3809. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3810. }
  3811. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  3812. {
  3813. currentStatus = Unavailable; //OCPP Status: Unavailable
  3814. }
  3815. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3816. {
  3817. currentStatus = Faulted; //OCPP Status: Faulted
  3818. }
  3819. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3820. {
  3821. currentStatus = Reserved; //OCPP Status: Reserved
  3822. }
  3823. }//end of the same index
  3824. }//end of for AC_QUANTITY
  3825. }
  3826. //it's option
  3827. if((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) &&
  3828. !ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq)
  3829. {
  3830. isStateChanged = FALSE;
  3831. }
  3832. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  3833. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3834. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3835. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3836. random_uuid(guid);
  3837. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3838. , MESSAGE_TYPE_CALL
  3839. , guid
  3840. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3841. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3842. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3843. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3844. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3845. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3846. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3847. if((server_sign == TRUE) && isStateChanged)
  3848. {
  3849. LWS_Send(message);
  3850. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3851. 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*/)
  3852. {
  3853. //DEBUG_ERROR("statusNotification mapitem pass");
  3854. result = PASS;
  3855. }
  3856. }
  3857. else
  3858. {
  3859. result = PASS;
  3860. }
  3861. return result;
  3862. }
  3863. int sendStopTransactionRequest(int gun_index)
  3864. {
  3865. mtrace();
  3866. int result = FAIL;
  3867. //char message[1500]={0};
  3868. char guid[37]={0};
  3869. char tempdata[65]={0};
  3870. int tempIndex = 0;
  3871. char TempStopTransaction[256];
  3872. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  3873. //int idx_sample=0;
  3874. DEBUG_INFO("sendStopTransactionRequest \n");
  3875. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3876. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  3877. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3878. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3879. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3880. {
  3881. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3882. {
  3883. tempIndex = ((gun_index==2) ? 1: 0);
  3884. }
  3885. else
  3886. {
  3887. tempIndex = gun_index;
  3888. }
  3889. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3890. {
  3891. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3892. {
  3893. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3894. }
  3895. }// END OF CHAdeMO_QUANTITY
  3896. }
  3897. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3898. {
  3899. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3900. {
  3901. tempIndex = ((gun_index==2) ? 1: 0);
  3902. }
  3903. else
  3904. {
  3905. tempIndex = gun_index;
  3906. }
  3907. for (int index = 0; index < CCS_QUANTITY; index++)
  3908. {
  3909. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3910. {
  3911. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3912. }
  3913. }// END OF CCS_QUANTITY
  3914. }
  3915. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3916. {
  3917. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3918. {
  3919. tempIndex = ((gun_index==2) ? 1: 0);
  3920. }
  3921. else
  3922. {
  3923. tempIndex = gun_index;
  3924. }
  3925. for (int index = 0; index < GB_QUANTITY; index++)
  3926. {
  3927. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3928. {
  3929. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3930. }
  3931. }// END OF GB_QUANTITY
  3932. }
  3933. else if(gunType[gun_index] == GUN_TYPE_DO)
  3934. {
  3935. tempIndex = gun_index;
  3936. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3937. {
  3938. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3939. {
  3940. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3941. }
  3942. }// END OF GB_QUANTITY
  3943. }
  3944. else
  3945. {
  3946. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3947. {
  3948. tempIndex = 2;
  3949. }
  3950. else
  3951. {
  3952. tempIndex = gun_index;
  3953. }
  3954. for (int index = 0; index < AC_QUANTITY; index++)
  3955. {
  3956. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3957. {
  3958. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3959. }
  3960. }// END OF AC_QUANTITY
  3961. }
  3962. //====================================== Stop Transaction Time =====================================================
  3963. struct timeval tmnow;
  3964. struct tm *tm;
  3965. char buf[28];//, usec_buf[6];
  3966. gettimeofday(&tmnow, NULL);
  3967. time_t t;
  3968. t = time(NULL);
  3969. /*UTC time and date*/
  3970. tm = gmtime(&t);
  3971. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3972. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  3973. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  3974. random_uuid(guid);
  3975. /***********************************transactionData******************************************************/
  3976. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  3977. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  3978. //=================================
  3979. // Transaction_Begin
  3980. //=================================
  3981. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  3982. {
  3983. //============================================ Energy.Active.Import.Interval ================================
  3984. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  3985. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  3986. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  3987. 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*/]);
  3988. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3989. 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))
  3990. {
  3991. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  3992. }
  3993. else
  3994. {
  3995. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  3996. }
  3997. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  3998. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3999. }
  4000. //=================================
  4001. // Transaction_End
  4002. //=================================
  4003. // ================================= Current.Import L1 ===============================================
  4004. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4005. {
  4006. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  4007. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  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 < CHAdeMO_QUANTITY; index++)
  4018. {
  4019. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4020. {
  4021. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4022. }
  4023. }// End of for CHAdeMO_QUANTITY
  4024. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4025. }
  4026. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4027. {
  4028. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4029. {
  4030. tempIndex = ((gun_index==2) ? 1: 0);
  4031. }
  4032. else
  4033. {
  4034. tempIndex = gun_index;
  4035. }
  4036. for (int index = 0; index < CCS_QUANTITY; index++)
  4037. {
  4038. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4039. {
  4040. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4041. }
  4042. }// End of for CCS_QUANTITY
  4043. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4044. }
  4045. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4046. {
  4047. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4048. {
  4049. tempIndex = ((gun_index==2) ? 1: 0);
  4050. }
  4051. else
  4052. {
  4053. tempIndex = gun_index;
  4054. }
  4055. for (int index = 0; index < GB_QUANTITY; index++)
  4056. {
  4057. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4058. {
  4059. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4060. }
  4061. }// End of for GB_QUANTITY
  4062. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4063. }
  4064. else if(gunType[gun_index] == GUN_TYPE_DO)
  4065. {
  4066. tempIndex = gun_index;
  4067. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4068. {
  4069. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4070. {
  4071. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4072. }
  4073. }
  4074. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4075. }
  4076. else
  4077. {
  4078. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4079. {
  4080. tempIndex = 2;
  4081. }
  4082. else
  4083. {
  4084. tempIndex = gun_index;
  4085. }
  4086. for (int index = 0; index < AC_QUANTITY; index++)
  4087. {
  4088. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4089. {
  4090. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  4091. }
  4092. }// End of for AC_QUANTITY
  4093. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  4094. }
  4095. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4096. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  4097. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  4098. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  4099. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4100. }
  4101. // ================================= Energy.Active.Import.Interval ==============================================
  4102. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4103. {
  4104. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4105. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4106. {
  4107. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4108. {
  4109. tempIndex = ((gun_index==2) ? 1: 0);
  4110. }
  4111. else
  4112. {
  4113. tempIndex = gun_index;
  4114. }
  4115. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4116. {
  4117. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4118. {
  4119. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4120. }
  4121. }// END OF CHAdeMO_QUANTITY
  4122. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4123. }
  4124. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4125. {
  4126. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4127. {
  4128. tempIndex = ((gun_index==2) ? 1: 0);
  4129. }
  4130. else
  4131. {
  4132. tempIndex = gun_index;
  4133. }
  4134. for (int index = 0; index < CCS_QUANTITY; index++)
  4135. {
  4136. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4137. {
  4138. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4139. }
  4140. }// END OF CCS_QUANTITY
  4141. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4142. }
  4143. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4144. {
  4145. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4146. {
  4147. tempIndex = ((gun_index==2) ? 1: 0);
  4148. }
  4149. else
  4150. {
  4151. tempIndex = gun_index;
  4152. }
  4153. for (int index = 0; index < GB_QUANTITY; index++)
  4154. {
  4155. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4156. {
  4157. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4158. }
  4159. }// END OF GB_QUANTITY
  4160. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4161. }
  4162. else if(gunType[gun_index] == GUN_TYPE_DO)
  4163. {
  4164. tempIndex = gun_index;
  4165. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4166. {
  4167. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4168. {
  4169. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4170. }
  4171. }
  4172. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4173. }
  4174. else
  4175. {
  4176. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4177. {
  4178. tempIndex = 2;
  4179. }
  4180. else
  4181. {
  4182. tempIndex = gun_index;
  4183. }
  4184. for (int index = 0; index < AC_QUANTITY; index++)
  4185. {
  4186. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4187. {
  4188. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4189. }
  4190. }// END OF AC_QUANTITY
  4191. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  4192. }
  4193. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4194. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  4195. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  4196. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  4197. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4198. }
  4199. //=================================== Power.Active.Import ==================================================
  4200. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  4201. {
  4202. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4203. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4204. {
  4205. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4206. {
  4207. tempIndex = ((gun_index==2) ? 1: 0);
  4208. }
  4209. else
  4210. {
  4211. tempIndex = gun_index;
  4212. }
  4213. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4214. {
  4215. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4216. {
  4217. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4218. }
  4219. } // End for CHAdeMO_QUANTITY
  4220. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4221. }
  4222. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4223. {
  4224. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4225. {
  4226. tempIndex = ((gun_index==2) ? 1: 0);
  4227. }
  4228. else
  4229. {
  4230. tempIndex = gun_index;
  4231. }
  4232. for (int index = 0; index < CCS_QUANTITY; index++)
  4233. {
  4234. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4235. {
  4236. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4237. }
  4238. } // END for CCS_QUANTITY
  4239. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4240. }
  4241. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4242. {
  4243. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4244. {
  4245. tempIndex = ((gun_index==2) ? 1: 0);
  4246. }
  4247. else
  4248. {
  4249. tempIndex = gun_index;
  4250. }
  4251. for (int index = 0; index < GB_QUANTITY; index++)
  4252. {
  4253. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4254. {
  4255. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4256. }
  4257. }// END for GB_QUANTITY
  4258. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4259. }
  4260. else if(gunType[gun_index] == GUN_TYPE_DO)
  4261. {
  4262. tempIndex = gun_index;
  4263. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4264. {
  4265. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4266. {
  4267. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4268. }
  4269. }
  4270. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4271. }
  4272. else
  4273. {
  4274. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4275. {
  4276. tempIndex = 2;
  4277. }
  4278. else
  4279. {
  4280. tempIndex = gun_index;
  4281. }
  4282. for (int index = 0; index < AC_QUANTITY; index++)
  4283. {
  4284. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4285. {
  4286. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4287. }
  4288. } // END for AC_QUANTITY
  4289. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  4290. }
  4291. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4292. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  4293. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  4294. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  4295. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  4296. }
  4297. //============================ Voltage L1 ====================================
  4298. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4299. {
  4300. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4301. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4302. {
  4303. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4304. {
  4305. tempIndex = ((gun_index==2) ? 1: 0);
  4306. }
  4307. else
  4308. {
  4309. tempIndex = gun_index;
  4310. }
  4311. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4312. {
  4313. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4314. {
  4315. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4316. }
  4317. } // END OF FOR CHAdeMO_QUANTITY
  4318. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4319. }
  4320. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4321. {
  4322. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4323. {
  4324. tempIndex = ((gun_index==2) ? 1: 0);
  4325. }
  4326. else
  4327. {
  4328. tempIndex = gun_index;
  4329. }
  4330. for (int index = 0; index < CCS_QUANTITY; index++)
  4331. {
  4332. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4333. {
  4334. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4335. }
  4336. } // END OF FOR CCS_QUANTITY
  4337. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4338. }
  4339. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4340. {
  4341. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4342. {
  4343. tempIndex = ((gun_index==2) ? 1: 0);
  4344. }
  4345. else
  4346. {
  4347. tempIndex = gun_index;
  4348. }
  4349. for (int index = 0; index < GB_QUANTITY; index++)
  4350. {
  4351. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4352. {
  4353. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4354. }
  4355. } // END OF FOR GB_QUANTITY
  4356. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4357. }
  4358. else if(gunType[gun_index] == GUN_TYPE_DO)
  4359. {
  4360. tempIndex = gun_index;
  4361. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4362. {
  4363. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4364. {
  4365. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4366. }
  4367. }
  4368. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4369. }
  4370. else
  4371. {
  4372. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4373. {
  4374. tempIndex = 2;
  4375. }
  4376. else
  4377. {
  4378. tempIndex = gun_index;
  4379. }
  4380. for (int index = 0; index < AC_QUANTITY; index++)
  4381. {
  4382. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4383. {
  4384. 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
  4385. }
  4386. } // END OF FOR AC_QUANTITY
  4387. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  4388. }
  4389. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4390. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  4391. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  4392. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  4393. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4394. }
  4395. //====================== End SoC ================================
  4396. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4397. {
  4398. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4399. 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))
  4400. {
  4401. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4402. {
  4403. tempIndex = ((gun_index==2) ? 1: 0);
  4404. }
  4405. else
  4406. {
  4407. tempIndex = gun_index;
  4408. }
  4409. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4410. {
  4411. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4412. {
  4413. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4414. {
  4415. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  4416. }
  4417. }
  4418. }
  4419. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4420. {
  4421. for (int index = 0; index < CCS_QUANTITY; index++)
  4422. {
  4423. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4424. {
  4425. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  4426. }
  4427. }
  4428. }
  4429. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4430. {
  4431. for (int index = 0; index < GB_QUANTITY; index++)
  4432. {
  4433. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4434. {
  4435. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  4436. }
  4437. }
  4438. }
  4439. else if(gunType[gun_index] == GUN_TYPE_DO)
  4440. {
  4441. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4442. {
  4443. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4444. {
  4445. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  4446. }
  4447. }
  4448. }
  4449. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4450. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  4451. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4452. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  4453. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  4454. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4455. } // END FOR DC CASE
  4456. }
  4457. // ================================= Current.Import L2 ===============================================
  4458. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4459. {
  4460. // AC 3 phse L2 current
  4461. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4462. {
  4463. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4464. {
  4465. tempIndex = 2;
  4466. }
  4467. else
  4468. {
  4469. tempIndex = gun_index;
  4470. }
  4471. for (int index = 0; index < AC_QUANTITY; index++)
  4472. {
  4473. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4474. {
  4475. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  4476. }
  4477. }// End of for AC_QUANTITY
  4478. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  4479. }
  4480. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4481. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  4482. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  4483. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  4484. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4485. }
  4486. // ================================= Current.Import L3 ===============================================
  4487. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4488. {
  4489. // AC 3 phse L3 current
  4490. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4491. {
  4492. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4493. {
  4494. tempIndex = 2;
  4495. }
  4496. else
  4497. {
  4498. tempIndex = gun_index;
  4499. }
  4500. for (int index = 0; index < AC_QUANTITY; index++)
  4501. {
  4502. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4503. {
  4504. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  4505. }
  4506. }// End of for AC_QUANTITY
  4507. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  4508. }
  4509. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4510. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  4511. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  4512. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  4513. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4514. }
  4515. //============================ Voltage L2 ====================================
  4516. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4517. {
  4518. // AC 3 phse L2 voltage
  4519. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4520. {
  4521. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4522. {
  4523. tempIndex = 2;
  4524. }
  4525. else
  4526. {
  4527. tempIndex = gun_index;
  4528. }
  4529. for (int index = 0; index < AC_QUANTITY; index++)
  4530. {
  4531. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4532. {
  4533. 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
  4534. }
  4535. } // END OF FOR AC_QUANTITY
  4536. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  4537. }
  4538. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4539. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  4540. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  4541. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  4542. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4543. }
  4544. //============================ Voltage L3 ====================================
  4545. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4546. {
  4547. // AC 3 phse L3 voltage
  4548. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4549. {
  4550. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4551. {
  4552. tempIndex = 2;
  4553. }
  4554. else
  4555. {
  4556. tempIndex = gun_index;
  4557. }
  4558. for (int index = 0; index < AC_QUANTITY; index++)
  4559. {
  4560. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4561. {
  4562. 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
  4563. }
  4564. } // END OF FOR AC_QUANTITY
  4565. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  4566. }
  4567. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4568. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  4569. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  4570. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  4571. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4572. }
  4573. //====================== Start SoC ================================
  4574. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4575. {
  4576. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4577. 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))
  4578. {
  4579. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4580. {
  4581. tempIndex = ((gun_index==2) ? 1: 0);
  4582. }
  4583. else
  4584. {
  4585. tempIndex = gun_index;
  4586. }
  4587. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4588. {
  4589. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4590. {
  4591. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4592. {
  4593. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  4594. }
  4595. }
  4596. }
  4597. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4598. {
  4599. for (int index = 0; index < CCS_QUANTITY; index++)
  4600. {
  4601. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4602. {
  4603. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  4604. }
  4605. }
  4606. }
  4607. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4608. {
  4609. for (int index = 0; index < GB_QUANTITY; index++)
  4610. {
  4611. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4612. {
  4613. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  4614. }
  4615. }
  4616. }
  4617. else if(gunType[gun_index] == GUN_TYPE_DO)
  4618. {
  4619. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4620. {
  4621. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4622. {
  4623. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  4624. }
  4625. }
  4626. }
  4627. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4628. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  4629. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4630. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  4631. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  4632. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4633. } // END FOR DC CASE
  4634. }
  4635. //================================================ Message create ====================================================
  4636. json_object *StopTransaction = json_object_new_object();
  4637. json_object *transactionDatas = json_object_new_array();
  4638. json_object *sampledValues = json_object_new_array();
  4639. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  4640. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  4641. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  4642. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  4643. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  4644. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  4645. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  4646. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  4647. {
  4648. json_object *transactionData = json_object_new_object();
  4649. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  4650. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  4651. {
  4652. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  4653. {
  4654. json_object *sampledValue = json_object_new_object();
  4655. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  4656. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  4657. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  4658. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  4659. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  4660. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  4661. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  4662. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  4663. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  4664. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  4665. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  4666. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  4667. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  4668. json_object_array_add(sampledValues, sampledValue);
  4669. }
  4670. }
  4671. json_object_object_add(transactionData, "sampledValue", sampledValues);
  4672. json_object_array_add(transactionDatas, transactionData);
  4673. }
  4674. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  4675. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  4676. ,MESSAGE_TYPE_CALL
  4677. ,guid
  4678. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  4679. json_object_put(StopTransaction);
  4680. #if 1 // for TempStopTransaction
  4681. //Delete TempStopTransaction
  4682. if((access(TempStopTransaction,F_OK))!=-1)
  4683. {
  4684. remove(TempStopTransaction); // remove file "TempStopTransaction"
  4685. }
  4686. #endif
  4687. #if 1
  4688. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4689. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4690. {
  4691. result = PASS;
  4692. //DEBUG_INFO("StopTransaction mapitem pass\n");
  4693. }
  4694. #endif
  4695. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4696. OCPP_insert_transaction_msg(NO, queuedata);
  4697. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4698. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4699. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  4700. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4701. {
  4702. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4703. }
  4704. //for test
  4705. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4706. return result;
  4707. }
  4708. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4709. {
  4710. mtrace();
  4711. int result = FAIL;
  4712. char guid[37]={0};
  4713. char tempdata[65]={0};
  4714. int tempIndex = 0;
  4715. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4716. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4717. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  4718. //set value
  4719. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4720. 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) )?
  4721. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  4722. -1);
  4723. random_uuid(guid);
  4724. //UTC Date time
  4725. struct timeval tmnow;
  4726. struct tm *tm;
  4727. char buf[28];//, usec_buf[6];
  4728. gettimeofday(&tmnow, NULL);
  4729. time_t t;
  4730. t = time(NULL);
  4731. /*UTC time and date*/
  4732. tm = gmtime(&t);
  4733. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4734. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4735. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4736. //********************************(1)Current.Import L1************************************************/
  4737. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  4738. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  4739. (dataType == ReadingContext_Trigger))
  4740. {
  4741. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4742. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4743. {
  4744. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4745. {
  4746. tempIndex = ((gun_index==2) ? 1: 0);
  4747. }
  4748. else
  4749. {
  4750. tempIndex = gun_index;
  4751. }
  4752. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4753. {
  4754. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4755. {
  4756. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4757. }
  4758. }
  4759. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4760. }
  4761. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4762. {
  4763. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4764. {
  4765. tempIndex = ((gun_index==2) ? 1: 0);
  4766. }
  4767. else
  4768. {
  4769. tempIndex = gun_index;
  4770. }
  4771. for (int index = 0; index < CCS_QUANTITY; index++)
  4772. {
  4773. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4774. {
  4775. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4776. }
  4777. }
  4778. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4779. }
  4780. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4781. {
  4782. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4783. {
  4784. tempIndex = ((gun_index==2) ? 1: 0);
  4785. }
  4786. else
  4787. {
  4788. tempIndex = gun_index;
  4789. }
  4790. for (int index = 0; index < GB_QUANTITY; index++)
  4791. {
  4792. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4793. {
  4794. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4795. }
  4796. }
  4797. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4798. }
  4799. else if(gunType[gun_index] == GUN_TYPE_DO)
  4800. {
  4801. tempIndex = gun_index;
  4802. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4803. {
  4804. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4805. {
  4806. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  4807. }
  4808. }
  4809. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4810. }
  4811. else
  4812. {
  4813. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4814. {
  4815. tempIndex = 2;
  4816. }
  4817. else
  4818. {
  4819. tempIndex = gun_index;
  4820. }
  4821. for (int index = 0; index < AC_QUANTITY; index++)
  4822. {
  4823. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4824. {
  4825. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4826. }
  4827. }
  4828. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4829. }
  4830. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4831. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4832. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4833. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4834. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4835. }
  4836. //********************************(2)Energy.Active.Import.Register ************************************************/
  4837. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4838. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4839. (dataType == ReadingContext_Trigger))
  4840. {
  4841. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4842. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4843. {
  4844. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4845. {
  4846. tempIndex = ((gun_index==2) ? 1: 0);
  4847. }
  4848. else
  4849. {
  4850. tempIndex = gun_index;
  4851. }
  4852. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4853. {
  4854. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4855. {
  4856. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4857. }
  4858. }
  4859. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4860. }
  4861. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4862. {
  4863. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4864. {
  4865. tempIndex = ((gun_index==2) ? 1: 0);
  4866. }
  4867. else
  4868. {
  4869. tempIndex = gun_index;
  4870. }
  4871. for (int index = 0; index < CCS_QUANTITY; index++)
  4872. {
  4873. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4874. {
  4875. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4876. }
  4877. }
  4878. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4879. }
  4880. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4881. {
  4882. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4883. {
  4884. tempIndex = ((gun_index==2) ? 1: 0);
  4885. }
  4886. else
  4887. {
  4888. tempIndex = gun_index;
  4889. }
  4890. for (int index = 0; index < GB_QUANTITY; index++)
  4891. {
  4892. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4893. {
  4894. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4895. }
  4896. }
  4897. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4898. }
  4899. else if(gunType[gun_index] == GUN_TYPE_DO)
  4900. {
  4901. tempIndex = gun_index;
  4902. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4903. {
  4904. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4905. {
  4906. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  4907. }
  4908. }
  4909. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4910. }
  4911. else
  4912. {
  4913. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4914. {
  4915. tempIndex = 2;
  4916. }
  4917. else
  4918. {
  4919. tempIndex = gun_index;
  4920. }
  4921. for (int index = 0; index < AC_QUANTITY; index++)
  4922. {
  4923. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4924. {
  4925. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4926. }
  4927. }
  4928. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4929. }
  4930. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  4931. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4932. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4933. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4934. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4935. }
  4936. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  4937. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  4938. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  4939. (dataType == ReadingContext_Trigger))
  4940. {
  4941. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4942. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4943. {
  4944. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4945. {
  4946. tempIndex = ((gun_index==2) ? 1: 0);
  4947. }
  4948. else
  4949. {
  4950. tempIndex = gun_index;
  4951. }
  4952. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4953. {
  4954. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4955. {
  4956. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4957. }
  4958. } // END OF FOR CHAdeMO_QUANTITY
  4959. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4960. }
  4961. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4962. {
  4963. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4964. {
  4965. tempIndex = ((gun_index==2) ? 1: 0);
  4966. }
  4967. else
  4968. {
  4969. tempIndex = gun_index;
  4970. }
  4971. for (int index = 0; index < CCS_QUANTITY; index++)
  4972. {
  4973. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4974. {
  4975. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  4976. }
  4977. } // END OF CCS_QUANTITY
  4978. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4979. }
  4980. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4981. {
  4982. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4983. {
  4984. tempIndex = ((gun_index==2) ? 1: 0);
  4985. }
  4986. else
  4987. {
  4988. tempIndex = gun_index;
  4989. }
  4990. for (int index = 0; index < GB_QUANTITY; index++)
  4991. {
  4992. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4993. {
  4994. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  4995. }
  4996. } // END OF GB_QUANTITY
  4997. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4998. }
  4999. else if(gunType[gun_index] == GUN_TYPE_DO)
  5000. {
  5001. tempIndex = gun_index;
  5002. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5003. {
  5004. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5005. {
  5006. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  5007. }
  5008. }
  5009. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5010. }
  5011. else
  5012. {
  5013. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5014. {
  5015. tempIndex = 2;
  5016. }
  5017. else
  5018. {
  5019. tempIndex = gun_index;
  5020. }
  5021. for (int index = 0; index < AC_QUANTITY; index++)
  5022. {
  5023. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5024. {
  5025. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  5026. }
  5027. }
  5028. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  5029. }
  5030. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  5031. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  5032. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  5033. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  5034. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5035. }
  5036. //********************************(4)Power.Active.Import************************************************/
  5037. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Power.Active.Import") != NULL)) ||
  5038. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Power.Active.Import") != NULL)) ||
  5039. (dataType == ReadingContext_Trigger))
  5040. {
  5041. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5042. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5043. {
  5044. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5045. {
  5046. tempIndex = ((gun_index==2) ? 1: 0);
  5047. }
  5048. else
  5049. {
  5050. tempIndex = gun_index;
  5051. }
  5052. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5053. {
  5054. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5055. {
  5056. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  5057. }
  5058. } // END OF FOR
  5059. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5060. }
  5061. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5062. {
  5063. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5064. {
  5065. tempIndex = ((gun_index==2) ? 1: 0);
  5066. }
  5067. else
  5068. {
  5069. tempIndex = gun_index;
  5070. }
  5071. for (int index = 0; index < CCS_QUANTITY; index++)
  5072. {
  5073. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5074. {
  5075. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  5076. }
  5077. }
  5078. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5079. }
  5080. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5081. {
  5082. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5083. {
  5084. tempIndex = ((gun_index==2) ? 1: 0);
  5085. }
  5086. else
  5087. {
  5088. tempIndex = gun_index;
  5089. }
  5090. for (int index = 0; index < GB_QUANTITY; index++)
  5091. {
  5092. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5093. {
  5094. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5095. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  5096. }
  5097. }
  5098. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5099. }
  5100. else if(gunType[gun_index] == GUN_TYPE_DO)
  5101. {
  5102. tempIndex = gun_index;
  5103. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5104. {
  5105. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5106. {
  5107. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5108. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  5109. }
  5110. }
  5111. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5112. }
  5113. else
  5114. {
  5115. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5116. {
  5117. tempIndex = 2;
  5118. }
  5119. else
  5120. {
  5121. tempIndex = gun_index;
  5122. }
  5123. for (int index = 0; index < AC_QUANTITY; index++)
  5124. {
  5125. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5126. {
  5127. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  5128. }
  5129. }
  5130. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  5131. }
  5132. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  5133. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  5134. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  5135. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  5136. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  5137. }
  5138. //***********************************************(5)VOLTAGE L1******************************************************/
  5139. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5140. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5141. (dataType == ReadingContext_Trigger))
  5142. {
  5143. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5144. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5145. {
  5146. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5147. {
  5148. tempIndex = ((gun_index==2) ? 1: 0);
  5149. }
  5150. else
  5151. {
  5152. tempIndex = gun_index;
  5153. }
  5154. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5155. {
  5156. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5157. {
  5158. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  5159. }
  5160. }
  5161. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5162. }
  5163. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5164. {
  5165. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5166. {
  5167. tempIndex = ((gun_index==2) ? 1: 0);
  5168. }
  5169. else
  5170. {
  5171. tempIndex = gun_index;
  5172. }
  5173. for (int index = 0; index < CCS_QUANTITY; index++)
  5174. {
  5175. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5176. {
  5177. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  5178. }
  5179. }
  5180. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5181. }
  5182. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5183. {
  5184. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5185. {
  5186. tempIndex = ((gun_index==2) ? 1: 0);
  5187. }
  5188. else
  5189. {
  5190. tempIndex = gun_index;
  5191. }
  5192. for (int index = 0; index < GB_QUANTITY; index++)
  5193. {
  5194. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5195. {
  5196. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  5197. }
  5198. }
  5199. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5200. }
  5201. else if(gunType[gun_index] == GUN_TYPE_DO)
  5202. {
  5203. tempIndex = gun_index;
  5204. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5205. {
  5206. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5207. {
  5208. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  5209. }
  5210. }
  5211. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5212. }
  5213. else
  5214. {
  5215. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5216. {
  5217. tempIndex = 2;
  5218. }
  5219. else
  5220. {
  5221. tempIndex = gun_index;
  5222. }
  5223. for (int index = 0; index < AC_QUANTITY; index++)
  5224. {
  5225. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5226. {
  5227. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  5228. }
  5229. }
  5230. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  5231. }
  5232. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  5233. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  5234. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  5235. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  5236. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5237. }
  5238. //***********************************************(6)SOC******************************************************/
  5239. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "SOC") != NULL)) ||
  5240. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "SOC") != NULL)) ||
  5241. (dataType == ReadingContext_Trigger))
  5242. {
  5243. 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))
  5244. {
  5245. //idx_sample=5;
  5246. //sampledValue = NULL;
  5247. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5248. {
  5249. tempIndex = ((gun_index==2) ? 1: 0);
  5250. }
  5251. else
  5252. {
  5253. tempIndex = gun_index;
  5254. }
  5255. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5256. {
  5257. //tempIndex = ((gun_index==2) ? 1: 0);
  5258. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5259. {
  5260. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5261. {
  5262. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  5263. }
  5264. }
  5265. }
  5266. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5267. {
  5268. //tempIndex = ((gun_index==2) ? 1: 0);
  5269. for (int index = 0; index < CCS_QUANTITY; index++)
  5270. {
  5271. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5272. {
  5273. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  5274. }
  5275. }
  5276. }
  5277. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5278. {
  5279. //tempIndex = ((gun_index==2) ? 1: 0);
  5280. for (int index = 0; index < GB_QUANTITY; index++)
  5281. {
  5282. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5283. {
  5284. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  5285. }
  5286. }
  5287. }
  5288. else if(gunType[gun_index] == GUN_TYPE_DO)
  5289. {
  5290. //tempIndex = ((gun_index==2) ? 1: 0);
  5291. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5292. {
  5293. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5294. {
  5295. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  5296. }
  5297. }
  5298. }
  5299. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  5300. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  5301. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  5302. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  5303. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  5304. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  5305. }
  5306. }
  5307. //********************************(7)Current.Import L2************************************************/
  5308. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5309. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5310. (dataType == ReadingContext_Trigger))
  5311. {
  5312. // Only for AC 3 phase
  5313. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5314. {
  5315. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5316. {
  5317. tempIndex = 2;
  5318. }
  5319. else
  5320. {
  5321. tempIndex = gun_index;
  5322. }
  5323. for (int index = 0; index < AC_QUANTITY; index++)
  5324. {
  5325. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5326. {
  5327. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  5328. }
  5329. }
  5330. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  5331. }
  5332. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  5333. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  5334. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  5335. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  5336. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5337. }
  5338. //********************************(8)Current.Import L3************************************************/
  5339. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5340. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5341. (dataType == ReadingContext_Trigger))
  5342. {
  5343. // Only for AC 3 phase
  5344. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5345. {
  5346. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5347. {
  5348. tempIndex = 2;
  5349. }
  5350. else
  5351. {
  5352. tempIndex = gun_index;
  5353. }
  5354. for (int index = 0; index < AC_QUANTITY; index++)
  5355. {
  5356. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5357. {
  5358. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  5359. }
  5360. }
  5361. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  5362. }
  5363. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  5364. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  5365. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  5366. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  5367. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5368. }
  5369. //***********************************************(9)VOLTAGE L2******************************************************/
  5370. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5371. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5372. (dataType == ReadingContext_Trigger))
  5373. {
  5374. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5375. {
  5376. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5377. {
  5378. tempIndex = 2;
  5379. }
  5380. else
  5381. {
  5382. tempIndex = gun_index;
  5383. }
  5384. for (int index = 0; index < AC_QUANTITY; index++)
  5385. {
  5386. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5387. {
  5388. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  5389. }
  5390. }
  5391. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  5392. }
  5393. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  5394. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  5395. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  5396. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  5397. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5398. }
  5399. //***********************************************(10)VOLTAGE L3******************************************************/
  5400. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5401. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5402. (dataType == ReadingContext_Trigger))
  5403. {
  5404. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5405. {
  5406. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5407. {
  5408. tempIndex = 2;
  5409. }
  5410. else
  5411. {
  5412. tempIndex = gun_index;
  5413. }
  5414. for (int index = 0; index < AC_QUANTITY; index++)
  5415. {
  5416. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5417. {
  5418. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  5419. }
  5420. }
  5421. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  5422. }
  5423. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  5424. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  5425. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  5426. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  5427. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5428. }
  5429. // Message create ====================================================================================================
  5430. if(TRUE)
  5431. {
  5432. json_object *MeterValueReq = json_object_new_object();
  5433. json_object *MeterValues = json_object_new_array();
  5434. json_object *sampledValues = json_object_new_array();
  5435. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  5436. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  5437. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  5438. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  5439. {
  5440. json_object *MeterValue = json_object_new_object();
  5441. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  5442. {
  5443. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  5444. {
  5445. json_object *sampledValue = json_object_new_object();
  5446. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  5447. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  5448. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  5449. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  5450. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  5451. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  5452. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  5453. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  5454. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  5455. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  5456. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  5457. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  5458. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  5459. json_object_array_add(sampledValues, sampledValue);
  5460. }
  5461. }
  5462. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  5463. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  5464. json_object_array_add(MeterValues, MeterValue);
  5465. }
  5466. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  5467. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  5468. ,gun_index + 1
  5469. ,MESSAGE_TYPE_CALL
  5470. ,guid
  5471. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  5472. json_object_put(MeterValueReq);
  5473. }
  5474. // Put request guid to hash map
  5475. sprintf(tempdata, "MeterValues,%d", (gun_index));
  5476. 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*/)
  5477. {
  5478. result = PASS;
  5479. //DEBUG_INFO("MeterValues mapitem pass\n");
  5480. }
  5481. if((dataType != ReadingContext_Trigger) &&
  5482. (dataType != ReadingContext_Sample_Clock) &&
  5483. (ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1))
  5484. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  5485. else
  5486. {
  5487. if(FirstHeartBeat)
  5488. LWS_Send(queuedata +2);
  5489. }
  5490. return result;
  5491. }
  5492. int sendLogStatusNotificationRequest(char *status)
  5493. {
  5494. mtrace();
  5495. int result = PASS;
  5496. char message[4096]={0};
  5497. char guid[37]={0};
  5498. char tempdata[128]={0};
  5499. json_object *LogStatusNotification = json_object_new_object();
  5500. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  5501. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  5502. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  5503. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  5504. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  5505. random_uuid(guid);
  5506. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  5507. json_object_put(LogStatusNotification);
  5508. LWS_Send(message);
  5509. sprintf(tempdata, "LogStatusNotification,%d", 0);
  5510. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5511. {
  5512. result = PASS;
  5513. }
  5514. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  5515. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  5516. return result;
  5517. }
  5518. int sendSecurityEventNotificationRequest()
  5519. {
  5520. mtrace();
  5521. int result = PASS;
  5522. char message[4096]={0};
  5523. char guid[37]={0};
  5524. char tempdata[128]={0};
  5525. json_object *SecurityEventNotification = json_object_new_object();
  5526. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  5527. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  5528. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  5529. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  5530. random_uuid(guid);
  5531. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  5532. json_object_put(SecurityEventNotification);
  5533. LWS_Send(message);
  5534. sprintf(tempdata, "SecurityEventNotification,0");
  5535. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5536. {
  5537. result = PASS;
  5538. }
  5539. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  5540. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  5541. return result;
  5542. }
  5543. int sendSignCertificateRequest()
  5544. {
  5545. mtrace();
  5546. int result = PASS;
  5547. char message[4096]={0};
  5548. char guid[37]={0};
  5549. char tempdata[128]={0};
  5550. json_object *SignCertificate = json_object_new_object();
  5551. DEBUG_INFO("sendSignCertificateRequest...\n");
  5552. // Read csr file content
  5553. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  5554. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  5555. char *line = NULL;
  5556. size_t len = 0;
  5557. while(getline(&line, &len, fp) != -1)
  5558. {
  5559. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  5560. {
  5561. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  5562. }
  5563. }
  5564. fclose(fp);
  5565. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  5566. random_uuid(guid);
  5567. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  5568. json_object_put(SignCertificate);
  5569. LWS_Send(message);
  5570. sprintf(tempdata, "SignCertificate,0");
  5571. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5572. {
  5573. result = PASS;
  5574. }
  5575. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  5576. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  5577. return result;
  5578. }
  5579. int sendSignedFirmwareStatusNotificationRequest(char *status)
  5580. {
  5581. mtrace();
  5582. int result = PASS;
  5583. char message[110]={0};
  5584. char guid[37]={0};
  5585. char tempdata[65]={0};
  5586. json_object *FirmwareStatusNotification = json_object_new_object();
  5587. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  5588. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  5589. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  5590. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  5591. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  5592. random_uuid(guid);
  5593. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  5594. json_object_put(FirmwareStatusNotification);
  5595. LWS_Send(message);
  5596. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5597. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5598. {
  5599. result = PASS;
  5600. }
  5601. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  5602. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  5603. return result;
  5604. }
  5605. //==========================================
  5606. // send confirm routine
  5607. //==========================================
  5608. int sendCancelReservationConfirmation(char *uuid,char *payload)
  5609. {
  5610. mtrace();
  5611. int result = FAIL;
  5612. char message[100]={0};
  5613. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  5614. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5615. LWS_Send(message);
  5616. result = TRUE;
  5617. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  5618. return result;
  5619. }
  5620. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  5621. {
  5622. mtrace();
  5623. int result = FAIL;
  5624. char message[100]={0};
  5625. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  5626. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5627. LWS_Send(message);
  5628. result = TRUE;
  5629. return result;
  5630. }
  5631. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  5632. {
  5633. mtrace();
  5634. int result = FAIL;
  5635. char message[100]={0};
  5636. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  5637. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5638. LWS_Send(message);
  5639. result = TRUE;
  5640. return result;
  5641. }
  5642. int sendClearCacheConfirmation(char *uuid,char *payload)
  5643. {
  5644. mtrace();
  5645. int result = FAIL;
  5646. char message[500]={0};
  5647. DEBUG_INFO("sendClearCacheConfirmation...\n");
  5648. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5649. LWS_Send(message);
  5650. return result;
  5651. }
  5652. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  5653. {
  5654. mtrace();
  5655. int result = FAIL;
  5656. char message[500]={0};
  5657. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  5658. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5659. LWS_Send(message);
  5660. return result;
  5661. }
  5662. int sendDataTransferConfirmation(char *uuid,char *payload)
  5663. {
  5664. mtrace();
  5665. char statusStr[20]={0};
  5666. char dataStr[10]={0};
  5667. char sstr[20]={0};
  5668. int c = 0;
  5669. char *loc;
  5670. int result = FAIL;
  5671. DEBUG_INFO("sendDataTransferConfirmation...\n");
  5672. /**********************status**************************/
  5673. loc = strstr(payload, "status");
  5674. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5675. c = 0;
  5676. while (loc[3+strlen("status")+c] != '\"')
  5677. {
  5678. sstr[c] = loc[3+strlen("status")+c];
  5679. c++;
  5680. }
  5681. sstr[c] = '\0';
  5682. strcpy(statusStr, sstr);
  5683. /**********************data**************************/
  5684. loc = strstr(payload, "data");
  5685. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5686. c = 0;
  5687. while (loc[3+strlen("data")+c] != '\"')
  5688. {
  5689. sstr[c] = loc[3+strlen("data")+c];
  5690. c++;
  5691. }
  5692. sstr[c] = '\0';
  5693. strcpy(dataStr, sstr);
  5694. return result;
  5695. }
  5696. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  5697. {
  5698. mtrace();
  5699. int result = FAIL;
  5700. char message[1000]={0};
  5701. int CompositeScheduleIndex = 0;
  5702. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  5703. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  5704. if(nPeriod == 0)
  5705. {
  5706. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  5707. {
  5708. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  5709. ,MESSAGE_TYPE_CALLRESULT
  5710. ,uuid
  5711. ,payload
  5712. ,connectorIdInt);
  5713. }
  5714. else
  5715. {
  5716. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  5717. ,MESSAGE_TYPE_CALLRESULT
  5718. ,uuid
  5719. ,payload
  5720. ,connectorIdInt
  5721. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5722. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5723. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5724. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  5725. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  5726. }
  5727. }
  5728. else
  5729. {
  5730. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  5731. ,MESSAGE_TYPE_CALLRESULT
  5732. ,uuid
  5733. ,payload
  5734. ,connectorIdInt
  5735. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5736. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5737. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5738. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  5739. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  5740. {
  5741. if (idx_sample == 0)
  5742. {
  5743. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5744. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5745. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5746. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5747. }
  5748. else
  5749. {
  5750. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5751. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5752. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5753. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5754. }
  5755. }
  5756. sprintf(message + strlen(message), "]}}]");
  5757. }
  5758. LWS_Send(message);
  5759. result = TRUE;
  5760. return result;
  5761. }
  5762. int sendGetConfigurationConfirmation(char *uuid)
  5763. {
  5764. mtrace();
  5765. int result = FAIL;
  5766. int MaxKeySupported = 0;
  5767. int sentConfigurationNumber= 0;
  5768. int sentunConfigurationNumber= 0;
  5769. char message[4000]={0};
  5770. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5771. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5772. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5773. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5774. ,MESSAGE_TYPE_CALLRESULT
  5775. ,uuid );
  5776. //configuration key
  5777. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5778. {
  5779. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5780. {
  5781. if (sentConfigurationNumber == 0)
  5782. {
  5783. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5784. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5785. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5786. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5787. }
  5788. else
  5789. {
  5790. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5791. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5792. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5793. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5794. }
  5795. sentConfigurationNumber = sentConfigurationNumber + 1;
  5796. }
  5797. }
  5798. sprintf(message + strlen(message), "]");
  5799. if(UnknownKeynum != 0)
  5800. {
  5801. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5802. //unkown key
  5803. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5804. {
  5805. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5806. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5807. if(sentunConfigurationNumber == 0)
  5808. {
  5809. sprintf(message + strlen(message), "\"%s\""
  5810. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5811. }
  5812. else
  5813. {
  5814. sprintf(message + strlen(message), ",\"%s\""
  5815. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5816. }
  5817. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5818. }
  5819. sprintf(message + strlen(message), "]");
  5820. }
  5821. sprintf(message + strlen(message), "}]");
  5822. LWS_Send(message);
  5823. return result;
  5824. }
  5825. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5826. {
  5827. mtrace();
  5828. int result = FAIL;
  5829. char message[400]={0};
  5830. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5831. if(strcmp(payload,"")==0)
  5832. {
  5833. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5834. }
  5835. else
  5836. {
  5837. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5838. }
  5839. LWS_Send(message);
  5840. result = TRUE;
  5841. return result;
  5842. }
  5843. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5844. {
  5845. mtrace();
  5846. int result = FAIL;
  5847. char message[80]={0};
  5848. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5849. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  5850. LWS_Send(message);
  5851. result = TRUE;
  5852. return result;
  5853. }
  5854. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5855. {
  5856. mtrace();
  5857. int result = FAIL;
  5858. char message[80]={0};
  5859. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5860. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5861. LWS_Send(message);
  5862. result = TRUE;
  5863. return result;
  5864. }
  5865. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5866. {
  5867. mtrace();
  5868. int result = FAIL;
  5869. char message[80]={0};
  5870. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5871. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5872. LWS_Send(message);
  5873. result = TRUE;
  5874. return result;
  5875. }
  5876. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5877. {
  5878. mtrace();
  5879. int result = FAIL;
  5880. char message[80]={0};
  5881. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5882. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5883. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5884. LWS_Send(message);
  5885. result = TRUE;
  5886. return result;
  5887. }
  5888. int sendResetConfirmation(char *uuid,char *payload)
  5889. {
  5890. mtrace();
  5891. int result = FAIL;
  5892. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  5893. char message[80]={0};
  5894. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  5895. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5896. LWS_Send(message);
  5897. result = TRUE;
  5898. return result;
  5899. }
  5900. int sendSendLocalListConfirmation(char *uuid,char *payload)
  5901. {
  5902. mtrace();
  5903. int result = FAIL;
  5904. char message[500]={0};
  5905. // [ 3, "1571284266109", { "status": "Accepted" } ]
  5906. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5907. LWS_Send(message);
  5908. result = TRUE;
  5909. return result;
  5910. }
  5911. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  5912. {
  5913. mtrace();
  5914. int result = FAIL;
  5915. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  5916. char message[80]={0};
  5917. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  5918. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5919. LWS_Send(message);
  5920. result = TRUE;
  5921. return result;
  5922. }
  5923. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  5924. {
  5925. mtrace();
  5926. int result = FAIL;
  5927. char message[80]={0};
  5928. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  5929. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5930. LWS_Send(message);
  5931. result = TRUE;
  5932. return result;
  5933. }
  5934. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  5935. {
  5936. mtrace();
  5937. int result = FAIL;
  5938. char message[80]={0};
  5939. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5940. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  5941. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5942. LWS_Send(message);
  5943. result = TRUE;
  5944. return result;
  5945. }
  5946. int sendUpdateFirmwareConfirmation(char *uuid)
  5947. {
  5948. mtrace();
  5949. int result = FAIL;
  5950. char message[60]={0};
  5951. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5952. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  5953. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5954. LWS_Send(message);
  5955. result = TRUE;
  5956. return result;
  5957. }
  5958. int sendCertificateSignedConfirmation(char *uuid)
  5959. {
  5960. mtrace();
  5961. int result = PASS;
  5962. char message[4096]={0};
  5963. json_object *CertificateSigned = json_object_new_object();
  5964. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  5965. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  5966. sprintf(message,"[%d,\"%s\",%s]"
  5967. ,MESSAGE_TYPE_CALLRESULT
  5968. ,uuid
  5969. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  5970. json_object_put(CertificateSigned);
  5971. LWS_Send(message);
  5972. return result;
  5973. }
  5974. int sendDeleteCertificateConfirmation(char *uuid)
  5975. {
  5976. mtrace();
  5977. int result = PASS;
  5978. char message[4096]={0};
  5979. json_object *DeleteCertificate = json_object_new_object();
  5980. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  5981. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  5982. sprintf(message,"[%d,\"%s\",%s]"
  5983. ,MESSAGE_TYPE_CALLRESULT
  5984. ,uuid
  5985. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  5986. json_object_put(DeleteCertificate);
  5987. LWS_Send(message);
  5988. return result;
  5989. }
  5990. int sendExtendedTriggerMessageConfirmation(char *uuid)
  5991. {
  5992. mtrace();
  5993. int result = PASS;
  5994. char message[4096]={0};
  5995. json_object *ExtendedTriggerMessage = json_object_new_object();
  5996. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  5997. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  5998. sprintf(message,"[%d,\"%s\",%s]"
  5999. ,MESSAGE_TYPE_CALLRESULT
  6000. ,uuid
  6001. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  6002. json_object_put(ExtendedTriggerMessage);
  6003. LWS_Send(message);
  6004. return result;
  6005. }
  6006. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  6007. {
  6008. mtrace();
  6009. int result = PASS;
  6010. char message[4096]={0};
  6011. json_object *GetInstalledCertificateIds = json_object_new_object();
  6012. json_object *certificateHashDataDatas = json_object_new_array();
  6013. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  6014. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  6015. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  6016. {
  6017. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  6018. {
  6019. json_object *certificateHashData = json_object_new_object();
  6020. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  6021. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  6022. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  6023. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  6024. json_object_array_add(certificateHashDataDatas, certificateHashData);
  6025. }
  6026. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  6027. }
  6028. else
  6029. {
  6030. json_object_put(certificateHashDataDatas);
  6031. }
  6032. sprintf(message,"[%d,\"%s\",%s]"
  6033. ,MESSAGE_TYPE_CALLRESULT
  6034. ,uuid
  6035. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  6036. json_object_put(GetInstalledCertificateIds);
  6037. LWS_Send(message);
  6038. return result;
  6039. }
  6040. int sendGetLogConfirmation(char *uuid)
  6041. {
  6042. mtrace();
  6043. int result = PASS;
  6044. char message[4096]={0};
  6045. json_object *GetLog = json_object_new_object();
  6046. DEBUG_INFO("sendGetLogConfirmation...\n");
  6047. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  6048. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  6049. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  6050. sprintf(message,"[%d,\"%s\",%s]"
  6051. ,MESSAGE_TYPE_CALLRESULT
  6052. ,uuid
  6053. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  6054. json_object_put(GetLog);
  6055. LWS_Send(message);
  6056. return result;
  6057. }
  6058. int sendInstallCertificateConfirmation(char *uuid)
  6059. {
  6060. mtrace();
  6061. int result = PASS;
  6062. char message[4096]={0};
  6063. json_object *InstallCertificate = json_object_new_object();
  6064. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  6065. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  6066. sprintf(message,"[%d,\"%s\",%s]"
  6067. ,MESSAGE_TYPE_CALLRESULT
  6068. ,uuid
  6069. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  6070. json_object_put(InstallCertificate);
  6071. LWS_Send(message);
  6072. return result;
  6073. }
  6074. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  6075. {
  6076. mtrace();
  6077. int result = PASS;
  6078. char message[4096]={0};
  6079. json_object *SignedUpdateFirmware = json_object_new_object();
  6080. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  6081. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  6082. sprintf(message,"[%d,\"%s\",%s]"
  6083. ,MESSAGE_TYPE_CALLRESULT
  6084. ,uuid
  6085. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  6086. json_object_put(SignedUpdateFirmware);
  6087. LWS_Send(message);
  6088. return result;
  6089. }
  6090. int sendUnknownConfirmation(char *uuid)
  6091. {
  6092. mtrace();
  6093. int result = PASS;
  6094. char message[256]={0};
  6095. DEBUG_INFO("sendUnknownConfirmation...\n");
  6096. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  6097. LWS_Send(message);
  6098. return result;
  6099. }
  6100. //==========================================
  6101. // Handle server request routine Start
  6102. //==========================================
  6103. int handleCancelReservationRequest(char *uuid, char *payload)
  6104. {
  6105. mtrace();
  6106. int result = FAIL;
  6107. int gunNO = 0;
  6108. int reservationIdInt = -1;
  6109. char comfirmstr[20];
  6110. DEBUG_INFO("handleCancelReservationRequest...\n");
  6111. json_object *CancelReservation;
  6112. CancelReservation = json_tokener_parse(payload);
  6113. if(!is_error(CancelReservation))
  6114. {
  6115. // Required data
  6116. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  6117. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  6118. }
  6119. json_object_put(CancelReservation);
  6120. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  6121. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6122. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  6123. if(reservationIdInt != -1)
  6124. {
  6125. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6126. //check Transaction active
  6127. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6128. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6129. {
  6130. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  6131. {
  6132. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6133. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6134. if(gunType[2] == GUN_TYPE_CHAdeMO)
  6135. {
  6136. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  6137. }
  6138. else
  6139. {
  6140. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  6141. }
  6142. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6143. goto end;
  6144. }
  6145. }
  6146. for (int index = 0; index < CCS_QUANTITY; index++)
  6147. {
  6148. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  6149. {
  6150. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6151. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6152. if(gunType[2] == GUN_TYPE_CCS)
  6153. {
  6154. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  6155. }
  6156. else
  6157. {
  6158. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  6159. }
  6160. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6161. goto end;
  6162. }
  6163. }
  6164. for (int index = 0; index < GB_QUANTITY; index++)
  6165. {
  6166. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  6167. {
  6168. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6169. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6170. if(gunType[2] == GUN_TYPE_GBT)
  6171. {
  6172. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  6173. }
  6174. else
  6175. {
  6176. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  6177. }
  6178. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6179. goto end;
  6180. }
  6181. }
  6182. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6183. {
  6184. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  6185. {
  6186. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6187. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6188. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  6189. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6190. goto end;
  6191. }
  6192. }
  6193. for (int index = 0; index < AC_QUANTITY; index++)
  6194. {
  6195. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  6196. {
  6197. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6198. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6199. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6200. {
  6201. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  6202. }
  6203. else
  6204. {
  6205. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  6206. }
  6207. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6208. goto end;
  6209. }
  6210. }
  6211. }
  6212. //The reservationId does NOT match the reservationId
  6213. sendCancelReservationConfirmation(uuid, comfirmstr);
  6214. end:
  6215. // Fill in ocpp packet uuid
  6216. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  6217. return result;
  6218. }
  6219. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  6220. {
  6221. mtrace();
  6222. int result = FAIL;
  6223. int gunIndex = 0;
  6224. char typeStr[16]={0};
  6225. char comfirmstr[20];
  6226. int specificId = FALSE;
  6227. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  6228. json_object *ChangeAvailability;
  6229. ChangeAvailability = json_tokener_parse(payload);
  6230. if(!is_error(ChangeAvailability))
  6231. {
  6232. // Required data
  6233. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  6234. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  6235. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  6236. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  6237. }
  6238. json_object_put(ChangeAvailability);
  6239. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6240. {
  6241. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  6242. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  6243. }
  6244. else if(gunIndex == 0)
  6245. {
  6246. for(int i=0; i < gunTotalNumber; i++)
  6247. {
  6248. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  6249. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  6250. }
  6251. }
  6252. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6253. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6254. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  6255. {
  6256. specificId = TRUE;
  6257. }
  6258. if(specificId == FALSE)
  6259. goto end;
  6260. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  6261. {
  6262. //----------------------gunIndex is 0 ------------------------------------------------//
  6263. if(gunIndex == 0)
  6264. {
  6265. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6266. {
  6267. for(int i=0; i < gunTotalNumber; i++)
  6268. {
  6269. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6270. {
  6271. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  6272. {
  6273. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6274. {
  6275. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6276. goto end;
  6277. }
  6278. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6279. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6280. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6281. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6282. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6283. {
  6284. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6285. goto end;
  6286. }
  6287. }
  6288. }//END FOR CHAdeMO_QUANTITY
  6289. for (int index = 0; index < CCS_QUANTITY; index++)
  6290. {
  6291. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  6292. {
  6293. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  6294. {
  6295. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6296. goto end;
  6297. }
  6298. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6299. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6300. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6301. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6302. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6303. {
  6304. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6305. goto end;
  6306. }
  6307. }
  6308. }//END FOR CCS_QUANTITY
  6309. for (int index = 0; index < GB_QUANTITY; index++)
  6310. {
  6311. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  6312. {
  6313. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6314. {
  6315. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6316. goto end;
  6317. }
  6318. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6319. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6320. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6321. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6322. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6323. {
  6324. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6325. goto end;
  6326. }
  6327. }
  6328. }// END FOR GB_QUANTITY
  6329. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6330. {
  6331. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  6332. {
  6333. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6334. {
  6335. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6336. goto end;
  6337. }
  6338. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6339. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6340. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6341. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6342. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6343. {
  6344. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6345. goto end;
  6346. }
  6347. }
  6348. }// END FOR GENERAL_GUN_QUANTITY
  6349. for (int index = 0; index < AC_QUANTITY; index++)
  6350. {
  6351. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  6352. {
  6353. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6354. {
  6355. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6356. goto end;
  6357. }
  6358. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6359. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6360. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6361. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6362. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6363. {
  6364. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6365. goto end;
  6366. }
  6367. }
  6368. }//END FOR AC_QUANTITY
  6369. }// END FOR gunTotalNumber
  6370. }
  6371. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6372. {
  6373. for(int i=0; i < gunTotalNumber; i++)
  6374. {
  6375. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6376. {
  6377. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6378. goto end;
  6379. }
  6380. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6381. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  6382. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  6383. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  6384. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6385. {
  6386. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6387. goto end;
  6388. }
  6389. }
  6390. }
  6391. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6392. goto end;
  6393. }
  6394. //----------------------gunIndex is not 0 ------------------------------------------------//
  6395. //check Transaction active
  6396. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6397. {
  6398. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  6399. {
  6400. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  6401. {
  6402. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6403. goto end;
  6404. }
  6405. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6406. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6407. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6408. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6409. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6410. {
  6411. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6412. goto end;
  6413. }
  6414. else
  6415. {
  6416. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  6417. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6418. goto end;
  6419. }
  6420. }
  6421. }//END FOR CHAdeMO_QUANTITY
  6422. for (int index = 0; index < CCS_QUANTITY; index++)
  6423. {
  6424. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  6425. {
  6426. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  6427. {
  6428. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6429. goto end;
  6430. }
  6431. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6432. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6433. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6434. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6435. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6436. {
  6437. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6438. goto end;
  6439. }
  6440. else
  6441. {
  6442. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  6443. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6444. goto end;
  6445. }
  6446. }
  6447. }//END FOR CCS_QUANTITY
  6448. for (int index = 0; index < GB_QUANTITY; index++)
  6449. {
  6450. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  6451. {
  6452. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6453. {
  6454. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6455. goto end;
  6456. }
  6457. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6458. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6459. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6460. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6461. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6462. {
  6463. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6464. goto end;
  6465. }
  6466. else
  6467. {
  6468. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  6469. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6470. goto end;
  6471. }
  6472. }
  6473. }// END FOR GB_QUANTITY
  6474. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6475. {
  6476. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  6477. {
  6478. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6479. {
  6480. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6481. goto end;
  6482. }
  6483. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6484. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6485. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6486. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6487. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6488. {
  6489. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6490. goto end;
  6491. }
  6492. else
  6493. {
  6494. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  6495. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6496. goto end;
  6497. }
  6498. }
  6499. }// END FOR GENERAL_GUN_QUANTITY
  6500. for (int index = 0; index < AC_QUANTITY; index++)
  6501. {
  6502. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  6503. {
  6504. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6505. {
  6506. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6507. goto end;
  6508. }
  6509. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6510. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6511. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6512. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6513. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6514. {
  6515. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6516. goto end;
  6517. }
  6518. else
  6519. {
  6520. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  6521. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6522. goto end;
  6523. }
  6524. }
  6525. }//END FOR AC_QUANTITY
  6526. }//END FOR AvailabilityTypeStr[Inoperative]
  6527. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  6528. {
  6529. //----------------------gunIndex is 0 ------------------------------------------------//
  6530. if(gunIndex == 0)
  6531. {
  6532. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6533. {
  6534. for(int i=0; i < gunTotalNumber; i++)
  6535. {
  6536. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6537. {
  6538. 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
  6539. {
  6540. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6541. goto end;
  6542. }
  6543. }//END FOR CHAdeMO_QUANTITY
  6544. for (int index = 0; index < CCS_QUANTITY; index++)
  6545. {
  6546. 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
  6547. {
  6548. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6549. goto end;
  6550. }
  6551. }//END FOR CCS_QUANTITY
  6552. for (int index = 0; index < GB_QUANTITY; index++)
  6553. {
  6554. 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
  6555. {
  6556. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6557. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6558. goto end;
  6559. }
  6560. }// END FOR GB_QUANTITY
  6561. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6562. {
  6563. 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
  6564. {
  6565. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6566. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6567. goto end;
  6568. }
  6569. }// END FOR GENERAL_GUN_QUANTITY
  6570. for (int index = 0; index < AC_QUANTITY; index++)
  6571. {
  6572. 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
  6573. {
  6574. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6575. goto end;
  6576. }
  6577. }//END FOR CHAdeMO_QUANTITY
  6578. }// END FOR gunTotalNumber
  6579. }
  6580. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6581. {
  6582. for(int i=0; i < gunTotalNumber; i++)
  6583. {
  6584. for (int index = 0; index < AC_QUANTITY; index++)
  6585. {
  6586. 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
  6587. {
  6588. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6589. goto end;
  6590. }
  6591. }//END FOR CHAdeMO_QUANTITY
  6592. } // END FOR gunTotalNumber
  6593. }
  6594. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6595. goto end;
  6596. }
  6597. //----------------------gunIndex is not 0 ------------------------------------------------//
  6598. //check Transaction active
  6599. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6600. {
  6601. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6602. {
  6603. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6604. goto end;
  6605. }
  6606. }//END FOR CHAdeMO_QUANTITY
  6607. for (int index = 0; index < CCS_QUANTITY; index++)
  6608. {
  6609. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6610. {
  6611. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6612. goto end;
  6613. }
  6614. }//END FOR CCS_QUANTITY
  6615. for (int index = 0; index < GB_QUANTITY; index++)
  6616. {
  6617. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6618. {
  6619. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6620. goto end;
  6621. }
  6622. }// END FOR GB_QUANTITY
  6623. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6624. {
  6625. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6626. {
  6627. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6628. goto end;
  6629. }
  6630. }// END FOR GENERAL_GUN_QUANTITY
  6631. for (int index = 0; index < AC_QUANTITY; index++)
  6632. {
  6633. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6634. {
  6635. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6636. goto end;
  6637. }
  6638. }//END FOR AC_QUANTITY
  6639. }//END FOR AvailabilityTypeStr[Operative]
  6640. end:
  6641. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6642. {
  6643. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  6644. }
  6645. else
  6646. {
  6647. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  6648. }
  6649. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6650. {
  6651. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6652. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6653. }
  6654. else if(gunIndex == 0)
  6655. {
  6656. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6657. {
  6658. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  6659. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  6660. }
  6661. }
  6662. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  6663. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6664. return result;
  6665. }
  6666. int handleChangeConfigurationRequest(char *uuid, char *payload)
  6667. {
  6668. mtrace();
  6669. int result = FAIL;
  6670. char keystr[40]={0};
  6671. char valuestr[256]={0};
  6672. char comfirmstr[20]={0};
  6673. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  6674. json_object *ChangeConfiguration;
  6675. ChangeConfiguration = json_tokener_parse(payload);
  6676. if(!is_error(ChangeConfiguration))
  6677. {
  6678. // Required data
  6679. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  6680. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  6681. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  6682. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  6683. }
  6684. json_object_put(ChangeConfiguration);
  6685. if((uuid==NULL) || (payload ==NULL) )
  6686. {
  6687. DEBUG_ERROR("Payload is null\n");
  6688. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6689. }
  6690. else
  6691. {
  6692. int status = setKeyValue(keystr, valuestr);
  6693. switch(status)
  6694. {
  6695. case ConfigurationStatus_Accepted:
  6696. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  6697. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  6698. StoreConfigurationTable();
  6699. break;
  6700. case RebootRequired:
  6701. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  6702. StoreConfigurationTable();
  6703. break;
  6704. case NotSupported:
  6705. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  6706. break;
  6707. case ConfigurationStatus_Rejected:
  6708. default:
  6709. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6710. break;
  6711. }
  6712. }
  6713. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  6714. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  6715. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6716. {
  6717. ChageWebSocketPingInterval(atoi(valuestr));
  6718. }
  6719. if((strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6720. {
  6721. SetOcppConnStatus(FALSE);
  6722. }
  6723. return result;
  6724. }
  6725. int handleClearCacheRequest(char *uuid, char *payload)
  6726. {
  6727. mtrace();
  6728. int result = FAIL;
  6729. char comfirmstr[20];
  6730. char rmFileCmd[100]={0};
  6731. struct stat stats;
  6732. DEBUG_INFO("handleClearCacheRequest...\n");
  6733. stat("/Storage/OCPP", &stats);
  6734. // Check for directory existence
  6735. if (S_ISDIR(stats.st_mode) == 1)
  6736. {}
  6737. else
  6738. {
  6739. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  6740. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  6741. system(rmFileCmd);
  6742. }
  6743. if(OCPP_cleanLocalCache())
  6744. {
  6745. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  6746. }
  6747. else
  6748. {
  6749. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  6750. }
  6751. sendClearCacheConfirmation(uuid, comfirmstr);
  6752. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6753. return result;
  6754. }
  6755. int handleClearChargingProfileRequest(char *uuid, char *payload)
  6756. {
  6757. mtrace();
  6758. int result = FAIL;
  6759. int resultRename;
  6760. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  6761. char chargingProfilePurposeStr[26]={0};
  6762. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  6763. char tempchargingProfilePurposeStr[26]={0};
  6764. char str[100]={0};
  6765. char fname[200]={0};
  6766. char comfirmstr[20]={0};
  6767. char word[1600]={0};
  6768. int clearflag = FALSE;
  6769. int chargingProfileIdIsNULL = FALSE;
  6770. int connectorIsNULL = FALSE;
  6771. int chargingProfilePurposeIsNULL = FALSE;
  6772. int stackLevelIsNULL = FALSE;
  6773. //int GotoEnd = FALSE;
  6774. FILE *fptr1, *fptr2;
  6775. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  6776. int n_chargingProfile=0;
  6777. int isEmptyFile = FALSE;
  6778. char sLineWord[1600]={0};
  6779. char chargingProfiles[10][100]={0};
  6780. int ChargeProfileCount = 0;
  6781. int ch;
  6782. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  6783. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  6784. json_object *ClearChargingProfile;
  6785. ClearChargingProfile = json_tokener_parse(payload);
  6786. if(!is_error(ClearChargingProfile))
  6787. {
  6788. // Optional data
  6789. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  6790. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  6791. else
  6792. chargingProfileIdIsNULL = TRUE;
  6793. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  6794. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  6795. else
  6796. connectorIsNULL = TRUE;
  6797. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  6798. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  6799. else
  6800. chargingProfilePurposeIsNULL = TRUE;
  6801. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  6802. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  6803. else
  6804. stackLevelIsNULL = TRUE;
  6805. }
  6806. json_object_put(ClearChargingProfile);
  6807. if(connectorIsNULL == FALSE)
  6808. {
  6809. switch(connectorIdInt)
  6810. {
  6811. case 0:
  6812. if(chargingProfilePurposeIsNULL == TRUE)
  6813. {
  6814. int l = 0;
  6815. strcpy(fname, ChargePointMaxProfile_JSON);
  6816. if((access(fname,F_OK))!=-1)
  6817. {
  6818. strcpy(chargingProfiles[l], fname);
  6819. l = l + 1;
  6820. }
  6821. strcpy(fname, TxDefaultProfile_0_JSON);
  6822. if((access(fname,F_OK))!=-1)
  6823. {
  6824. strcpy(chargingProfiles[l], fname);
  6825. l = l + 1;
  6826. }
  6827. ChargeProfileCount = l;
  6828. }
  6829. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  6830. {
  6831. strcpy(fname, ChargePointMaxProfile_JSON);
  6832. if((access(fname,F_OK))!=-1)
  6833. {
  6834. strcpy(chargingProfiles[0], fname);
  6835. ChargeProfileCount = 1;
  6836. }
  6837. }
  6838. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6839. {
  6840. strcpy(fname, TxDefaultProfile_0_JSON);
  6841. if((access(fname,F_OK))!=-1)
  6842. {
  6843. strcpy(chargingProfiles[0], fname);
  6844. ChargeProfileCount = 1;
  6845. }
  6846. }
  6847. break;
  6848. default:
  6849. if(chargingProfilePurposeIsNULL == TRUE)
  6850. {
  6851. int m = 0;
  6852. memset(fname, 0, ARRAY_SIZE(fname));
  6853. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6854. if((access(fname,F_OK))!=-1)
  6855. {
  6856. strcpy(chargingProfiles[m], fname);
  6857. m = m + 1;
  6858. }
  6859. memset(fname, 0, ARRAY_SIZE(fname));
  6860. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6861. if((access(fname,F_OK))!=-1)
  6862. {
  6863. strcpy(chargingProfiles[m], fname);
  6864. m = m + 1;
  6865. }
  6866. ChargeProfileCount = m;
  6867. }
  6868. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6869. {
  6870. //strcpy(fname, TxDefaultProfile_1_JSON);
  6871. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6872. if((access(fname,F_OK))!=-1)
  6873. {
  6874. strcpy(chargingProfiles[0], fname);
  6875. ChargeProfileCount = 1;
  6876. }
  6877. }
  6878. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  6879. {
  6880. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6881. if((access(fname,F_OK))!=-1)
  6882. {
  6883. strcpy(chargingProfiles[0], fname);
  6884. ChargeProfileCount = 1;
  6885. }
  6886. //strcpy(fname, TxProfile_1_JSON);
  6887. }
  6888. //strcpy(fname, ChargePointMaxProfile_JSON );
  6889. break;
  6890. }
  6891. }
  6892. else // Check all Charging Profiles
  6893. {
  6894. int i = 0;
  6895. char fnametemp[200]={0};
  6896. ChargeProfileCount = 0;
  6897. //Check ChargePointMaxProfile.json exit
  6898. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  6899. {
  6900. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  6901. i = i + 1;
  6902. }
  6903. //Check TxDefaultProfile_0.json exit
  6904. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  6905. {
  6906. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  6907. i = i + 1;
  6908. }
  6909. //Check TxDefaultProfile_%d.json
  6910. for(int j=1; j <= gunTotalNumber; j++)
  6911. {
  6912. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6913. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  6914. if((access(fnametemp,F_OK))!=-1)
  6915. {
  6916. strcpy(chargingProfiles[i], fnametemp);
  6917. i = i + 1;
  6918. }
  6919. }
  6920. //Check TxProfile_%d.json
  6921. for(int j=1; j <= gunTotalNumber; j++)
  6922. {
  6923. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6924. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  6925. if((access(fnametemp,F_OK))!=-1)
  6926. {
  6927. strcpy(chargingProfiles[i], fnametemp);
  6928. i = i + 1;
  6929. }
  6930. }
  6931. ChargeProfileCount = i;
  6932. }// End connectorIsNULL is TRUE
  6933. if(ChargeProfileCount == 0)
  6934. {
  6935. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6936. goto end;
  6937. }
  6938. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  6939. {
  6940. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6941. goto end;
  6942. }
  6943. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  6944. {
  6945. memset(str, 0, ARRAY_SIZE(str));
  6946. // clear temp file
  6947. sprintf(str,"rm -f %s",temp);
  6948. system(str);
  6949. for(int k=0; k < ChargeProfileCount; k++)
  6950. {
  6951. memset(str, 0, ARRAY_SIZE(str));
  6952. //clear file in C
  6953. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6954. system(str);
  6955. }
  6956. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6957. goto end;
  6958. }
  6959. else if(connectorIsNULL == TRUE)
  6960. {
  6961. for(int k=0; k < ChargeProfileCount; k++)
  6962. {
  6963. fptr1 = fopen(chargingProfiles[k], "r");
  6964. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  6965. //Check Charging Profile Count
  6966. while(fscanf(fptr1, "%s", word) != EOF)
  6967. {
  6968. //DEBUG_INFO("word=%s\n",word);
  6969. if(strstr(word, "chargingProfileId")!= NULL)
  6970. {
  6971. //DEBUG_INFO("test chargingProfileId \n");
  6972. n_chargingProfile = n_chargingProfile + 1;
  6973. //DEBUG_INFO("chargingProfileId Found\n");
  6974. }
  6975. }
  6976. rewind(fptr1);
  6977. //search Charging Profile Element
  6978. //int i= 0;
  6979. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6980. {
  6981. json_object *tmpProfilee;
  6982. tmpProfilee = json_tokener_parse(sLineWord);
  6983. if(!is_error(tmpProfilee))
  6984. {
  6985. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  6986. {
  6987. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  6988. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  6989. }
  6990. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  6991. {
  6992. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  6993. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  6994. }
  6995. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  6996. {
  6997. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  6998. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  6999. }
  7000. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7001. {
  7002. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7003. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7004. }
  7005. }
  7006. json_object_put(tmpProfilee);
  7007. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7008. {
  7009. //------- not write to fptr2-------//
  7010. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7011. //clearflag = TRUE;
  7012. }
  7013. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7014. {
  7015. //------- not write to fptr2-------//
  7016. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7017. }
  7018. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7019. {
  7020. //------- not write to fptr2-------//
  7021. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7022. }
  7023. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  7024. {
  7025. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7026. }
  7027. else
  7028. {
  7029. fprintf(fptr2, sLineWord);//writing data into file
  7030. }
  7031. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7032. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7033. if(clearflag == TRUE)
  7034. {
  7035. fclose(fptr1);
  7036. fclose(fptr2);
  7037. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7038. system(str);
  7039. // clear temp file
  7040. sprintf(str,"rm -f %s",temp);
  7041. system(str);
  7042. }
  7043. else
  7044. {
  7045. fclose(fptr1);
  7046. fclose(fptr2);
  7047. memset(str, 0, ARRAY_SIZE(str));
  7048. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7049. system(str);
  7050. resultRename = rename(temp, chargingProfiles[k]);
  7051. if(resultRename == 0)
  7052. {
  7053. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  7054. }
  7055. else
  7056. {
  7057. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  7058. }
  7059. if(comfirmstr[0]== 0)
  7060. {
  7061. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7062. }
  7063. //Check chargingProfile is empty file
  7064. /*------ Read the file ----------------*/
  7065. fptr1=fopen(chargingProfiles[k],"r");
  7066. ch=fgetc(fptr1);
  7067. rewind(fptr1);
  7068. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7069. if(ch!=EOF)
  7070. {
  7071. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7072. {
  7073. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7074. if(sLineWord[0]=='\0')
  7075. {
  7076. isEmptyFile = TRUE;
  7077. break;
  7078. }
  7079. else
  7080. {
  7081. isEmptyFile = FALSE;
  7082. break;
  7083. }
  7084. }
  7085. }
  7086. else
  7087. isEmptyFile = TRUE;
  7088. fclose(fptr1);
  7089. if(isEmptyFile == TRUE)
  7090. {
  7091. memset(str, 0, ARRAY_SIZE(str));
  7092. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7093. system(str);
  7094. }
  7095. }
  7096. }// End of while(int k=0; k < ChargePointCount; k++)
  7097. }
  7098. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  7099. {
  7100. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  7101. for(int k=0; k < ChargeProfileCount; k++)
  7102. {
  7103. fptr1 = fopen(chargingProfiles[k], "r");
  7104. fptr2 = fopen(temp, "w+");
  7105. //Check Charging Profile Count
  7106. while(fscanf(fptr1, "%s", word) != EOF)
  7107. {
  7108. //DEBUG_INFO("word=%s\n",word);
  7109. if(strstr(word, "chargingProfileId")!= NULL)
  7110. {
  7111. n_chargingProfile = n_chargingProfile + 1;
  7112. }
  7113. }
  7114. rewind(fptr1);
  7115. //search Charging Profile Element
  7116. //int i= 0;
  7117. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7118. {
  7119. json_object *tmpProfilee;
  7120. tmpProfilee = json_tokener_parse(sLineWord);
  7121. if(!is_error(tmpProfilee))
  7122. {
  7123. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7124. {
  7125. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7126. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7127. }
  7128. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7129. {
  7130. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7131. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7132. }
  7133. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7134. {
  7135. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7136. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7137. }
  7138. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7139. {
  7140. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7141. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7142. }
  7143. }
  7144. json_object_put(tmpProfilee);
  7145. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7146. {
  7147. //------- not write to fptr2-------//
  7148. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7149. //clearflag = TRUE;
  7150. }
  7151. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7152. {
  7153. //------- not write to fptr2-------//
  7154. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7155. }
  7156. else if(stackLevelIsNULL == TRUE)
  7157. {
  7158. //Clear Whole File
  7159. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7160. clearflag = TRUE;
  7161. break;
  7162. }
  7163. else
  7164. {
  7165. fprintf(fptr2, sLineWord);//writing data into file
  7166. }
  7167. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7168. }
  7169. if(clearflag == TRUE)
  7170. {
  7171. fclose(fptr1);
  7172. fclose(fptr2);
  7173. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7174. system(str);
  7175. // clear temp file
  7176. sprintf(str,"rm -f %s",temp);
  7177. system(str);
  7178. }
  7179. else
  7180. {
  7181. fclose(fptr1);
  7182. fclose(fptr2);
  7183. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7184. system(str);
  7185. resultRename = rename(temp, chargingProfiles[k]);
  7186. if(resultRename == 0)
  7187. {
  7188. DEBUG_INFO("File ChargingProfile renamed successfully");
  7189. }
  7190. else
  7191. {
  7192. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  7193. }
  7194. if(comfirmstr[0]== 0)
  7195. {
  7196. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7197. }
  7198. //Check chargingProfile is empty file
  7199. /*------ Read the file ----------------*/
  7200. fptr1=fopen(chargingProfiles[k],"r");
  7201. ch=fgetc(fptr1);
  7202. rewind(fptr1);
  7203. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7204. if(ch!=EOF)
  7205. {
  7206. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7207. {
  7208. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7209. if(sLineWord[0]=='\0')
  7210. {
  7211. isEmptyFile = TRUE;
  7212. break;
  7213. }
  7214. else
  7215. {
  7216. isEmptyFile = FALSE;
  7217. break;
  7218. }
  7219. }
  7220. }
  7221. else
  7222. isEmptyFile = TRUE;
  7223. fclose(fptr1);
  7224. if(isEmptyFile == TRUE)
  7225. {
  7226. memset(str, 0, ARRAY_SIZE(str));
  7227. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7228. system(str);
  7229. }
  7230. /*------- End of reading ---------------*/
  7231. }
  7232. } // while(int k=0; k < ChargeProfileCount; k++)
  7233. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  7234. end:
  7235. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  7236. {
  7237. if(connectorIdInt == 0)
  7238. {
  7239. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  7240. {
  7241. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  7242. }
  7243. }
  7244. else
  7245. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  7246. }
  7247. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  7248. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7249. return result;
  7250. }
  7251. void createFirmwareVersionByDataTransfer(void)
  7252. {
  7253. json_object *FirmwareDataTransfer = json_object_new_object();
  7254. // AC & DC model
  7255. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  7256. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  7257. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  7258. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  7259. // DC model
  7260. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O')
  7261. {
  7262. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  7263. {
  7264. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7265. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7266. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  7267. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  7268. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7269. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7270. }
  7271. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  7272. ((gunType[1] != GUN_TYPE_UNKNOWN) || (gunType[2] != GUN_TYPE_UNKNOWN) || (gunType[3] != GUN_TYPE_UNKNOWN)))
  7273. {
  7274. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  7275. }
  7276. }
  7277. else
  7278. {
  7279. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7280. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7281. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7282. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7283. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  7284. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  7285. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  7286. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  7287. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  7288. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  7289. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  7290. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  7291. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  7292. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  7293. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  7294. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  7295. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  7296. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  7297. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  7298. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  7299. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  7300. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  7301. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  7302. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  7303. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  7304. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  7305. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  7306. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  7307. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  7308. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  7309. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  7310. }
  7311. // 4G model
  7312. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  7313. {
  7314. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  7315. }
  7316. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  7317. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  7318. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  7319. json_object_put(FirmwareDataTransfer);
  7320. }
  7321. int handleDataTransferRequest(char *uuid, char *payload)
  7322. {
  7323. mtrace();
  7324. json_object *response = json_object_new_object();
  7325. int result = FAIL;
  7326. char tempvendorId[255]={0};
  7327. char tempmessageId[50]={0};
  7328. char tempdata[512]={0};
  7329. char message[2048]={0};
  7330. DEBUG_INFO("handleDataTransferRequest...\n");
  7331. if((uuid != NULL) && (payload != NULL))
  7332. {
  7333. json_object *DataTransfer;
  7334. DataTransfer = json_tokener_parse(payload);
  7335. if(!is_error(DataTransfer))
  7336. {
  7337. // Required data
  7338. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  7339. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  7340. // Optional data
  7341. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  7342. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  7343. if(json_object_object_get(DataTransfer, "data") != NULL)
  7344. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  7345. result = PASS;
  7346. }
  7347. json_object_put(DataTransfer);
  7348. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  7349. {
  7350. // Send all moudle firmware version on EVSE
  7351. createFirmwareVersionByDataTransfer();
  7352. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7353. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  7354. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7355. json_object_put(response);
  7356. }
  7357. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  7358. {
  7359. system("/usr/bin/run_tmate_restart.sh &");
  7360. }
  7361. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  7362. {
  7363. json_object *data;
  7364. data = json_tokener_parse(tempdata);
  7365. if(!is_error(data))
  7366. {
  7367. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  7368. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  7369. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  7370. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  7371. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  7372. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  7373. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  7374. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  7375. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  7376. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  7377. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7378. }
  7379. else
  7380. {
  7381. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7382. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7383. }
  7384. json_object_put(data);
  7385. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7386. json_object_put(response);
  7387. }
  7388. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  7389. {
  7390. json_object *data;
  7391. data = json_tokener_parse(tempdata);
  7392. if(!is_error(data))
  7393. {
  7394. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  7395. if(json_object_object_get(data, "idToken") != NULL)
  7396. {
  7397. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  7398. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  7399. }
  7400. if(json_object_object_get(data, "price") != NULL)
  7401. {
  7402. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  7403. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  7404. }
  7405. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7406. }
  7407. else
  7408. {
  7409. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7410. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7411. }
  7412. json_object_put(data);
  7413. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7414. json_object_put(response);
  7415. }
  7416. else if(strstr(tempmessageId, "RunningCost") != NULL)
  7417. {
  7418. json_object *data;
  7419. data = json_tokener_parse(tempdata);
  7420. if(!is_error(data))
  7421. {
  7422. if(json_object_object_get(data, "txId") != NULL)
  7423. {
  7424. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7425. for(int idx = 0;idx<gunTotalNumber;idx++)
  7426. {
  7427. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7428. {
  7429. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  7430. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7431. if(json_object_object_get(data, "description") != NULL)
  7432. {
  7433. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7434. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7435. }
  7436. }
  7437. }
  7438. }
  7439. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7440. }
  7441. else
  7442. {
  7443. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7444. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7445. }
  7446. json_object_put(data);
  7447. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7448. json_object_put(response);
  7449. }
  7450. else if(strstr(tempmessageId, "FinalCost") != NULL)
  7451. {
  7452. json_object *data;
  7453. data = json_tokener_parse(tempdata);
  7454. if(!is_error(data))
  7455. {
  7456. if(json_object_object_get(data, "txId") != NULL)
  7457. {
  7458. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7459. for(int idx = 0;idx<gunTotalNumber;idx++)
  7460. {
  7461. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7462. {
  7463. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  7464. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7465. if(json_object_object_get(data, "description") != NULL)
  7466. {
  7467. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7468. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7469. }
  7470. }
  7471. }
  7472. }
  7473. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7474. }
  7475. else
  7476. {
  7477. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7478. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7479. }
  7480. json_object_put(data);
  7481. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7482. json_object_put(response);
  7483. }
  7484. else
  7485. {
  7486. // Can not find valid message id
  7487. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  7488. }
  7489. }
  7490. else
  7491. {
  7492. // Payload is null
  7493. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  7494. }
  7495. LWS_Send(message);
  7496. return result;
  7497. }
  7498. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  7499. {
  7500. mtrace();
  7501. int result = FAIL;
  7502. int connectorIdInt, durationInt;
  7503. char chargingRateUnitStr[4]={0};
  7504. char comfirmstr[20];
  7505. int confirmPeriods = 0;
  7506. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  7507. json_object *GetCompositeSchedule;
  7508. GetCompositeSchedule = json_tokener_parse(payload);
  7509. if(!is_error(GetCompositeSchedule))
  7510. {
  7511. // Required data
  7512. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  7513. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  7514. else
  7515. connectorIdInt = -1;
  7516. if(json_object_object_get(GetCompositeSchedule, "duration"))
  7517. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  7518. else
  7519. durationInt = 86400;
  7520. // Optional data
  7521. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  7522. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  7523. }
  7524. json_object_put(GetCompositeSchedule);
  7525. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  7526. if((connectorIdInt == 0) ||
  7527. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  7528. {
  7529. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  7530. struct StructChargingProfile tmpProfile[1];
  7531. if(strstr(chargingRateUnitStr, "W") != NULL)
  7532. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  7533. else
  7534. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  7535. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7536. {
  7537. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7538. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7539. }
  7540. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  7541. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  7542. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  7543. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7544. {
  7545. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7546. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7547. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  7548. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  7549. {
  7550. confirmPeriods = idx;
  7551. break;
  7552. }
  7553. }
  7554. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  7555. }
  7556. else
  7557. {
  7558. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  7559. }
  7560. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  7561. return result;
  7562. }
  7563. int handleGetConfigurationRequest(char *uuid, char *payload)
  7564. {
  7565. mtrace();
  7566. int result = FAIL;
  7567. int MaxKeySupported = 0;
  7568. int n_keys = 0;
  7569. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  7570. DEBUG_INFO("handleGetConfigurationRequest...\n");
  7571. json_object *GetConfiguration;
  7572. GetConfiguration = json_tokener_parse(payload);
  7573. if(!is_error(GetConfiguration))
  7574. {
  7575. // Optional data
  7576. if(json_object_object_get(GetConfiguration, "key") != NULL)
  7577. {
  7578. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  7579. {
  7580. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  7581. n_keys = idx + 1;
  7582. }
  7583. }
  7584. }
  7585. json_object_put(GetConfiguration);
  7586. UnknownKeynum = 0;
  7587. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  7588. MaxKeySupported = GetConfigurationMaxKeysNUM;
  7589. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  7590. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  7591. if(n_keys != 0)
  7592. {
  7593. for(int i=0;i<n_keys;i++)
  7594. {
  7595. getKeyValue(requestKey[i]);
  7596. }
  7597. }
  7598. else
  7599. {
  7600. DEBUG_INFO("There is no key in Message, get all configuration\n");
  7601. getKeyValue("");
  7602. }
  7603. processUnkownKey();
  7604. sendGetConfigurationConfirmation(uuid);
  7605. return result;
  7606. }
  7607. static char fnamePlusPath[100]={0};
  7608. static char fnamePWithNoPath[60]={0};
  7609. void checkUploadLog(void)
  7610. {
  7611. FILE *fp;
  7612. /* Open the command for reading. */
  7613. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  7614. if (fp == NULL) {
  7615. printf("Failed to run command\n" );
  7616. exit(1);
  7617. }
  7618. int ftppathlen = 0;
  7619. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  7620. int i = 0;
  7621. /* Read the output a line at a time - output it. */
  7622. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  7623. if(i==0)
  7624. {
  7625. ftppathlen = strlen(fnamePlusPath);
  7626. printf("%s\n", fnamePlusPath);
  7627. fnamePlusPath[ftppathlen]='\0';
  7628. break;
  7629. }
  7630. i= i+1;
  7631. }
  7632. /* close */
  7633. pclose(fp);
  7634. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  7635. {
  7636. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  7637. {
  7638. fnamePlusPath[k]='\0';
  7639. }
  7640. }
  7641. i=1;
  7642. //char fname[60]={0};
  7643. while(i < ftppathlen)
  7644. {
  7645. int len=ftppathlen-i;
  7646. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  7647. {
  7648. printf("compare '/' all right\n");
  7649. break;
  7650. }
  7651. i=i+1;
  7652. }
  7653. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  7654. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  7655. fnamePWithNoPath[i+1] = '\0';
  7656. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  7657. {
  7658. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  7659. {
  7660. fnamePWithNoPath[j]='\0';
  7661. }
  7662. }
  7663. FILE* fp1 = fopen(fnamePlusPath, "r");
  7664. if (fp1)
  7665. {
  7666. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  7667. // file exists
  7668. fclose(fp1);
  7669. }
  7670. else
  7671. {
  7672. // file doesn't exist
  7673. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  7674. }
  7675. }
  7676. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  7677. {
  7678. mtrace();
  7679. int result = FAIL;
  7680. time_t CurrentTime;
  7681. struct tm *tm;
  7682. pthread_t th_Status;
  7683. CurrentTime = time(NULL);
  7684. tm = localtime(&CurrentTime);
  7685. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  7686. 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);
  7687. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  7688. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  7689. return result;
  7690. }
  7691. void* GetDiagnosticsProcess(void* data)
  7692. {
  7693. pthread_detach(pthread_self());
  7694. mtrace();
  7695. int retriesInt=0, retryIntervalInt=0;
  7696. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  7697. 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};
  7698. int port=0;
  7699. int isSuccess = FALSE;
  7700. char ftpbuf[200]={0};
  7701. char cmdBuf[2048];
  7702. struct tm *tmNow;
  7703. time_t CurrentTime;
  7704. struct tm tmStart;
  7705. struct tm tmStop;
  7706. CurrentTime = time(NULL);
  7707. tmNow=localtime(&CurrentTime);
  7708. uint16_t targetYear, targetMonth;
  7709. json_object *GetDiagnostics;
  7710. DEBUG_INFO("GetDiagnosticsProcess...\n");
  7711. GetDiagnostics = json_tokener_parse(data);
  7712. if(!is_error(GetDiagnostics))
  7713. {
  7714. // Required data
  7715. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  7716. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  7717. // Optional data
  7718. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  7719. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  7720. else
  7721. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  7722. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  7723. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  7724. else
  7725. retryIntervalInt = 30;
  7726. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  7727. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  7728. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  7729. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  7730. }
  7731. json_object_put(GetDiagnostics);
  7732. // Pack log to compress file
  7733. if((sscanf((char*)startTimestr, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  7734. (sscanf((char*)stopTimestr, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  7735. {
  7736. // Pack system log
  7737. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  7738. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  7739. targetYear = tmStart.tm_year;
  7740. targetMonth = tmStart.tm_mon;
  7741. do
  7742. {
  7743. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7744. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7745. if(targetMonth+1>=13)
  7746. {
  7747. targetYear += 1;
  7748. targetMonth = 1;
  7749. }
  7750. else
  7751. {
  7752. targetMonth += 1;
  7753. }
  7754. }while((targetYear < (tmNow->tm_year+1900)) ||
  7755. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  7756. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  7757. system(cmdBuf);
  7758. // Pack charging & event log
  7759. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  7760. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  7761. targetYear = tmStart.tm_year;
  7762. targetMonth = tmStart.tm_mon;
  7763. do
  7764. {
  7765. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7766. if(targetMonth+1>=13)
  7767. {
  7768. targetYear += 1;
  7769. targetMonth = 1;
  7770. }
  7771. else
  7772. {
  7773. targetMonth += 1;
  7774. }
  7775. }while((targetYear < (tmNow->tm_year+1900)) ||
  7776. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  7777. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  7778. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  7779. system(cmdBuf);
  7780. // Combine log file
  7781. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  7782. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  7783. }
  7784. else
  7785. {
  7786. system("exec /root/logPackTools 'log' 6");
  7787. }
  7788. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  7789. system(cmdBuf);
  7790. checkUploadLog();
  7791. //****************location*******************/
  7792. if(strcmp(locationstr,"")==0)
  7793. {
  7794. DEBUG_INFO("location is <Empty>!\n");
  7795. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7796. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7797. goto end;
  7798. }
  7799. memset(protocol, 0, ARRAY_SIZE(protocol));
  7800. memset(user, 0, ARRAY_SIZE(user) );
  7801. memset(password, 0, ARRAY_SIZE(password));
  7802. memset(host, 0, ARRAY_SIZE(host));
  7803. memset(path, 0, ARRAY_SIZE(path));
  7804. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  7805. memset(host1, 0, ARRAY_SIZE(host1));
  7806. memset(path1, 0, ARRAY_SIZE(path1));
  7807. /*location: ftp://user:password@host:port/path*/
  7808. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  7809. if((access(fnamePlusPath,F_OK))!=-1)
  7810. {
  7811. DEBUG_INFO("fnamePlusPath exist.\n");
  7812. }
  7813. else
  7814. {
  7815. DEBUG_INFO("fnamePlusPath not exist!\n");
  7816. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7817. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7818. goto end;
  7819. }
  7820. if(strchr(locationstr,'@')==NULL)
  7821. {
  7822. sscanf(locationstr,
  7823. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  7824. protocol, host, &port, path);
  7825. strcpy(user,"anonymous");
  7826. strcpy(password,"");
  7827. }
  7828. else
  7829. {
  7830. //DEBUG_INFO("pch=%s\n", pch);
  7831. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  7832. protocol, user, password, host, &port, path);
  7833. }
  7834. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  7835. {
  7836. DEBUG_INFO("protocol is not ftp/http ! \n");
  7837. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7838. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7839. goto end;
  7840. }
  7841. if(strncmp(locationstr,"http", 4) == 0)
  7842. {
  7843. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  7844. sprintf(ftppath,"/%s", path);
  7845. do
  7846. {
  7847. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7848. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7849. sleep(3);
  7850. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  7851. if(!isSuccess)
  7852. {
  7853. DEBUG_INFO("Diagnostics fail.\n");
  7854. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7855. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7856. sleep(retryIntervalInt);
  7857. }
  7858. else
  7859. {
  7860. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7861. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7862. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7863. }
  7864. retriesInt--;
  7865. }while((isSuccess == 0)&&(retriesInt >= 0));
  7866. }
  7867. else
  7868. {
  7869. sscanf(host,"%[^/]%s",host1, path1);
  7870. if(strlen(path) > 0)
  7871. sprintf(ftppath,"/%s", path);
  7872. else
  7873. sprintf(ftppath,"/%s", path1);
  7874. int ftppathlen=strlen(ftppath);
  7875. int i=1;
  7876. char filenametemp[50];
  7877. while(i < ftppathlen)
  7878. {
  7879. int len=ftppathlen-i;
  7880. if(ftppath[len]== 47) // '/' ascll code: 47
  7881. {
  7882. DEBUG_INFO("find '/' all right\n");
  7883. break;
  7884. }
  7885. i=i+1;
  7886. }
  7887. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  7888. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  7889. filenametemp[i+1] = 0;
  7890. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  7891. if(port == 0)
  7892. port = 21;
  7893. do
  7894. {
  7895. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7896. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7897. sleep(3);
  7898. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  7899. if(!isSuccess)
  7900. {
  7901. DEBUG_INFO("Diagnostics fail.\n");
  7902. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7903. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7904. sleep(retryIntervalInt);
  7905. }
  7906. else
  7907. {
  7908. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7909. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7910. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7911. }
  7912. retriesInt--;
  7913. }while((!isSuccess)&&(retriesInt >= 0));
  7914. }
  7915. end:
  7916. system("rm -f /mnt/*");
  7917. sleep(5);
  7918. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  7919. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7920. pthread_exit(NULL);
  7921. }
  7922. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  7923. {
  7924. mtrace();
  7925. int result = FAIL;
  7926. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  7927. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  7928. {
  7929. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  7930. localversion = -1;
  7931. }
  7932. else
  7933. {
  7934. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  7935. OCPP_getListVerion();
  7936. }
  7937. //from db.OCPP_getListVerion
  7938. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  7939. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  7940. sendGetLocalListVersionConfirmation(uuid,"");
  7941. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  7942. return result;
  7943. }
  7944. int handleRemoteStartRequest(char *uuid, char *payload)
  7945. {
  7946. mtrace();
  7947. int result = FAIL;
  7948. int connectorIdInt=0;
  7949. int tempIndex = 0;
  7950. int connectorIdIsNULL, chargingProfileIsNULL;
  7951. char comfirmstr[20]={0};
  7952. char cmdBuf[512];
  7953. json_object *RemoteStartTransaction;
  7954. FILE *fp;
  7955. DEBUG_INFO("handleRemoteStartRequest ...\n");
  7956. if(server_pending == TRUE)
  7957. {
  7958. return 0;
  7959. }
  7960. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  7961. RemoteStartTransaction = json_tokener_parse(payload);
  7962. if(!is_error(RemoteStartTransaction))
  7963. {
  7964. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  7965. {
  7966. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  7967. if(connectorIdInt <= gunTotalNumber)
  7968. {
  7969. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  7970. // Required data
  7971. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  7972. // Optional data
  7973. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  7974. {
  7975. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  7976. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  7977. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  7978. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  7979. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  7980. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  7981. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  7982. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  7983. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  7984. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  7985. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  7986. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  7987. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  7988. {
  7989. 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")));
  7990. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  7991. 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"));
  7992. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  7993. 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"));
  7994. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  7995. 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")));
  7996. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  7997. {
  7998. 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++)
  7999. {
  8000. 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"));
  8001. 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"));
  8002. 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)
  8003. 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"));
  8004. }
  8005. }
  8006. }
  8007. }
  8008. else
  8009. chargingProfileIsNULL = TRUE;
  8010. }
  8011. }
  8012. else
  8013. connectorIdIsNULL = TRUE;
  8014. }
  8015. else
  8016. connectorIdIsNULL = TRUE;
  8017. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  8018. {
  8019. DEBUG_WARN("Connector id is NULL\n.");
  8020. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8021. goto end;
  8022. }
  8023. /*
  8024. enum _SYSTEM_STATUS
  8025. {
  8026. S_BOOTING = 0,
  8027. S_IDLE, = 1
  8028. S_AUTHORIZING, = 2
  8029. S_REASSIGN_CHECK, = 3
  8030. S_REASSIGN, = 4
  8031. S_PRECHARGE, = 5
  8032. S_PREPARING_FOR_EV, = 6
  8033. S_PREPARING_FOR_EVSE, = 7
  8034. S_CHARGING, = 8
  8035. S_TERMINATING, = 9
  8036. S_COMPLETE, = 10
  8037. S_ALARM, = 11
  8038. S_FAULT = 12
  8039. }
  8040. */
  8041. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  8042. {
  8043. //check Transaction active
  8044. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8045. {
  8046. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8047. {
  8048. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8049. }
  8050. else
  8051. {
  8052. tempIndex = connectorIdInt -1;
  8053. }
  8054. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8055. {
  8056. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  8057. {
  8058. 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))
  8059. {
  8060. //Reserved
  8061. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8062. }
  8063. 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))
  8064. {
  8065. //Reserved
  8066. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8067. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8068. goto end;
  8069. }
  8070. else
  8071. {
  8072. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8073. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  8074. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  8075. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  8076. {
  8077. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  8078. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8079. goto end;
  8080. }
  8081. }//END FOR ELSE
  8082. }
  8083. }// END FOR CHAdeMO_QUANTITY
  8084. }
  8085. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8086. {
  8087. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8088. {
  8089. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8090. }
  8091. else
  8092. {
  8093. tempIndex = connectorIdInt -1;
  8094. }
  8095. for (int index = 0; index < CCS_QUANTITY; index++)
  8096. {
  8097. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8098. {
  8099. 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))
  8100. {
  8101. //Reserved
  8102. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8103. }
  8104. 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))
  8105. {
  8106. //Reserved
  8107. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8108. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8109. goto end;
  8110. }
  8111. else
  8112. {
  8113. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8114. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8115. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8116. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8117. {
  8118. DEBUG_WARN("CCS connector not allow start\n.");
  8119. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8120. goto end;
  8121. }
  8122. }// END FOR ELSE
  8123. }
  8124. }// END FOR CCS_QUANTITY
  8125. }
  8126. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8127. {
  8128. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8129. {
  8130. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8131. }
  8132. else
  8133. {
  8134. tempIndex = connectorIdInt -1;
  8135. }
  8136. for (int index = 0; index < GB_QUANTITY; index++)
  8137. {
  8138. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  8139. {
  8140. 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))
  8141. {
  8142. //Reserved
  8143. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8144. }
  8145. 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))
  8146. {
  8147. //Reserved
  8148. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8149. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8150. goto end;
  8151. }
  8152. else
  8153. {
  8154. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8155. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8156. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8157. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8158. {
  8159. DEBUG_WARN("GB connector not allow start\n.");
  8160. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8161. goto end;
  8162. }
  8163. }// END FOR ELSE
  8164. }
  8165. } // END FOR GB_QUANTITY
  8166. }
  8167. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8168. {
  8169. tempIndex = connectorIdInt -1;
  8170. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8171. {
  8172. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  8173. {
  8174. 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))
  8175. {
  8176. //Reserved
  8177. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8178. }
  8179. 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))
  8180. {
  8181. //Reserved
  8182. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8183. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8184. goto end;
  8185. }
  8186. else
  8187. {
  8188. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8189. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8190. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8191. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8192. {
  8193. DEBUG_WARN("GB connector not allow start\n.");
  8194. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8195. goto end;
  8196. }
  8197. }// END FOR ELSE
  8198. }
  8199. } // END FOR GB_QUANTITY
  8200. }
  8201. else
  8202. {
  8203. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8204. {
  8205. tempIndex = 2;
  8206. }
  8207. else
  8208. {
  8209. tempIndex = connectorIdInt -1;
  8210. }
  8211. for (int index = 0; index < AC_QUANTITY; index++)
  8212. {
  8213. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  8214. {
  8215. 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))
  8216. {
  8217. //Reserved
  8218. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8219. }
  8220. 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))
  8221. {
  8222. //Reserved
  8223. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8224. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8225. goto end;
  8226. }
  8227. else
  8228. {
  8229. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8230. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8231. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8232. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8233. {
  8234. DEBUG_WARN("AC connector not allow start\n.");
  8235. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8236. goto end;
  8237. }
  8238. }//END FOR ELSE
  8239. }
  8240. }// END FOR AC_QUANTITY
  8241. }
  8242. if(chargingProfileIsNULL == FALSE)
  8243. {
  8244. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8245. {
  8246. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  8247. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8248. //memset idTag
  8249. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  8250. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8251. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  8252. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8253. // Save profile to file
  8254. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8255. system(cmdBuf);
  8256. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8257. fp = fopen(cmdBuf, "w");
  8258. 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));
  8259. fclose(fp);
  8260. }
  8261. else
  8262. {
  8263. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  8264. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8265. }
  8266. }
  8267. else
  8268. {
  8269. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  8270. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8271. //memset idTag
  8272. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  8273. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8274. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  8275. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8276. }
  8277. }
  8278. else
  8279. {
  8280. DEBUG_WARN("Connector id over\n.");
  8281. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8282. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8283. }
  8284. end:
  8285. json_object_put(RemoteStartTransaction);
  8286. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  8287. {
  8288. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  8289. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8290. }
  8291. //OCPP send RemoteStartConfirmation by first.
  8292. sendRemoteStartConfirmation(uuid, comfirmstr);
  8293. return result;
  8294. }
  8295. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  8296. {
  8297. mtrace();
  8298. int result = FAIL;
  8299. int match = FALSE;
  8300. int GunNO = 0;
  8301. int tempIndex = 0;
  8302. int transactionIdInt=0;
  8303. int transactionIdIsNULL= TRUE;
  8304. char comfirmstr[20];
  8305. json_object *RemoteStopTransaction;
  8306. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  8307. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  8308. if(server_pending == TRUE)
  8309. {
  8310. return 0;
  8311. }
  8312. RemoteStopTransaction = json_tokener_parse(payload);
  8313. if(!is_error(RemoteStopTransaction))
  8314. {
  8315. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  8316. {
  8317. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  8318. transactionIdIsNULL = FALSE;
  8319. }
  8320. }
  8321. json_object_put(RemoteStopTransaction);
  8322. if(transactionIdIsNULL == FALSE)
  8323. {
  8324. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  8325. {
  8326. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  8327. {
  8328. //check Transaction active
  8329. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  8330. {
  8331. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8332. {
  8333. tempIndex = ((gun_index==2) ? 1: 0);
  8334. }
  8335. else
  8336. {
  8337. tempIndex = gun_index;
  8338. }
  8339. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8340. {
  8341. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8342. {
  8343. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8344. {
  8345. match = TRUE;
  8346. GunNO = gun_index;
  8347. }
  8348. }
  8349. }// END FOR CHAdeMO_QUANTITY
  8350. }
  8351. else if(gunType[gun_index] == GUN_TYPE_CCS)
  8352. {
  8353. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8354. {
  8355. tempIndex = ((gun_index==2) ? 1: 0);
  8356. }
  8357. else
  8358. {
  8359. tempIndex = gun_index;
  8360. }
  8361. for (int index = 0; index < CCS_QUANTITY; index++)
  8362. {
  8363. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8364. {
  8365. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8366. {
  8367. match = TRUE;
  8368. GunNO = gun_index;
  8369. }
  8370. }
  8371. }// END FOR CCS_QUANTITY
  8372. }
  8373. else if(gunType[gun_index] == GUN_TYPE_GBT)
  8374. {
  8375. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8376. {
  8377. tempIndex = ((gun_index==2) ? 1: 0);
  8378. }
  8379. else
  8380. {
  8381. tempIndex = gun_index;
  8382. }
  8383. for (int index = 0; index < GB_QUANTITY; index++)
  8384. {
  8385. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8386. {
  8387. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8388. {
  8389. match = TRUE;
  8390. GunNO = gun_index;
  8391. }
  8392. }
  8393. }// END FOR GB_QUANTITY
  8394. }
  8395. else if(gunType[gun_index] == GUN_TYPE_DO)
  8396. {
  8397. tempIndex = gun_index;
  8398. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8399. {
  8400. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8401. {
  8402. 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
  8403. {
  8404. match = TRUE;
  8405. GunNO = gun_index;
  8406. }
  8407. }
  8408. }// END FOR GB_QUANTITY
  8409. }
  8410. else
  8411. {
  8412. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8413. {
  8414. tempIndex = 2;
  8415. }
  8416. else
  8417. {
  8418. tempIndex = gun_index;
  8419. }
  8420. for (int index = 0; index < AC_QUANTITY; index++)
  8421. {
  8422. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8423. {
  8424. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8425. {
  8426. match = TRUE;
  8427. GunNO = gun_index;
  8428. }
  8429. }
  8430. }// END FOR CHAdeMO_QUANTITY
  8431. } // END FOR AC ELSE
  8432. }// CHECK IF ResponseTransactionId == transactionIdInt
  8433. }//END FOR
  8434. if( match == TRUE)
  8435. {
  8436. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  8437. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8438. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  8439. }
  8440. else
  8441. {
  8442. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8443. }
  8444. }
  8445. else
  8446. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8447. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  8448. return result;
  8449. }
  8450. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  8451. {
  8452. mtrace();
  8453. int result = FAIL;
  8454. int connectorIdInt=0, reservationIdInt=0;
  8455. int tempIndex = 0;
  8456. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  8457. char comfirmstr[20]={0};
  8458. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  8459. int c = 0;
  8460. char *loc;
  8461. //char *ptr;
  8462. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  8463. strcpy(sstrtemp, stringtrimspace(payload));
  8464. //***(1)connectorId ****/
  8465. c=0;
  8466. loc = strstr(sstrtemp, "connectorId");
  8467. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8468. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  8469. {
  8470. sstr[c] = loc[strlen("connectorId")+2+c];
  8471. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8472. c++;
  8473. }
  8474. sstr[c] = '\0';
  8475. connectorIdInt = atoi(sstr);
  8476. //***(2)expiryDate ****/
  8477. loc = strstr(sstrtemp, "expiryDate");
  8478. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8479. c = 0;
  8480. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  8481. {
  8482. sstr[c] = loc[3+strlen("expiryDate")+c];
  8483. c++;
  8484. }
  8485. sstr[c] = '\0';
  8486. strcpy(expiryDatestr, sstr);
  8487. //***(3)idTag ****/
  8488. loc = strstr(sstrtemp, "idTag");
  8489. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8490. c = 0;
  8491. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  8492. {
  8493. sstr[c] = loc[3+strlen("idTag")+c];
  8494. c++;
  8495. }
  8496. sstr[c] = '\0';
  8497. strcpy(idTagstr, sstr);
  8498. //***(4)parentIdTag ****/
  8499. loc = strstr(sstrtemp, "parentIdTag");
  8500. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8501. c = 0;
  8502. if(loc == NULL)
  8503. {
  8504. strcpy(parentIdTagstr, "");
  8505. }
  8506. else
  8507. {
  8508. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8509. {
  8510. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8511. c++;
  8512. }
  8513. sstr[c] = '\0';
  8514. strcpy(parentIdTagstr, sstr);
  8515. }
  8516. //***(5)reservationId ****/
  8517. c=0;
  8518. loc = strstr(sstrtemp, "reservationId");
  8519. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8520. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  8521. {
  8522. sstr[c] = loc[strlen("reservationId")+2+c];
  8523. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8524. c++;
  8525. }
  8526. sstr[c] = '\0';
  8527. reservationIdInt = atoi(sstr);
  8528. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8529. /*
  8530. enum SYSTEM_STATUS
  8531. {
  8532. SYS_MODE_BOOTING = 0,
  8533. SYS_MODE_IDLE = 1,
  8534. SYS_MODE_AUTHORIZING = 2,
  8535. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  8536. SYS_MODE_REASSIGN = 4,
  8537. SYS_MODE_PREPARING = 5,
  8538. SYS_MODE_PREPARE_FOR_EV = 6,
  8539. SYS_MODE_PREPARE_FOR_EVSE = 7,
  8540. SYS_MODE_CHARGING = 8,
  8541. SYS_MODE_TERMINATING = 9,
  8542. SYS_MODE_COMPLETE = 10,
  8543. SYS_MODE_ALARM = 11,
  8544. SYS_MODE_FAULT = 12,
  8545. SYS_MODE_RESERVATION = 13,
  8546. SYS_MODE_BOOKING = 14,
  8547. SYS_MODE_MAINTAIN = 15,
  8548. SYS_MODE_DEBUG = 16,
  8549. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  8550. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  8551. SYS_MODE_UPDATE = 19
  8552. };
  8553. */
  8554. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  8555. {
  8556. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8557. goto end;
  8558. }
  8559. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  8560. {
  8561. //check Transaction active
  8562. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8563. {
  8564. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8565. {
  8566. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8567. }
  8568. else
  8569. {
  8570. tempIndex = connectorIdInt -1;
  8571. }
  8572. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8573. {
  8574. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8575. {
  8576. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8577. {
  8578. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8579. {
  8580. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8581. {
  8582. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8583. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8584. }
  8585. 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'))
  8586. {
  8587. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8588. }
  8589. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8590. {
  8591. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8592. }
  8593. else
  8594. {
  8595. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8596. }
  8597. }
  8598. 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
  8599. {
  8600. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8601. }
  8602. }
  8603. else
  8604. {
  8605. //replace reservation
  8606. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8607. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8608. }
  8609. }
  8610. } // END FOR CHAdeMO_QUANTITY
  8611. }
  8612. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8613. {
  8614. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8615. {
  8616. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8617. }
  8618. else
  8619. {
  8620. tempIndex = connectorIdInt -1;
  8621. }
  8622. for (int index = 0; index < CCS_QUANTITY; index++)
  8623. {
  8624. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8625. {
  8626. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8627. {
  8628. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8629. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8630. {
  8631. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8632. {
  8633. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8634. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8635. }
  8636. 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'))
  8637. {
  8638. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8639. }
  8640. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  8641. {
  8642. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8643. }
  8644. else
  8645. {
  8646. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8647. }
  8648. }
  8649. 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
  8650. {
  8651. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8652. }
  8653. }
  8654. else
  8655. {
  8656. //replace reservation
  8657. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8658. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8659. }
  8660. }
  8661. } // END FOR CCS_QUANTITY
  8662. }
  8663. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8664. {
  8665. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8666. {
  8667. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8668. }
  8669. else
  8670. {
  8671. tempIndex = connectorIdInt -1;
  8672. }
  8673. for (int index = 0; index < GB_QUANTITY; index++)
  8674. {
  8675. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8676. {
  8677. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8678. {
  8679. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8680. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8681. {
  8682. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8683. {
  8684. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8685. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8686. }
  8687. 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'))
  8688. {
  8689. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8690. }
  8691. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8692. {
  8693. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8694. }
  8695. else
  8696. {
  8697. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8698. }
  8699. }
  8700. 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
  8701. {
  8702. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8703. }
  8704. }
  8705. else
  8706. {
  8707. //replace reservation
  8708. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8709. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8710. }
  8711. }
  8712. }// END FOR GB_QUANTITY
  8713. }
  8714. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8715. {
  8716. tempIndex = connectorIdInt -1;
  8717. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8718. {
  8719. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8720. {
  8721. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  8722. {
  8723. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8724. 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
  8725. {
  8726. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8727. {
  8728. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8729. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8730. }
  8731. 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'))
  8732. {
  8733. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8734. }
  8735. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8736. {
  8737. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8738. }
  8739. else
  8740. {
  8741. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8742. }
  8743. }
  8744. 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
  8745. {
  8746. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8747. }
  8748. }
  8749. else
  8750. {
  8751. //replace reservation
  8752. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8753. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8754. }
  8755. }
  8756. }// END FOR GB_QUANTITY
  8757. }
  8758. else
  8759. {
  8760. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8761. {
  8762. tempIndex = 2;
  8763. }
  8764. else
  8765. {
  8766. tempIndex = (connectorIdInt -1);
  8767. }
  8768. for (int index = 0; index < AC_QUANTITY; index++)
  8769. {
  8770. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8771. {
  8772. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8773. {
  8774. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8775. {
  8776. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8777. {
  8778. 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))
  8779. {
  8780. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8781. }
  8782. else
  8783. {
  8784. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8785. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8786. }
  8787. }
  8788. 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'))
  8789. {
  8790. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8791. }
  8792. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8793. {
  8794. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8795. }
  8796. else
  8797. {
  8798. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8799. }
  8800. }
  8801. 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
  8802. {
  8803. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8804. }
  8805. }
  8806. else
  8807. {
  8808. //replace reservation
  8809. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8810. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8811. }
  8812. }
  8813. } // END FOR AC_QUANTITY
  8814. }
  8815. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8816. }
  8817. else if(connectorIdInt == 0)
  8818. {
  8819. //check Transaction active
  8820. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8821. {
  8822. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8823. {
  8824. 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'))
  8825. {
  8826. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8827. goto end;
  8828. }
  8829. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8830. {
  8831. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8832. goto end;
  8833. }
  8834. 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
  8835. {
  8836. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8837. goto end;
  8838. }
  8839. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8840. {
  8841. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8842. goto end;
  8843. }
  8844. }
  8845. }// END FOR CHAdeMO_QUANTITY
  8846. for (int index = 0; index < CCS_QUANTITY; index++)
  8847. {
  8848. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8849. {
  8850. 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'))
  8851. {
  8852. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8853. goto end;
  8854. }
  8855. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  8856. {
  8857. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8858. goto end;
  8859. }
  8860. 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
  8861. {
  8862. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8863. goto end;
  8864. }
  8865. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8866. {
  8867. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8868. goto end;
  8869. }
  8870. }
  8871. } // END FOR CCS_QUANTITY
  8872. for (int index = 0; index < GB_QUANTITY; index++)
  8873. {
  8874. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8875. {
  8876. 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'))
  8877. {
  8878. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8879. goto end;
  8880. }
  8881. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8882. {
  8883. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8884. goto end;
  8885. }
  8886. 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
  8887. {
  8888. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8889. goto end;
  8890. }
  8891. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8892. {
  8893. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8894. goto end;
  8895. }
  8896. }
  8897. } // END FOR GB_QUANTITY
  8898. for (int index = 0; index < AC_QUANTITY; index++)
  8899. {
  8900. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8901. {
  8902. 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'))
  8903. {
  8904. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8905. goto end;
  8906. }
  8907. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8908. {
  8909. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8910. goto end;
  8911. }
  8912. 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
  8913. {
  8914. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8915. goto end;
  8916. }
  8917. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8918. {
  8919. 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))
  8920. {
  8921. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8922. goto end;
  8923. }
  8924. }
  8925. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8926. {
  8927. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8928. goto end;
  8929. }
  8930. }
  8931. }// END FOR AC_QUANTITY
  8932. //The connectorId is 0
  8933. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  8934. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8935. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  8936. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  8937. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  8938. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  8939. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  8940. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  8941. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  8942. result = TRUE;
  8943. return result;
  8944. }
  8945. else
  8946. {
  8947. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8948. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8949. }
  8950. if(strcmp(comfirmstr,"Accepted") == 0)
  8951. {
  8952. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  8953. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  8954. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  8955. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  8956. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  8957. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  8958. result = TRUE;
  8959. return result;
  8960. }
  8961. end:
  8962. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  8963. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  8964. return result;
  8965. }
  8966. int handleResetRequest(char *uuid, char *payload)
  8967. {
  8968. mtrace();
  8969. int result = FAIL;
  8970. char sstr[10]={0},sstrtemp[30]={ 0 };
  8971. char typestr[10]={0};
  8972. char comfirmstr[20]={0};
  8973. int c = 0;
  8974. char *loc;
  8975. DEBUG_INFO("handleResetRequest...\n");
  8976. strcpy(sstrtemp, stringtrimspace(payload));
  8977. loc = strstr(sstrtemp, "type");
  8978. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8979. c = 0;
  8980. while (loc[3+strlen("type")+c] != '\"')
  8981. {
  8982. sstr[c] = loc[3+strlen("type")+c];
  8983. c++;
  8984. }
  8985. sstr[c] = '\0';
  8986. strcpy(typestr,sstr);
  8987. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  8988. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  8989. {
  8990. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  8991. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  8992. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  8993. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  8994. }
  8995. else
  8996. {
  8997. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  8998. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  8999. result = PASS;
  9000. }
  9001. sendResetConfirmation(uuid, comfirmstr);
  9002. return result;
  9003. }
  9004. int handleSendLocalListRequest(char *uuid, char *payload)
  9005. {
  9006. mtrace();
  9007. int result = FAIL;
  9008. int listVersionInt;
  9009. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  9010. char listsearch[]="listVersion";
  9011. char updateTypesearch[]="updateType";
  9012. char localAuthorizationListsearch[]="localAuthorizationList";
  9013. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  9014. char CardList[500][160]={0};
  9015. char updateTypestr[15]={0};
  9016. char idTagstr[20]={0};
  9017. char parentIdTag[20]={0};
  9018. char expiryDate[30]={0};
  9019. char idTagstatus[16]={0};
  9020. int c = 0;
  9021. int i = 0;
  9022. char *delim1 = "}";
  9023. char * pch;
  9024. char *loc;
  9025. //char *ptr;
  9026. char comfirmstr[20];
  9027. //int n_localAuthorizations = 0;
  9028. int checkState_Faulted = FALSE;
  9029. DEBUG_INFO("handleSendLocalListRequest...\n");
  9030. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  9031. {
  9032. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9033. goto end;
  9034. }
  9035. //check Charge Point state
  9036. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9037. {
  9038. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9039. {
  9040. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9041. }
  9042. }
  9043. for (int index = 0; index < CCS_QUANTITY; index++)
  9044. {
  9045. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9046. {
  9047. checkState_Faulted = TRUE; //OCPP Status
  9048. }
  9049. }
  9050. for (int index = 0; index < GB_QUANTITY; index++)
  9051. {
  9052. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9053. {
  9054. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9055. }
  9056. }
  9057. //check Charge Point state
  9058. for (int index = 0; index < AC_QUANTITY; index++)
  9059. {
  9060. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9061. {
  9062. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9063. }
  9064. }
  9065. if(checkState_Faulted == TRUE)
  9066. {
  9067. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9068. goto end;
  9069. }
  9070. //Filter payload space
  9071. strcpy(sstrtemp, stringtrimspace(payload));
  9072. //listVersion
  9073. c = 0;
  9074. loc = strstr(sstrtemp, listsearch);
  9075. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  9076. {
  9077. sstr[c] = loc[strlen("listVersion")+2+c];
  9078. c++;
  9079. }
  9080. sstr[c] = '\0';
  9081. listVersionInt = atoi(sstr);
  9082. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  9083. //updateType
  9084. loc = strstr(sstrtemp, updateTypesearch);
  9085. c = 0;
  9086. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  9087. {
  9088. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  9089. c++;
  9090. }
  9091. sstr[c] = '\0';
  9092. strcpy(updateTypestr, sstr);
  9093. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  9094. //localAuthorizationList
  9095. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9096. loc = strstr(sstrtemp, localAuthorizationListsearch);
  9097. if(loc != NULL) // localAuthorizationList is not NULL
  9098. {
  9099. //Check UpdateType
  9100. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9101. {
  9102. //Local list full update
  9103. printf("Local list full update.\n");
  9104. OCPP_getListVerion();
  9105. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  9106. {
  9107. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9108. goto end;
  9109. }
  9110. OCPP_cleanLocalList();
  9111. }
  9112. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9113. {
  9114. //Local list different update
  9115. printf("Local list different update.\n");
  9116. OCPP_getListVerion();
  9117. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  9118. {
  9119. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  9120. goto end;
  9121. }
  9122. }
  9123. else
  9124. {
  9125. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9126. goto end;
  9127. }
  9128. c = 0;
  9129. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  9130. {
  9131. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  9132. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9133. c++;
  9134. }
  9135. sstr[c] = '\0';
  9136. //DEBUG_INFO("sstr=%s\n", sstr);
  9137. //parsing strings to words
  9138. i = 0;
  9139. pch = strtok(sstr,delim1);
  9140. while (pch != NULL)
  9141. {
  9142. strcpy(CardList[i], pch);
  9143. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  9144. pch = strtok (NULL, delim1);
  9145. i = i + 1;
  9146. }
  9147. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  9148. //local Authorizations List Numbers
  9149. //n_localAuthorizations = i;
  9150. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  9151. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  9152. c= 0;
  9153. while(c < i) // i is CardList Number
  9154. {
  9155. //Search "IdToken"
  9156. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9157. loc = strstr(CardList[c], "idTag");
  9158. int j = 0;
  9159. while (loc[3+strlen("idTag")+j] != '\"')
  9160. {
  9161. sstr[j] = loc[3+strlen("idTag")+j];
  9162. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9163. j++;
  9164. }
  9165. sstr[j] = '\0';
  9166. strcpy(idTagstr, sstr);
  9167. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  9168. //Search "expiryDate"
  9169. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9170. loc = strstr(CardList[c], "expiryDate");
  9171. j = 0;
  9172. if(loc != NULL)
  9173. {
  9174. while (loc[3+strlen("expiryDate")+j] != '\"')
  9175. {
  9176. sstr[j] = loc[3+strlen("expiryDate")+j];
  9177. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9178. j++;
  9179. }
  9180. sstr[j] = '\0';
  9181. strcpy(expiryDate, sstr);
  9182. }
  9183. else
  9184. {
  9185. strcpy(expiryDate, "");
  9186. }
  9187. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  9188. //Search "parentIdTag"
  9189. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9190. loc = strstr(CardList[c], "parentIdTag");
  9191. j = 0;
  9192. if(loc != NULL)
  9193. {
  9194. while (loc[3+strlen("parentIdTag")+j] != '\"')
  9195. {
  9196. sstr[j] = loc[3+strlen("parentIdTag")+j];
  9197. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9198. j++;
  9199. }
  9200. sstr[j] = '\0';
  9201. strcpy(parentIdTag, sstr);
  9202. }
  9203. else
  9204. {
  9205. strcpy(parentIdTag, "");
  9206. }
  9207. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  9208. //Search "status"
  9209. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9210. loc = strstr(CardList[c], "status");
  9211. j = 0;
  9212. while (loc[3+strlen("status")+j] != '\"')
  9213. {
  9214. sstr[j] = loc[3+strlen("status")+j];
  9215. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9216. j++;
  9217. }
  9218. sstr[j] = '\0';
  9219. strcpy(idTagstatus, sstr);
  9220. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  9221. OCPP_getIdTagFromLocalList(idTagstr);
  9222. //OCPP_getIdTagFromLocalList("test"); For Test
  9223. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  9224. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  9225. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9226. {
  9227. //Local list full update
  9228. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9229. // update list
  9230. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9231. //DEBUG_INFO("Local list full update. 1\n");
  9232. //OCPP_get_TableAuthlocalAllData();
  9233. //DEBUG_INFO("Local list full update. 2\n");
  9234. }
  9235. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9236. {
  9237. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9238. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  9239. }
  9240. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  9241. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  9242. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  9243. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  9244. c++;
  9245. }
  9246. }
  9247. else
  9248. {
  9249. //Check UpdateType
  9250. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9251. {
  9252. //Local list full update
  9253. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  9254. OCPP_cleanLocalList();
  9255. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9256. goto end;
  9257. }
  9258. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9259. {
  9260. //Local list different update
  9261. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  9262. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9263. goto end;
  9264. }
  9265. }
  9266. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9267. end:
  9268. sendSendLocalListConfirmation(uuid, comfirmstr);
  9269. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  9270. return result;
  9271. }
  9272. #define MAX 200
  9273. int handleSetChargingProfileRequest(char *uuid, char *payload)
  9274. {
  9275. mtrace();
  9276. int result = FAIL;
  9277. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  9278. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  9279. char chargingProfilePurposeStr[30]={0};
  9280. char chargingProfileKindStr[16]={0};
  9281. char recurrencyKindStr[10]={0};
  9282. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  9283. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  9284. int chargingSchedulePeriodCount = 0;
  9285. char comfirmstr[20]={0};
  9286. int meet= FALSE;
  9287. FILE *fptr1;
  9288. char filename[MAX]={0};
  9289. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  9290. char rmFileCmd[50]={0};
  9291. char tempchargingProfilePurposeStr[30]={0};
  9292. char word[1600]={0};
  9293. int n_chargingProfile = 0;
  9294. json_object *SetChargingProfile;
  9295. DEBUG_INFO("handleSetChargingProfileRequest\n");
  9296. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  9297. SetChargingProfile = json_tokener_parse(payload);
  9298. if(!is_error(SetChargingProfile))
  9299. {
  9300. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  9301. {
  9302. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  9303. if(connectorIdInt == 0)
  9304. {
  9305. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  9306. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  9307. }
  9308. else
  9309. {
  9310. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  9311. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  9312. }
  9313. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  9314. }
  9315. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  9316. {
  9317. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9318. {
  9319. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9320. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9321. {
  9322. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9323. }
  9324. else
  9325. {
  9326. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9327. }
  9328. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  9329. }
  9330. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9331. {
  9332. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  9333. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9334. {
  9335. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  9336. }
  9337. else
  9338. {
  9339. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  9340. }
  9341. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  9342. }
  9343. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9344. {
  9345. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9346. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9347. {
  9348. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9349. }
  9350. else
  9351. {
  9352. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9353. }
  9354. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  9355. }
  9356. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  9357. {
  9358. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  9359. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9360. {
  9361. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9362. }
  9363. else
  9364. {
  9365. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9366. }
  9367. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  9368. }
  9369. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  9370. {
  9371. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  9372. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9373. {
  9374. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  9375. }
  9376. else
  9377. {
  9378. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  9379. }
  9380. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  9381. }
  9382. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  9383. {
  9384. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  9385. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9386. {
  9387. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9388. }
  9389. else
  9390. {
  9391. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9392. }
  9393. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  9394. }
  9395. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  9396. {
  9397. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  9398. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9399. {
  9400. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  9401. }
  9402. else
  9403. {
  9404. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  9405. }
  9406. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  9407. }
  9408. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  9409. {
  9410. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  9411. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9412. {
  9413. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  9414. }
  9415. else
  9416. {
  9417. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  9418. }
  9419. //DEBUG_INFO("validToStr: %s\n", validToStr);
  9420. }
  9421. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  9422. {
  9423. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  9424. {
  9425. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  9426. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9427. {
  9428. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9429. }
  9430. else
  9431. {
  9432. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9433. }
  9434. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  9435. }
  9436. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  9437. {
  9438. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  9439. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9440. {
  9441. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9442. }
  9443. else
  9444. {
  9445. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9446. }
  9447. //DEBUG_INFO("durationInt: %d\n", durationInt);
  9448. }
  9449. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  9450. {
  9451. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  9452. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9453. {
  9454. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9455. }
  9456. else
  9457. {
  9458. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9459. }
  9460. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  9461. }
  9462. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  9463. {
  9464. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  9465. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9466. {
  9467. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9468. }
  9469. else
  9470. {
  9471. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9472. }
  9473. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  9474. }
  9475. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9476. {
  9477. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  9478. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  9479. if(chargingSchedulePeriodCount <= 10)
  9480. {
  9481. 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++)
  9482. {
  9483. 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)
  9484. {
  9485. 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"));
  9486. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9487. {
  9488. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9489. }
  9490. else
  9491. {
  9492. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9493. }
  9494. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  9495. }
  9496. 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)
  9497. {
  9498. 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"));
  9499. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9500. {
  9501. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9502. }
  9503. else
  9504. {
  9505. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9506. }
  9507. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  9508. }
  9509. 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)
  9510. {
  9511. 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"));
  9512. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9513. {
  9514. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9515. }
  9516. else
  9517. {
  9518. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9519. }
  9520. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  9521. }
  9522. }
  9523. }
  9524. }
  9525. }
  9526. }
  9527. }
  9528. json_object_put(SetChargingProfile);
  9529. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  9530. {
  9531. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9532. goto end;
  9533. }
  9534. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  9535. {
  9536. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  9537. if(connectorIdInt != 0)
  9538. {
  9539. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9540. goto end;
  9541. }
  9542. strcpy(filename, ChargePointMaxProfile_JSON );
  9543. fptr1 = fopen(filename, "r");
  9544. if (!fptr1)
  9545. {
  9546. //file not exist
  9547. DEBUG_INFO("Unable to open the input file!!\n");
  9548. fptr1 = fopen(filename, "w+");
  9549. }
  9550. else
  9551. {
  9552. //Check Charging Profile Count
  9553. while(fscanf(fptr1, "%s", word) != EOF)
  9554. {
  9555. //DEBUG_INFO("word=%s\n",word);
  9556. if(strstr(word, "chargingProfileId")!= NULL)
  9557. {
  9558. //DEBUG_INFO("test chargingProfileId \n");
  9559. n_chargingProfile = n_chargingProfile + 1;
  9560. //DEBUG_INFO("chargingProfileId Found\n");
  9561. }
  9562. }
  9563. }
  9564. fclose(fptr1);
  9565. }
  9566. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  9567. {
  9568. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  9569. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9570. {
  9571. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9572. goto end;
  9573. }
  9574. memset(filename, 0, ARRAY_SIZE(filename));
  9575. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9576. fptr1 = fopen(filename, "r");
  9577. if (!fptr1)
  9578. {
  9579. //file not exist
  9580. //DEBUG_INFO("Unable to open the input file!!\n");
  9581. fptr1 = fopen(filename, "w+");
  9582. }
  9583. else
  9584. {
  9585. //Check Charging Profile Count
  9586. while(fscanf(fptr1, "%s", word) != EOF)
  9587. {
  9588. //DEBUG_INFO("word=%s\n",word);
  9589. if(strstr(word, "chargingProfileId")!= NULL)
  9590. {
  9591. //DEBUG_INFO("test chargingProfileId \n");
  9592. n_chargingProfile = n_chargingProfile + 1;
  9593. //DEBUG_INFO("chargingProfileId Found\n");
  9594. }
  9595. }
  9596. }
  9597. fclose(fptr1);
  9598. }
  9599. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9600. {
  9601. //printf("set chargingProfile 1-4\n");
  9602. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  9603. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  9604. if(connectorIdInt == 0)
  9605. {
  9606. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9607. goto end;
  9608. }
  9609. int tempIndex = 0;
  9610. //check Transaction active
  9611. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9612. {
  9613. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9614. {
  9615. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9616. }
  9617. else
  9618. {
  9619. tempIndex = connectorIdInt -1;
  9620. }
  9621. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9622. {
  9623. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9624. {
  9625. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9626. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9627. {
  9628. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9629. {
  9630. meet = TRUE;
  9631. break;
  9632. }
  9633. }
  9634. }
  9635. }
  9636. }
  9637. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9638. {
  9639. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9640. {
  9641. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9642. }
  9643. else
  9644. {
  9645. tempIndex = connectorIdInt -1;
  9646. }
  9647. for (int index = 0; index < CCS_QUANTITY; index++)
  9648. {
  9649. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9650. {
  9651. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9652. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9653. {
  9654. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9655. {
  9656. meet = TRUE;
  9657. break;
  9658. }
  9659. }
  9660. }
  9661. }
  9662. }
  9663. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9664. {
  9665. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9666. {
  9667. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9668. }
  9669. else
  9670. {
  9671. tempIndex = connectorIdInt -1;
  9672. }
  9673. for (int index = 0; index < GB_QUANTITY; index++)
  9674. {
  9675. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9676. {
  9677. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9678. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9679. {
  9680. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9681. {
  9682. meet = TRUE;
  9683. break;
  9684. }
  9685. }
  9686. }
  9687. }
  9688. }
  9689. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9690. {
  9691. tempIndex = connectorIdInt -1;
  9692. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9693. {
  9694. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9695. {
  9696. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  9697. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9698. {
  9699. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9700. {
  9701. meet = TRUE;
  9702. break;
  9703. }
  9704. }
  9705. }
  9706. }
  9707. }
  9708. else
  9709. {
  9710. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9711. {
  9712. tempIndex = 2;
  9713. }
  9714. else
  9715. {
  9716. tempIndex = (connectorIdInt -1);
  9717. }
  9718. for (int index = 0; index < AC_QUANTITY; index++)
  9719. {
  9720. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9721. {
  9722. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9723. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9724. {
  9725. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9726. {
  9727. meet = TRUE;
  9728. break;
  9729. }
  9730. }
  9731. }
  9732. }
  9733. }
  9734. //check Transaction active
  9735. if(meet == FALSE)
  9736. {
  9737. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9738. goto end;
  9739. }
  9740. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9741. {
  9742. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9743. goto end;
  9744. }
  9745. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9746. fptr1 = fopen(filename, "r");
  9747. if (!fptr1)
  9748. {
  9749. //file not exist
  9750. DEBUG_INFO("Unable to open the input file!!\n");
  9751. fptr1 = fopen(filename, "w+");
  9752. }
  9753. else
  9754. {
  9755. //Check Charging Profile Count
  9756. while(fscanf(fptr1, "%s", word) != EOF)
  9757. {
  9758. //DEBUG_INFO("word=%s\n",word);
  9759. if(strstr(word, "chargingProfileId")!= NULL)
  9760. {
  9761. //DEBUG_INFO("test chargingProfileId \n");
  9762. n_chargingProfile = n_chargingProfile + 1;
  9763. //DEBUG_INFO("chargingProfileId Found\n");
  9764. }
  9765. }
  9766. }
  9767. fclose(fptr1);
  9768. }
  9769. // Check ChargeProfileMaxStackLevel
  9770. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  9771. {
  9772. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9773. goto end;
  9774. }
  9775. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9776. {
  9777. int i = 0;
  9778. char fnametemp[200]={0};
  9779. n_chargingProfile = 0;
  9780. //Check ChargePointMaxProfile.json exit
  9781. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9782. {
  9783. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  9784. //Check Charging Profile Count
  9785. while(fscanf(fptr1, "%s", word) != EOF)
  9786. {
  9787. //DEBUG_INFO("word=%s\n",word);
  9788. if(strstr(word, "chargingProfileId")!= NULL)
  9789. {
  9790. //DEBUG_INFO("test chargingProfileId \n");
  9791. n_chargingProfile = n_chargingProfile + 1;
  9792. i = i + 1;
  9793. //DEBUG_INFO("chargingProfileId Found\n");
  9794. }
  9795. memset(word, 0, ARRAY_SIZE(word));
  9796. }
  9797. fclose(fptr1);
  9798. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  9799. }
  9800. //Check TxDefaultProfile_0.json exit
  9801. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9802. {
  9803. i = 0;
  9804. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  9805. //Check Charging Profile Count
  9806. while(fscanf(fptr1, "%s", word) != EOF)
  9807. {
  9808. //DEBUG_INFO("word=%s\n",word);
  9809. if(strstr(word, "chargingProfileId")!= NULL)
  9810. {
  9811. //DEBUG_INFO("test chargingProfileId \n");
  9812. n_chargingProfile = n_chargingProfile + 1;
  9813. i = i + 1;
  9814. //DEBUG_INFO("chargingProfileId Found\n");
  9815. }
  9816. memset(word, 0, ARRAY_SIZE(word));
  9817. }
  9818. fclose(fptr1);
  9819. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  9820. }
  9821. //Check TxDefaultProfile_%d.json
  9822. for(int j=1; j <= gunTotalNumber; j++)
  9823. {
  9824. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9825. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9826. if((access(fnametemp,F_OK))!=-1)
  9827. {
  9828. i = 0;
  9829. fptr1 = fopen(fnametemp, "r");
  9830. //Check Charging Profile Count
  9831. while(fscanf(fptr1, "%s", word) != EOF)
  9832. {
  9833. //DEBUG_INFO("word=%s\n",word);
  9834. if(strstr(word, "chargingProfileId")!= NULL)
  9835. {
  9836. //DEBUG_INFO("test chargingProfileId \n");
  9837. n_chargingProfile = n_chargingProfile + 1;
  9838. i = i + 1;
  9839. //DEBUG_INFO("chargingProfileId Found\n");
  9840. }
  9841. memset(word, 0, ARRAY_SIZE(word));
  9842. }
  9843. fclose(fptr1);
  9844. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9845. }
  9846. }
  9847. //Check TxProfile_%d.json
  9848. for(int j=1; j <= gunTotalNumber; j++)
  9849. {
  9850. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9851. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9852. if((access(fnametemp,F_OK))!=-1)
  9853. {
  9854. i = 0;
  9855. fptr1 = fopen(fnametemp, "r");
  9856. //Check Charging Profile Count
  9857. while(fscanf(fptr1, "%s", word) != EOF)
  9858. {
  9859. //DEBUG_INFO("word=%s\n",word);
  9860. if(strstr(word, "chargingProfileId")!= NULL)
  9861. {
  9862. //DEBUG_INFO("test chargingProfileId \n");
  9863. n_chargingProfile = n_chargingProfile + 1;
  9864. i = i + 1;
  9865. //DEBUG_INFO("chargingProfileId Found\n");
  9866. }
  9867. memset(word, 0, ARRAY_SIZE(word));
  9868. }
  9869. fclose(fptr1);
  9870. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9871. }
  9872. }
  9873. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  9874. {
  9875. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9876. goto end;
  9877. }
  9878. }
  9879. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9880. //**********************************Write to File********************************************************/
  9881. FILE *infile;
  9882. FILE *outfile;
  9883. infile = fopen (filename, "r");
  9884. outfile = fopen (tempfile, "w");
  9885. int d =0;
  9886. d = fgetc(infile);
  9887. rewind(infile);
  9888. if(d == EOF)
  9889. {
  9890. // Profile is empty
  9891. fprintf(outfile,"%s\n",payload);
  9892. fclose(infile);
  9893. fclose(outfile);
  9894. sprintf(rmFileCmd,"rm -f %s",filename);
  9895. system(rmFileCmd);
  9896. rename(tempfile, filename);
  9897. }
  9898. else
  9899. {
  9900. // Profile is not empty
  9901. char buf[2048]={0};
  9902. int ChargingProfileAdded = FALSE;
  9903. while (fgets(buf, sizeof(buf), infile) != NULL)
  9904. {
  9905. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9906. json_object *tmpChargingProfile;
  9907. tmpChargingProfile = json_tokener_parse(buf);
  9908. if(!is_error(SetChargingProfile))
  9909. {
  9910. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  9911. {
  9912. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  9913. }
  9914. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  9915. {
  9916. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9917. {
  9918. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9919. }
  9920. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9921. {
  9922. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  9923. }
  9924. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9925. {
  9926. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9927. }
  9928. }
  9929. }
  9930. json_object_put(tmpChargingProfile);
  9931. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  9932. {
  9933. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9934. {
  9935. //DEBUG_INFO("update set chargingProfile to file -0\n");
  9936. if(ChargingProfileAdded == FALSE)
  9937. {
  9938. fprintf(outfile,"%s\n",payload);
  9939. ChargingProfileAdded = TRUE;
  9940. }
  9941. }
  9942. else
  9943. {
  9944. if(tempstackLevelInt < stackLevelInt)
  9945. {
  9946. if(ChargingProfileAdded == FALSE)
  9947. {
  9948. fprintf(outfile,"%s\n",buf);
  9949. fprintf(outfile,"%s\n",payload);
  9950. ChargingProfileAdded = TRUE;
  9951. }
  9952. else
  9953. {
  9954. fprintf(outfile,"%s\n",buf);
  9955. }
  9956. }
  9957. else
  9958. {
  9959. if(ChargingProfileAdded == FALSE)
  9960. {
  9961. fprintf(outfile,"%s\n",buf);
  9962. fprintf(outfile,"%s\n",payload);
  9963. ChargingProfileAdded = TRUE;
  9964. }
  9965. else
  9966. {
  9967. fprintf(outfile,"%s\n",buf);
  9968. }
  9969. }
  9970. }
  9971. }
  9972. else
  9973. {
  9974. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9975. {
  9976. if(ChargingProfileAdded == FALSE)
  9977. {
  9978. fprintf(outfile,"%s\n",buf);
  9979. fprintf(outfile,"%s\n",payload);
  9980. ChargingProfileAdded = TRUE;
  9981. }
  9982. else
  9983. {
  9984. fprintf(outfile,"%s\n",buf);
  9985. }
  9986. }
  9987. else if(tempstackLevelInt < stackLevelInt)
  9988. {
  9989. if(ChargingProfileAdded == FALSE)
  9990. {
  9991. fprintf(outfile,"%s\n",buf);
  9992. fprintf(outfile,"%s\n",payload);
  9993. ChargingProfileAdded = TRUE;
  9994. }
  9995. else
  9996. {
  9997. fprintf(outfile,"%s\n",buf);
  9998. }
  9999. }
  10000. else
  10001. {
  10002. if(ChargingProfileAdded == FALSE)
  10003. {
  10004. fprintf(outfile,"%s\n",buf);
  10005. fprintf(outfile,"%s\n",payload);
  10006. ChargingProfileAdded = TRUE;
  10007. }
  10008. else
  10009. {
  10010. fprintf(outfile,"%s\n",buf);
  10011. }
  10012. }
  10013. }
  10014. } // end of while loop
  10015. fclose(infile);
  10016. fclose(outfile);
  10017. sprintf(rmFileCmd,"rm -f %s",filename);
  10018. system(rmFileCmd);
  10019. rename(tempfile, filename);
  10020. }
  10021. sleep(1);
  10022. result = TRUE;
  10023. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  10024. end:
  10025. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  10026. {
  10027. if(connectorIdInt == 0)
  10028. {
  10029. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  10030. {
  10031. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  10032. }
  10033. }
  10034. else
  10035. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  10036. }
  10037. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  10038. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10039. return result;
  10040. }
  10041. int handleTriggerMessageRequest(char *uuid, char *payload)
  10042. {
  10043. mtrace();
  10044. int result = FAIL;
  10045. int connectorIdIsNULL = FALSE;
  10046. int connectorIdInt =0;
  10047. char sstr[40]={0},sstrtemp[100]={ 0 };
  10048. char requestedMessagestr[40]={0};
  10049. char comfirmstr[20]={0};
  10050. int c = 0;
  10051. char *loc;
  10052. DEBUG_INFO("handleTriggerMessageRequest\n");
  10053. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  10054. strcpy(sstrtemp, stringtrimspace(payload));
  10055. c = 0;
  10056. loc = strstr(sstrtemp, "requestedMessage");
  10057. while (loc[3+strlen("requestedMessage")+c] != '\"')
  10058. {
  10059. sstr[c] = loc[3+strlen("requestedMessage")+c];
  10060. c++;
  10061. }
  10062. sstr[c] = '\0';
  10063. strcpy(requestedMessagestr, sstr);
  10064. c = 0;
  10065. loc = strstr(sstrtemp, "connectorId");
  10066. if(loc == NULL)
  10067. {
  10068. connectorIdIsNULL = TRUE;
  10069. }
  10070. else
  10071. {
  10072. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10073. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  10074. {
  10075. sstr[c] = loc[strlen("connectorId")+2+c];
  10076. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10077. c++;
  10078. }
  10079. sstr[c] = '\0';
  10080. connectorIdInt = atoi(sstr);
  10081. }
  10082. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  10083. {
  10084. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  10085. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  10086. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10087. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  10088. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  10089. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  10090. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  10091. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  10092. {
  10093. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10094. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10095. return TRUE;
  10096. }
  10097. else
  10098. {
  10099. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10100. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10101. }
  10102. }
  10103. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  10104. {
  10105. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  10106. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10107. return TRUE;
  10108. }
  10109. //==========================
  10110. // Trigger message
  10111. //==========================
  10112. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10113. {
  10114. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  10115. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  10116. {
  10117. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10118. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  10119. }
  10120. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10121. }
  10122. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  10123. {
  10124. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  10125. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10126. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10127. }
  10128. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  10129. {
  10130. //sendBootNotificationRequest();
  10131. server_sign = FALSE;
  10132. }
  10133. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  10134. {
  10135. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  10136. }
  10137. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  10138. {
  10139. if(connectorIdIsNULL == FALSE)
  10140. {
  10141. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  10142. {
  10143. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  10144. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  10145. }
  10146. }
  10147. else
  10148. {
  10149. for(int idx=0;idx< gunTotalNumber;idx++)
  10150. {
  10151. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10152. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10153. }
  10154. }
  10155. }
  10156. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  10157. {
  10158. if(connectorIdIsNULL == FALSE)
  10159. {
  10160. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  10161. {
  10162. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  10163. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  10164. }
  10165. }
  10166. else
  10167. {
  10168. for(int idx=0;idx< gunTotalNumber;idx++)
  10169. {
  10170. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  10171. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  10172. }
  10173. }
  10174. }
  10175. return result;
  10176. }
  10177. int handleUnlockConnectorRequest(char *uuid, char *payload)
  10178. {
  10179. mtrace();
  10180. int result = FAIL;
  10181. int connectorIdInt =0;
  10182. char comfirmstr[20]={0};
  10183. int tempIndex = 0;
  10184. json_object *UnlockConnector;
  10185. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  10186. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  10187. UnlockConnector = json_tokener_parse(payload);
  10188. if(!is_error(UnlockConnector))
  10189. {
  10190. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  10191. {
  10192. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  10193. }
  10194. }
  10195. json_object_put(UnlockConnector);
  10196. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  10197. if(gunTotalNumber == 0)
  10198. {
  10199. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10200. goto end;
  10201. }
  10202. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  10203. {
  10204. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10205. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10206. goto end;
  10207. }
  10208. else
  10209. {
  10210. //check Transaction active
  10211. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  10212. {
  10213. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10214. {
  10215. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10216. }
  10217. else
  10218. {
  10219. tempIndex = connectorIdInt -1;
  10220. }
  10221. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10222. {
  10223. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10224. {
  10225. //stop Transaction
  10226. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10227. }
  10228. }
  10229. }
  10230. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  10231. {
  10232. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10233. {
  10234. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10235. }
  10236. else
  10237. {
  10238. tempIndex = connectorIdInt -1;
  10239. }
  10240. for (int index = 0; index < CCS_QUANTITY; index++)
  10241. {
  10242. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10243. {
  10244. //stop Transaction
  10245. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10246. }
  10247. }
  10248. }
  10249. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  10250. {
  10251. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10252. {
  10253. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10254. }
  10255. else
  10256. {
  10257. tempIndex = connectorIdInt -1;
  10258. }
  10259. for (int index = 0; index < GB_QUANTITY; index++)
  10260. {
  10261. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  10262. {
  10263. //stop Transaction
  10264. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10265. }
  10266. }
  10267. }
  10268. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  10269. {
  10270. tempIndex = connectorIdInt -1;
  10271. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10272. {
  10273. 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)))
  10274. {
  10275. //stop Transaction
  10276. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10277. }
  10278. }
  10279. }
  10280. else
  10281. {
  10282. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10283. {
  10284. tempIndex = 2;
  10285. }
  10286. else
  10287. {
  10288. tempIndex = connectorIdInt-1;
  10289. }
  10290. for (int index = 0; index < AC_QUANTITY; index++)
  10291. {
  10292. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10293. {
  10294. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10295. }
  10296. }
  10297. }
  10298. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  10299. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  10300. result = TRUE;
  10301. return result;
  10302. }
  10303. end:
  10304. //json_object_put(obj); --- remove temporally
  10305. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  10306. return result;
  10307. }
  10308. static char UpdateFirmwarepayloadData[300]={0};
  10309. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  10310. {
  10311. mtrace();
  10312. int result = FAIL;
  10313. pthread_t t;
  10314. sendUpdateFirmwareConfirmation(uuid);
  10315. memset(UpdateFirmwarepayloadData, 0, 300);
  10316. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  10317. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  10318. ////pthread_join(t, NULL); //
  10319. //pthread_detach(t);
  10320. //sendUpdateFirmwareConfirmation(uuid);
  10321. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  10322. return result;
  10323. }
  10324. void *UpdateFirmwareProcess(void *data)
  10325. {
  10326. pthread_detach(pthread_self());
  10327. mtrace();
  10328. int retriesInt =0, retryIntervalInt=0;
  10329. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  10330. int port=0;
  10331. char locationstr[512]={0}, retrieveDatestr[36]={0};
  10332. int isSuccess = 0;
  10333. char ftpbuf[512];
  10334. char temp[100];
  10335. char * pch;
  10336. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  10337. json_object *UpdateFirmware;
  10338. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  10339. if(!is_error(UpdateFirmware))
  10340. {
  10341. // Required data
  10342. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  10343. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  10344. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  10345. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  10346. // Optional data
  10347. if(json_object_object_get(UpdateFirmware, "retries"))
  10348. {
  10349. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  10350. }
  10351. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  10352. {
  10353. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  10354. }
  10355. }
  10356. json_object_put(UpdateFirmware);
  10357. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10358. memset(path, 0, ARRAY_SIZE(path));
  10359. // Wait retrieveData
  10360. if(strlen(retrieveDatestr) > 10)
  10361. {
  10362. do
  10363. {
  10364. sleep(1);
  10365. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  10366. }
  10367. // Ready to download
  10368. system("rm -f /mnt/*");
  10369. if(strncmp(locationstr,"http", 4) == 0)
  10370. {
  10371. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10372. sprintf(ftppath,"/%s", path);
  10373. DEBUG_INFO("locationstr: %s\n", locationstr);
  10374. DEBUG_INFO("protocol: %s\n",protocol);
  10375. DEBUG_INFO("host: %s\n",host);
  10376. DEBUG_INFO("path: %s\n",path);
  10377. DEBUG_INFO("ftppath: %s\n",ftppath);
  10378. int ftppathlen=strlen(ftppath);
  10379. int i=1;
  10380. char filenametemp[50];
  10381. while(i < ftppathlen)
  10382. {
  10383. int len=ftppathlen-i;
  10384. if(ftppath[len]== 47) // '/' ascll code: 47
  10385. {
  10386. DEBUG_INFO("compare '/' all right\n");
  10387. break;
  10388. }
  10389. i=i+1;
  10390. }
  10391. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10392. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10393. filenametemp[i+1] = 0;
  10394. do
  10395. {
  10396. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  10397. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10398. sleep(1);
  10399. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  10400. if(!isSuccess)
  10401. {
  10402. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10403. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10404. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  10405. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10406. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10407. }
  10408. else
  10409. {
  10410. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10411. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10412. }
  10413. retriesInt--;
  10414. }while((isSuccess == 0)&&(retriesInt >= 0));
  10415. }
  10416. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  10417. {
  10418. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  10419. memset(temp, 0, ARRAY_SIZE(temp));
  10420. //DEBUG_INFO("locationstr=%s\n",locationstr);
  10421. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  10422. int ftppathlen=strlen(ftpbuf);
  10423. int i=1;
  10424. char filenametemp[50];
  10425. while(i < ftppathlen)
  10426. {
  10427. int len=ftppathlen-i;
  10428. if(ftpbuf[len]== 47) // '/' ascll code: 47
  10429. {
  10430. DEBUG_INFO(" compare '/' all right\n");
  10431. break;
  10432. }
  10433. i=i+1;
  10434. }
  10435. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10436. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  10437. filenametemp[i+1] = 0;
  10438. strncpy(temp, ftpbuf, ftppathlen-i+1);
  10439. pch=strchr(temp,'@');
  10440. if(pch==NULL)
  10441. {
  10442. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10443. protocol, host, &port, path);
  10444. strcpy(user,"anonymous");
  10445. strcpy(password,"");
  10446. }
  10447. else
  10448. {
  10449. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10450. protocol, user, password, host, &port, path);
  10451. }
  10452. sscanf(host,"%[^/]%s",host1, path1);
  10453. sprintf(ftppath,"%s", path1);
  10454. //DEBUG_INFO("protocol =%s\n",protocol);
  10455. //DEBUG_INFO("user =%s\n",user);
  10456. //DEBUG_INFO("password =%s\n",password);
  10457. //DEBUG_INFO("host1 =%s\n",host1);
  10458. //DEBUG_INFO("port =%d\n",port);
  10459. //DEBUG_INFO("path1 =%s\n",path1);
  10460. //DEBUG_INFO("ftppath=%s\n",ftppath);
  10461. //ftpFile(host, user, password, port, ftppath, fname);
  10462. //download firmware pthred
  10463. if(port == 0)
  10464. {
  10465. port = 21;
  10466. }
  10467. do
  10468. {
  10469. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  10470. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10471. sleep(1);
  10472. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  10473. if(!isSuccess)
  10474. {
  10475. //BulldogUtil.sleepMs(interval*1000);
  10476. DEBUG_INFO("Update firmware request and download file fail.\n");
  10477. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10478. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10479. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  10480. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10481. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10482. }
  10483. else
  10484. {
  10485. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10486. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10487. }
  10488. retriesInt--;
  10489. }while((!isSuccess)&&(retriesInt >= 0));
  10490. }
  10491. else
  10492. {
  10493. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10494. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10495. sleep(1);
  10496. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10497. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10498. }
  10499. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  10500. pthread_exit(NULL);
  10501. }
  10502. int handleCertificateSignedRequest(char *uuid, char *payload)
  10503. {
  10504. mtrace();
  10505. int result = PASS;
  10506. json_object *CertificateSigned;
  10507. DEBUG_INFO("handleCertificateSignedRequest...\n");
  10508. CertificateSigned = json_tokener_parse(payload);
  10509. if(!is_error(CertificateSigned))
  10510. {
  10511. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  10512. }
  10513. json_object_put(CertificateSigned);
  10514. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  10515. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  10516. fclose(fp);
  10517. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10518. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  10519. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  10520. sendCertificateSignedConfirmation(uuid);
  10521. return result;
  10522. }
  10523. int handleDeleteCertificateRequest(char *uuid, char *payload)
  10524. {
  10525. mtrace();
  10526. int result = PASS;
  10527. json_object *DeleteCertificate;
  10528. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  10529. DeleteCertificate = json_tokener_parse(payload);
  10530. if(!is_error(DeleteCertificate))
  10531. {
  10532. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  10533. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  10534. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  10535. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  10536. }
  10537. json_object_put(DeleteCertificate);
  10538. /*
  10539. * TODO: Delete certificateSigned process
  10540. */
  10541. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  10542. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  10543. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  10544. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  10545. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  10546. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  10547. sendDeleteCertificateConfirmation(uuid);
  10548. return result;
  10549. }
  10550. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  10551. {
  10552. mtrace();
  10553. int result = PASS;
  10554. json_object *ExtendedTriggerMessage;
  10555. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  10556. ExtendedTriggerMessage = json_tokener_parse(payload);
  10557. if(!is_error(ExtendedTriggerMessage))
  10558. {
  10559. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  10560. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  10561. {
  10562. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  10563. }
  10564. else
  10565. {
  10566. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  10567. }
  10568. }
  10569. json_object_put(ExtendedTriggerMessage);
  10570. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  10571. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  10572. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  10573. {
  10574. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  10575. }
  10576. else
  10577. {
  10578. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  10579. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  10580. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10581. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  10582. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  10583. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  10584. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  10585. {
  10586. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10587. }
  10588. else
  10589. {
  10590. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10591. }
  10592. }
  10593. sendExtendedTriggerMessageConfirmation(uuid);
  10594. //==========================
  10595. // Trigger message
  10596. //==========================
  10597. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  10598. {
  10599. //sendBootNotificationRequest();
  10600. server_sign = FALSE;
  10601. }
  10602. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  10603. {
  10604. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  10605. }
  10606. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10607. {
  10608. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  10609. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  10610. {
  10611. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10612. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  10613. }
  10614. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10615. }
  10616. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  10617. {
  10618. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  10619. }
  10620. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  10621. {
  10622. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  10623. {
  10624. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  10625. }
  10626. else
  10627. {
  10628. for(int idx=0;idx< gunTotalNumber;idx++)
  10629. {
  10630. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10631. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10632. }
  10633. }
  10634. }
  10635. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  10636. {
  10637. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  10638. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  10639. {
  10640. system("openssl req -newkey rsa:2048 -out /Storage/OCPP/certCP.csr -nodes -keyout /Storage/OCPP/certCP.key -subj \"/C=TW/ST=Taiwan/L=Taoyuan/O=Phihong Technology/OU=IT/CN=phihong.com\" &");
  10641. }
  10642. }
  10643. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  10644. {
  10645. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  10646. {
  10647. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  10648. }
  10649. else
  10650. {
  10651. for(int idx=0;idx< gunTotalNumber;idx++)
  10652. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  10653. }
  10654. }
  10655. return result;
  10656. }
  10657. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  10658. {
  10659. mtrace();
  10660. int result = PASS;
  10661. json_object *GetInstalledCertificateIds;
  10662. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  10663. GetInstalledCertificateIds = json_tokener_parse(payload);
  10664. if(!is_error(GetInstalledCertificateIds))
  10665. {
  10666. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  10667. }
  10668. json_object_put(GetInstalledCertificateIds);
  10669. /*
  10670. * TODO: Return installed certificate process
  10671. */
  10672. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  10673. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  10674. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  10675. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  10676. sendGetInstalledCertificateIdsConfirmation(uuid);
  10677. return result;
  10678. }
  10679. int handleGetLogRequest(char *uuid, char *payload)
  10680. {
  10681. mtrace();
  10682. int result = PASS;
  10683. json_object *GetLog;
  10684. DEBUG_INFO("handleGetLogRequest...\n");
  10685. GetLog = json_tokener_parse(payload);
  10686. if(!is_error(GetLog))
  10687. {
  10688. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  10689. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  10690. if(json_object_object_get(GetLog, "retries") != NULL)
  10691. {
  10692. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  10693. }
  10694. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  10695. {
  10696. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  10697. }
  10698. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  10699. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  10700. {
  10701. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  10702. }
  10703. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  10704. {
  10705. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  10706. }
  10707. }
  10708. json_object_put(GetLog);
  10709. /*
  10710. * TODO: Upload log process
  10711. */
  10712. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  10713. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  10714. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  10715. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  10716. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  10717. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  10718. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  10719. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  10720. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  10721. sendGetLogConfirmation(uuid);
  10722. return result;
  10723. }
  10724. int handleInstallCertificateRequest(char *uuid, char *payload)
  10725. {
  10726. mtrace();
  10727. int result = PASS;
  10728. json_object *InstallCertificate;
  10729. DEBUG_INFO("handleInstallCertificateRequest...\n");
  10730. InstallCertificate = json_tokener_parse(payload);
  10731. if(!is_error(InstallCertificate))
  10732. {
  10733. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  10734. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  10735. /*
  10736. * TODO: Install certificate process
  10737. */
  10738. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  10739. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  10740. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  10741. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  10742. sendInstallCertificateConfirmation(uuid);
  10743. }
  10744. json_object_put(InstallCertificate);
  10745. return result;
  10746. }
  10747. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  10748. {
  10749. mtrace();
  10750. int result = PASS;
  10751. json_object *SignedUpdateFirmware;
  10752. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  10753. SignedUpdateFirmware = json_tokener_parse(payload);
  10754. if(!is_error(SignedUpdateFirmware))
  10755. {
  10756. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  10757. {
  10758. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  10759. }
  10760. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  10761. {
  10762. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  10763. }
  10764. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  10765. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  10766. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  10767. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  10768. {
  10769. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  10770. }
  10771. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  10772. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  10773. }
  10774. json_object_put(SignedUpdateFirmware);
  10775. /*
  10776. * TODO: Upgrade firmware process
  10777. */
  10778. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  10779. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  10780. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  10781. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  10782. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  10783. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  10784. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  10785. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  10786. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  10787. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  10788. sendInstallCertificateConfirmation(uuid);
  10789. return result;
  10790. }
  10791. int handleUnknownRequest(char *uuid, char *payload)
  10792. {
  10793. mtrace();
  10794. int result = PASS;
  10795. DEBUG_INFO("handleUnknownRequest...\n");
  10796. sendUnknownConfirmation(uuid);
  10797. result = PASS;
  10798. return result;
  10799. }
  10800. //==========================================
  10801. // Handle server response routine
  10802. //==========================================
  10803. void handleAuthorizeResponse(char *payload, int gun_index)
  10804. {
  10805. mtrace();
  10806. char expiryDatestr[30]={0};
  10807. char parentIdTagstr[20]={0};
  10808. char statusstr[20]={0};
  10809. int expiryDateISNULL=FALSE;
  10810. int parentIdTagISNULL=FALSE;
  10811. DEBUG_INFO("handleAuthorizeResponse...\n");
  10812. json_object *Authorize;
  10813. Authorize = json_tokener_parse(payload);
  10814. if(!is_error(Authorize))
  10815. {
  10816. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  10817. {
  10818. // Required data
  10819. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  10820. // Optional data
  10821. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  10822. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  10823. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  10824. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  10825. }
  10826. }
  10827. json_object_put(Authorize);
  10828. if(expiryDateISNULL == FALSE)
  10829. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  10830. if(parentIdTagISNULL == FALSE)
  10831. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  10832. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  10833. //Update idTag information to authorization cache if supproted
  10834. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  10835. {
  10836. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  10837. }
  10838. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  10839. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  10840. authorizeRetryTimes = 0;
  10841. }
  10842. void handleBootNotificationResponse(char *payload, int gun_index)
  10843. {
  10844. mtrace();
  10845. char statusStr[12]={0};
  10846. char currentTimeStr[30]={0};
  10847. int intervalInt = 0;
  10848. DEBUG_INFO("handleBootNotificationResponse...\n");
  10849. json_object *BootNotification;
  10850. BootNotification = json_tokener_parse(payload);
  10851. if(!is_error(BootNotification))
  10852. {
  10853. // Required data
  10854. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  10855. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  10856. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  10857. }
  10858. json_object_put(BootNotification);
  10859. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10860. BootNotificationInterval = intervalInt;
  10861. HeartBeatWaitTime = intervalInt;
  10862. //write back to ShmOCPP16Data->BootNotification
  10863. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  10864. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10865. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  10866. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  10867. {
  10868. server_sign = TRUE;
  10869. server_pending =FALSE;
  10870. }
  10871. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  10872. {
  10873. server_pending = TRUE;
  10874. }
  10875. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  10876. srand(time(NULL));
  10877. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  10878. SetOcppConnStatus(TRUE);
  10879. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  10880. }
  10881. void handleDataTransferResponse(char *payload, int gun_index)
  10882. {
  10883. char sstr[160]={0};//sstr[200]={ 0 };
  10884. int c = 0;
  10885. char *loc;
  10886. DEBUG_INFO("handleDataTransferResponse ...\n");
  10887. loc = strstr(payload, "status");
  10888. printf("loc=%s\n",loc);
  10889. c = 0;
  10890. while (loc[3+strlen("status")+c] != '\"')
  10891. {
  10892. sstr[c] = loc[3+strlen("status")+c];
  10893. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10894. c++;
  10895. }
  10896. sstr[c] = '\0';
  10897. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  10898. }
  10899. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  10900. {
  10901. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  10902. //struct json_object *obj;
  10903. // obj = json_tokener_parse(payload);
  10904. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  10905. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  10906. //No fields are defined.
  10907. }
  10908. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  10909. {
  10910. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  10911. //struct json_object *obj;
  10912. // obj = json_tokener_parse(payload);
  10913. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  10914. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  10915. //No fields are defined.
  10916. }
  10917. void handleHeartbeatResponse(char *payload, int gun_index)
  10918. {
  10919. mtrace();
  10920. DEBUG_INFO("handleHeartbeatResponse...\n");
  10921. json_object *Heartbeat;
  10922. Heartbeat = json_tokener_parse(payload);
  10923. if(!is_error(Heartbeat))
  10924. {
  10925. // Required data
  10926. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  10927. }
  10928. json_object_put(Heartbeat);
  10929. if(FirstHeartBeat == 0)
  10930. {
  10931. FirstHeartBeat = 1;
  10932. DEBUG_INFO("FirstHeartBeat \n");
  10933. }
  10934. HeartBeatWithNOResponse = 0;
  10935. clientTime.Heartbeat=time((time_t*)NULL);
  10936. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  10937. }
  10938. void handleMeterValuesResponse(char *payload, int gun_index)
  10939. {
  10940. mtrace();
  10941. DEBUG_INFO("handleMeterValuesResponse...\n");
  10942. }
  10943. void handleStartTransactionResponse(char *payload, int gun_index)
  10944. {
  10945. mtrace();
  10946. //int transactionIdInt = 0;
  10947. FILE *outfile;
  10948. char data[100]={0};
  10949. DEBUG_INFO("handleStartTransactionResponse...\n");
  10950. json_object *StartTransaction;
  10951. StartTransaction = json_tokener_parse(payload);
  10952. if(!is_error(StartTransaction))
  10953. {
  10954. // Required data
  10955. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  10956. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  10957. // Optional data
  10958. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  10959. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  10960. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10961. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  10962. }
  10963. json_object_put(StartTransaction);
  10964. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  10965. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  10966. //-----------Start : write to the Queue TransactionId file -----------------//
  10967. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  10968. {}
  10969. else
  10970. {
  10971. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  10972. if(log == NULL)
  10973. {
  10974. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  10975. return ;
  10976. }
  10977. else
  10978. {
  10979. fclose(log);
  10980. }
  10981. }
  10982. // open file for writing
  10983. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  10984. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  10985. {
  10986. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  10987. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  10988. fputs(data, outfile);
  10989. fclose (outfile);
  10990. }
  10991. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10992. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10993. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  10994. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  10995. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10996. }
  10997. void handleStatusNotificationResponse(char *payload, int gun_index)
  10998. {
  10999. mtrace();
  11000. DEBUG_INFO("handleStatusNotificationResponse...\n");
  11001. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  11002. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  11003. }
  11004. void handleStopTransactionnResponse(char *payload, int gun_index)
  11005. {
  11006. mtrace();
  11007. DEBUG_INFO("handleStopTransactionnResponse...\n");
  11008. json_object *StopTransaction;
  11009. StopTransaction = json_tokener_parse(payload);
  11010. if(!is_error(StopTransaction))
  11011. {
  11012. // Optional data
  11013. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  11014. {
  11015. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  11016. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  11017. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  11018. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11019. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  11020. }
  11021. }
  11022. json_object_put(StopTransaction);
  11023. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  11024. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  11025. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11026. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11027. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  11028. }
  11029. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  11030. {
  11031. mtrace();
  11032. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  11033. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  11034. }
  11035. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  11036. {
  11037. mtrace();
  11038. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  11039. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  11040. }
  11041. void handleSignCertificateResponse(char *payload, int gun_index)
  11042. {
  11043. mtrace();
  11044. DEBUG_INFO("handleSignCertificateResponse...\n");
  11045. json_object *SignCertificate;
  11046. SignCertificate = json_tokener_parse(payload);
  11047. if(!is_error(SignCertificate))
  11048. {
  11049. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  11050. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  11051. }
  11052. json_object_put(SignCertificate);
  11053. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  11054. }
  11055. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11056. {
  11057. mtrace();
  11058. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  11059. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  11060. }
  11061. //==========================================
  11062. // Handle Error routine
  11063. //==========================================
  11064. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  11065. {
  11066. mtrace();
  11067. #ifdef SystemLogMessage
  11068. DEBUG_INFO("errorCode: %s\n", errorCode);
  11069. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  11070. DEBUG_INFO("errorDetails: %s\n", payload);
  11071. #endif
  11072. }
  11073. //===============================================
  11074. // Common routine
  11075. //===============================================
  11076. int initialConfigurationTable(void)
  11077. {
  11078. //clock_t start_t, end_t, total_t;
  11079. FILE *fp;
  11080. FILE *outfile;
  11081. char str[512]={0};
  11082. char sstr[256]={0};
  11083. int c = 0;
  11084. char *loc;
  11085. int confVersion = 2;
  11086. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  11087. //start_t = clock();
  11088. //printf("Starting of the program, start_t = %ld\n", start_t);
  11089. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  11090. // Check configuration file size is correct
  11091. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  11092. {
  11093. struct stat st;
  11094. stat("/Storage/OCPP/OCPPConfiguration", &st);
  11095. if(st.st_size < 3100)
  11096. {
  11097. system("rm -f /Storage/OCPP/OCPPConfiguration");
  11098. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  11099. }
  11100. }
  11101. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  11102. {
  11103. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  11104. if(outfile == NULL)
  11105. {
  11106. DEBUG_INFO("Error opening file\n");
  11107. return FALSE;
  11108. }
  11109. /*Core Profile*/
  11110. //AllowOfflineTxForUnknownId
  11111. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  11114. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11115. //AuthorizationCacheEnabled
  11116. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11117. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11119. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11120. //AuthorizeRemoteTxRequests
  11121. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11122. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11123. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  11124. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11125. //BlinkRepeat
  11126. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11127. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11128. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11129. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11130. //ClockAlignedDataInterval
  11131. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11132. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11134. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11135. //ConnectionTimeOut
  11136. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11137. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11138. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11139. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11140. //GetConfigurationMaxKeys
  11141. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11142. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11143. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  11144. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11145. // HeartbeatInterval
  11146. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11148. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  11149. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11150. // LightIntensity
  11151. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11152. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11153. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11154. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11155. // LocalAuthorizeOffline
  11156. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  11157. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11158. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11159. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11160. // LocalPreAuthorize
  11161. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  11162. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11163. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11164. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11165. // MaxEnergyOnInvalidId
  11166. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11167. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  11168. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  11169. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  11170. // MeterValuesAlignedData
  11171. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  11172. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  11173. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11174. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11175. else
  11176. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11177. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  11178. // MeterValuesAlignedDataMaxLength
  11179. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  11180. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  11181. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11182. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  11183. else
  11184. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "9" );
  11185. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  11186. // MeterValuesSampledData
  11187. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  11188. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  11189. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11190. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11191. else
  11192. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11193. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  11194. // MeterValuesSampledDataMaxLength
  11195. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  11196. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  11197. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11198. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  11199. else
  11200. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "9" );
  11201. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  11202. // MeterValueSampleInterval
  11203. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  11204. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  11205. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  11206. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  11207. // MinimumStatusDuration
  11208. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  11209. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  11210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  11211. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  11212. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  11213. // NumberOfConnectors
  11214. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  11215. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  11216. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11217. {
  11218. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  11219. }
  11220. else
  11221. {
  11222. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  11223. }
  11224. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  11225. // ResetRetries
  11226. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  11227. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  11228. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  11229. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  11230. // ConnectorPhaseRotation
  11231. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  11232. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  11233. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  11234. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  11235. // ConnectorPhaseRotationMaxLength
  11236. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  11237. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  11238. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  11239. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  11240. // StopTransactionOnEVSideDisconnect
  11241. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  11242. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  11243. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  11244. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  11245. // StopTransactionOnInvalidId
  11246. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  11247. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  11248. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  11249. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  11250. // StopTxnAlignedData
  11251. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  11252. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  11253. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  11254. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  11255. // StopTxnAlignedDataMaxLength
  11256. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  11257. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  11258. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11259. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11260. // StopTxnSampledData
  11261. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11262. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11263. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11264. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11265. else
  11266. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11267. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11268. // StopTxnSampledDataMaxLength
  11269. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11270. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11271. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11272. {
  11273. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  11274. }
  11275. else
  11276. {
  11277. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  11278. }
  11279. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11280. // SupportedFeatureProfiles
  11281. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11282. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11283. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11284. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  11285. // SupportedFeatureProfilesMaxLength
  11286. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  11287. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  11288. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  11289. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  11290. // TransactionMessageAttempts
  11291. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11292. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11293. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11294. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11295. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11296. // TransactionMessageRetryInterval
  11297. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11298. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11299. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11300. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11301. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11302. // UnlockConnectorOnEVSideDisconnect
  11303. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11304. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11305. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11306. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11307. // WebSocketPingInterval
  11308. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11309. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11311. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11312. // QueueOffLineStartTransactionMessage
  11313. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  11314. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  11315. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  11316. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  11317. // AuthorizationKey
  11318. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  11319. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  11320. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "" );
  11321. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  11322. // SecurityProfile
  11323. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  11324. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  11325. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "0" );
  11326. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  11327. // DefaultPrice
  11328. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  11329. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  11330. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  11331. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  11332. // CustomDisplayCostAndPrice
  11333. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  11334. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  11335. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  11336. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  11337. // CustomIdleFeeAfterStop
  11338. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  11339. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  11340. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  11341. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  11342. // Configuration Version
  11343. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  11344. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  11345. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  11346. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  11347. //* Local Auth List Management Profile*/
  11348. #if 0
  11349. //For OCTT Test Case
  11350. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11351. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  11352. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11353. #endif
  11354. #if 1
  11355. //LocalAuthListEnabled
  11356. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11357. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  11358. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11359. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11360. #endif
  11361. //LocalAuthListMaxLength
  11362. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  11363. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  11364. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  11365. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  11366. //SendLocalListMaxLength
  11367. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  11368. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11369. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  11370. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11371. //ReserveConnectorZeroSupported
  11372. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11373. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11374. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11375. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11376. //* Smart Charging Profile */
  11377. //ChargeProfileMaxStackLevel
  11378. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11379. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11380. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11381. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11382. // ChargingScheduleAllowedChargingRateUnit
  11383. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11384. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11385. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  11386. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11387. // ChargingScheduleMaxPeriods
  11388. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11389. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11390. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11391. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11392. // ConnectorSwitch3to1PhaseSupported
  11393. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11394. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11395. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  11396. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11397. // MaxChargingProfilesInstalled
  11398. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11399. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11400. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  11401. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11402. fclose(outfile);
  11403. }
  11404. else
  11405. {
  11406. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  11407. char keystr[60]={0};
  11408. char readonlystr[10]={0};
  11409. char valuestr[256]={0};
  11410. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  11411. if(fp == NULL) {
  11412. DEBUG_INFO("Error opening file");
  11413. return FALSE;
  11414. }
  11415. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  11416. {
  11417. //DEBUG_INFO("Get Configuration \n");
  11418. if(strlen(str) > 0)
  11419. {
  11420. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  11421. //*************************key*********************************/
  11422. if(strstr(str, "key") != NULL)
  11423. {
  11424. loc = strstr(str, "key");
  11425. c = 0;
  11426. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11427. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  11428. {
  11429. sstr[c] = loc[strlen("key")+3+c];
  11430. c++;
  11431. }
  11432. sstr[c] = '\0';
  11433. strcpy(keystr,sstr);
  11434. }
  11435. //*************************readonly*********************************/
  11436. if(strstr(str, "readonly") != NULL)
  11437. {
  11438. loc = strstr(str, "readonly");
  11439. c = 0;
  11440. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11441. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  11442. {
  11443. sstr[c] = loc[strlen("readonly")+2+c];
  11444. c++;
  11445. }
  11446. sstr[c] = '\0';
  11447. strcpy(readonlystr,sstr);
  11448. }
  11449. //*************************value*********************************/
  11450. if(strstr(str, "value") != NULL)
  11451. {
  11452. loc = strstr(str, "value");
  11453. c = 0;
  11454. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11455. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  11456. {
  11457. sstr[c] = loc[strlen("value")+3+c];
  11458. c++;
  11459. }
  11460. sstr[c] = '\0';
  11461. strcpy(valuestr,sstr);
  11462. }
  11463. // DEBUG_INFO("keystr=%s\n",keystr);
  11464. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  11465. // DEBUG_INFO("valuestr=%s\n",valuestr);
  11466. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  11467. {
  11468. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11469. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11470. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  11471. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  11472. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  11473. }
  11474. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  11475. {
  11476. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11477. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11478. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  11479. }
  11480. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  11481. {
  11482. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11483. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  11484. }
  11485. if(strcmp(keystr, "BlinkRepeat") == 0)
  11486. {
  11487. //Charger.BlinkRepeat = Integer.parseInt(value);
  11488. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11489. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  11490. }
  11491. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  11492. {
  11493. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11494. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  11495. }
  11496. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  11497. {
  11498. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11499. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  11500. }
  11501. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  11502. {
  11503. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11504. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  11505. }
  11506. if(strcmp(keystr, "HeartbeatInterval") == 0)
  11507. {
  11508. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11509. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  11510. HeartBeatWaitTime = atoi(valuestr);
  11511. }
  11512. if(strcmp(keystr, "LightIntensity") == 0)
  11513. {
  11514. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11515. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  11516. }
  11517. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  11518. {
  11519. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11520. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  11521. }
  11522. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  11523. {
  11524. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11525. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  11526. }
  11527. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  11528. {
  11529. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11530. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  11531. }
  11532. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  11533. {
  11534. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11535. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  11536. }
  11537. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  11538. {
  11539. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11540. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  11541. }
  11542. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  11543. {
  11544. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11545. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  11546. }
  11547. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  11548. {
  11549. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11550. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  11551. }
  11552. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  11553. {
  11554. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11555. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  11556. }
  11557. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  11558. {
  11559. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11560. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  11561. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  11562. }
  11563. if(strcmp(keystr, "NumberOfConnectors") == 0)
  11564. {
  11565. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11566. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  11567. }
  11568. if(strcmp(keystr, "ResetRetries") == 0)
  11569. {
  11570. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11571. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  11572. }
  11573. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  11574. {
  11575. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11576. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  11577. }
  11578. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  11579. {
  11580. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11581. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  11582. }
  11583. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  11584. {
  11585. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11586. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  11587. }
  11588. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  11589. {
  11590. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11591. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  11592. }
  11593. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  11594. {
  11595. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11596. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  11597. }
  11598. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  11599. {
  11600. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11601. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11602. }
  11603. if(strcmp(keystr, "StopTxnSampledData") == 0)
  11604. {
  11605. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11606. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  11607. }
  11608. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  11609. {
  11610. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11611. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11612. }
  11613. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  11614. {
  11615. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11616. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  11617. }
  11618. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  11619. {
  11620. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11621. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  11622. }
  11623. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  11624. {
  11625. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11626. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  11627. TransactionMessageAttemptsValue = atoi(valuestr);
  11628. }
  11629. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  11630. {
  11631. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11632. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  11633. TransactionMessageRetryIntervalValue = atoi(valuestr);
  11634. }
  11635. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  11636. {
  11637. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11638. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  11639. }
  11640. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  11641. {
  11642. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11643. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  11644. }
  11645. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  11646. {
  11647. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11648. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  11649. }
  11650. if(strcmp(keystr, "AuthorizationKey") == 0)
  11651. {
  11652. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11653. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  11654. }
  11655. if(strcmp(keystr, "SecurityProfile") == 0)
  11656. {
  11657. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11658. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  11659. }
  11660. if(strcmp(keystr, "DefaultPrice") == 0)
  11661. {
  11662. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11663. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  11664. }
  11665. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  11666. {
  11667. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11668. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  11669. }
  11670. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  11671. {
  11672. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11673. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  11674. }
  11675. if(strcmp(keystr, "ConfigurationVersion") == 0)
  11676. {
  11677. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11678. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  11679. }
  11680. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  11681. {
  11682. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11683. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  11684. }
  11685. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  11686. {
  11687. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11688. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  11689. }
  11690. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  11691. {
  11692. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11693. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  11694. }
  11695. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  11696. {
  11697. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11698. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  11699. }
  11700. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  11701. {
  11702. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11703. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  11704. }
  11705. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  11706. {
  11707. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11708. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  11709. }
  11710. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  11711. {
  11712. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11713. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  11714. }
  11715. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  11716. {
  11717. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11718. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  11719. }
  11720. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  11721. {
  11722. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11723. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  11724. }
  11725. }
  11726. }
  11727. fclose(fp);
  11728. }
  11729. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  11730. {
  11731. return PASS;
  11732. }
  11733. else
  11734. {
  11735. return FAIL;
  11736. }
  11737. }
  11738. void StoreConfigurationTable(void)
  11739. {
  11740. FILE *outfile;
  11741. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  11742. if(outfile == NULL)
  11743. {
  11744. DEBUG_INFO("Error opening file");
  11745. return ;
  11746. }
  11747. /*Core Profile*/
  11748. //AllowOfflineTxForUnknownId
  11749. /*
  11750. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11751. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  11752. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11753. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  11754. */
  11755. //DEBUG_INFO("data=%s\n",data);
  11756. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11757. //AuthorizationCacheEnabled
  11758. /*
  11759. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11760. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11761. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11762. */
  11763. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11764. //AuthorizeRemoteTxRequests
  11765. /*
  11766. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11767. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11768. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  11769. */
  11770. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11771. //BlinkRepeat
  11772. /*
  11773. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11775. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11776. */
  11777. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11778. //ClockAlignedDataInterval
  11779. /*
  11780. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11781. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11782. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11783. */
  11784. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11785. //ConnectionTimeOut
  11786. /*
  11787. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11789. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11790. */
  11791. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11792. //GetConfigurationMaxKeys
  11793. /*
  11794. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11796. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  11797. */
  11798. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11799. // HeartbeatInterval
  11800. /*
  11801. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  11804. */
  11805. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11806. // LightIntensity
  11807. /*
  11808. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11810. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11811. */
  11812. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11813. // LocalAuthorizeOffline
  11814. /*
  11815. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  11816. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11818. */
  11819. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11820. // LocalPreAuthorize
  11821. /*
  11822. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  11823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11825. */
  11826. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11827. // MaxEnergyOnInvalidId
  11828. /*
  11829. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11830. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  11831. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  11832. */
  11833. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  11834. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  11835. // MeterValuesAlignedData
  11836. /*
  11837. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  11838. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  11839. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  11840. */
  11841. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  11842. // MeterValuesAlignedDataMaxLength
  11843. /*
  11844. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  11845. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  11846. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  11847. */
  11848. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  11849. // MeterValuesSampledData
  11850. /*
  11851. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  11852. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  11853. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  11854. */
  11855. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  11856. // MeterValuesSampledDataMaxLength
  11857. /*
  11858. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  11859. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  11860. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  11861. */
  11862. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  11863. // MeterValueSampleInterval
  11864. /*
  11865. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  11866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  11867. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  11868. */
  11869. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  11870. // MinimumStatusDuration
  11871. /*
  11872. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  11873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  11874. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  11875. */
  11876. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  11877. // NumberOfConnectors
  11878. /*
  11879. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  11880. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  11881. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11882. {
  11883. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  11884. }
  11885. else
  11886. {
  11887. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  11888. }
  11889. */
  11890. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  11891. // ResetRetries
  11892. /*
  11893. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  11894. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  11895. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  11896. */
  11897. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  11898. // ConnectorPhaseRotation
  11899. /*
  11900. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  11901. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  11902. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  11903. */
  11904. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  11905. // ConnectorPhaseRotationMaxLength
  11906. /*
  11907. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  11908. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  11909. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  11910. */
  11911. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  11912. // StopTransactionOnEVSideDisconnect
  11913. /*
  11914. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  11915. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  11916. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  11917. */
  11918. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  11919. // StopTransactionOnInvalidId
  11920. /*
  11921. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  11922. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  11923. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  11924. */
  11925. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  11926. // StopTxnAlignedData
  11927. /*
  11928. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  11929. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  11930. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  11931. */
  11932. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  11933. // StopTxnAlignedDataMaxLength
  11934. /*
  11935. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  11936. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  11937. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11938. */
  11939. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11940. // StopTxnSampledData
  11941. /*
  11942. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11943. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11944. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  11945. */
  11946. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11947. // StopTxnSampledDataMaxLength
  11948. /*
  11949. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11950. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11951. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  11952. */
  11953. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11954. // SupportedFeatureProfiles
  11955. /*
  11956. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11957. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11958. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11959. */
  11960. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  11961. // SupportedFeatureProfilesMaxLength
  11962. /*
  11963. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  11964. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  11965. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  11966. */
  11967. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  11968. // TransactionMessageAttempts
  11969. /*
  11970. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11971. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11972. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11973. */
  11974. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11975. // TransactionMessageRetryInterval
  11976. /*
  11977. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11978. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11979. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11980. */
  11981. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11982. // UnlockConnectorOnEVSideDisconnect
  11983. /*
  11984. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11985. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11986. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11987. */
  11988. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11989. // WebSocketPingInterval
  11990. /*
  11991. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11992. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11993. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11994. */
  11995. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11996. // QueueOffLineStartTransactionMessage
  11997. /*
  11998. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  11999. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  12000. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  12001. */
  12002. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  12003. // AuthorizationKey
  12004. /*
  12005. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12006. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12007. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  12008. */
  12009. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12010. // SecurityProfile
  12011. /*
  12012. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12013. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12014. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  12015. */
  12016. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12017. // DefaultPrice
  12018. /*
  12019. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12020. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12021. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12022. */
  12023. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12024. // CustomDisplayCostAndPrice
  12025. /*
  12026. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12027. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12028. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12029. */
  12030. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12031. // CustomIdleFeeAfterStop
  12032. /*
  12033. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12034. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12035. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12036. */
  12037. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12038. // ConfigurationVersion
  12039. /*
  12040. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  12041. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12042. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  12043. */
  12044. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12045. //* Local Auth List Management Profile*/
  12046. //LocalAuthListEnabled
  12047. /*
  12048. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12049. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12050. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12051. */
  12052. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12053. //LocalAuthListMaxLength
  12054. /*
  12055. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12056. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12057. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  12058. */
  12059. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12060. //SendLocalListMaxLength
  12061. /*
  12062. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12063. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12064. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  12065. */
  12066. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12067. //ReserveConnectorZeroSupported
  12068. /*
  12069. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12070. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12071. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12072. */
  12073. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12074. //* Smart Charging Profile */
  12075. //ChargeProfileMaxStackLevel
  12076. /*
  12077. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12078. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12079. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12080. */
  12081. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12082. // ChargingScheduleAllowedChargingRateUnit
  12083. /*
  12084. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12085. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12086. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  12087. */
  12088. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12089. // ChargingScheduleMaxPeriods
  12090. /*
  12091. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12092. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12093. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12094. */
  12095. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12096. // ConnectorSwitch3to1PhaseSupported
  12097. /*
  12098. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12100. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  12101. */
  12102. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12103. // MaxChargingProfilesInstalled
  12104. /*
  12105. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12106. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12107. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12108. */
  12109. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12110. fclose(outfile);
  12111. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12112. }
  12113. void getKeyValue(char *keyReq)
  12114. {
  12115. int isEmpty = FALSE;
  12116. int isKnowKey = FALSE;
  12117. DEBUG_INFO("keyReq = %s\n", keyReq);
  12118. if((keyReq == NULL) || (strlen(keyReq) == 0))
  12119. isEmpty = TRUE;
  12120. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  12121. {
  12122. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  12123. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  12124. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  12125. {
  12126. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  12127. }
  12128. else
  12129. {
  12130. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  12131. }
  12132. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  12133. isKnowKey = TRUE;
  12134. }
  12135. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  12136. {
  12137. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  12138. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  12139. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  12140. {
  12141. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  12142. }
  12143. else
  12144. {
  12145. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  12146. }
  12147. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  12148. isKnowKey = TRUE;
  12149. }
  12150. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  12151. {
  12152. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  12153. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  12154. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  12155. {
  12156. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  12157. }
  12158. else
  12159. {
  12160. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  12161. }
  12162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  12163. isKnowKey = TRUE;
  12164. }
  12165. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  12166. {
  12167. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  12168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  12169. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  12170. {
  12171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  12172. }
  12173. else
  12174. {
  12175. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  12176. }
  12177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  12178. isKnowKey = TRUE;
  12179. }
  12180. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  12181. {
  12182. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  12183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  12184. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  12185. {
  12186. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  12187. }
  12188. else
  12189. {
  12190. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  12191. }
  12192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  12193. isKnowKey = TRUE;
  12194. }
  12195. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  12196. {
  12197. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  12198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  12199. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  12200. {
  12201. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  12202. }
  12203. else
  12204. {
  12205. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  12206. }
  12207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  12208. isKnowKey = TRUE;
  12209. }
  12210. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  12211. {
  12212. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  12213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  12214. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  12215. {
  12216. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  12217. }
  12218. else
  12219. {
  12220. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  12221. }
  12222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  12223. isKnowKey = TRUE;
  12224. }
  12225. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  12226. {
  12227. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  12228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  12229. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  12230. {
  12231. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  12232. }
  12233. else
  12234. {
  12235. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  12236. }
  12237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  12238. isKnowKey = TRUE;
  12239. }
  12240. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  12241. {
  12242. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  12243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  12244. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  12245. {
  12246. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  12247. }
  12248. else
  12249. {
  12250. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  12251. }
  12252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  12253. isKnowKey = TRUE;
  12254. }
  12255. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  12256. {
  12257. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  12258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  12259. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  12260. {
  12261. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  12262. }
  12263. else
  12264. {
  12265. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  12266. }
  12267. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  12268. isKnowKey = TRUE;
  12269. }
  12270. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  12271. {
  12272. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  12273. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  12274. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12275. {
  12276. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  12277. }
  12278. else
  12279. {
  12280. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  12281. }
  12282. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  12283. isKnowKey = TRUE;
  12284. }
  12285. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  12286. {
  12287. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  12288. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  12289. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  12290. {
  12291. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  12292. }
  12293. else
  12294. {
  12295. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  12296. }
  12297. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  12298. isKnowKey = TRUE;
  12299. }
  12300. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  12301. {
  12302. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  12303. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  12304. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12305. {
  12306. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  12307. }
  12308. else
  12309. {
  12310. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  12311. }
  12312. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  12313. isKnowKey = TRUE;
  12314. }
  12315. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  12316. {
  12317. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  12318. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  12319. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12320. {
  12321. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12322. }
  12323. else
  12324. {
  12325. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12326. }
  12327. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  12328. isKnowKey = TRUE;
  12329. }
  12330. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  12331. {
  12332. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  12333. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  12334. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12335. {
  12336. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  12337. }
  12338. else
  12339. {
  12340. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  12341. }
  12342. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  12343. isKnowKey = TRUE;
  12344. }
  12345. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  12346. {
  12347. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  12348. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  12349. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12350. {
  12351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12352. }
  12353. else
  12354. {
  12355. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12356. }
  12357. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  12358. isKnowKey = TRUE;
  12359. }
  12360. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  12361. {
  12362. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  12363. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  12364. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12365. {
  12366. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  12367. }
  12368. else
  12369. {
  12370. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  12371. }
  12372. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  12373. isKnowKey = TRUE;
  12374. }
  12375. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  12376. {
  12377. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  12378. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  12379. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12380. {
  12381. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  12382. }
  12383. else
  12384. {
  12385. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  12386. }
  12387. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  12388. isKnowKey = TRUE;
  12389. }
  12390. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  12391. {
  12392. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  12393. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  12394. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12395. {
  12396. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  12397. }
  12398. else
  12399. {
  12400. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  12401. }
  12402. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  12403. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  12404. isKnowKey = TRUE;
  12405. }
  12406. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  12407. {
  12408. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  12409. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  12410. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12411. {
  12412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  12413. }
  12414. else
  12415. {
  12416. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  12417. }
  12418. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  12419. isKnowKey = TRUE;
  12420. }
  12421. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  12422. {
  12423. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  12424. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  12425. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12426. {
  12427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  12428. }
  12429. else
  12430. {
  12431. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  12432. }
  12433. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  12434. isKnowKey = TRUE;
  12435. }
  12436. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  12437. {
  12438. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  12439. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  12440. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12441. {
  12442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12443. }
  12444. else
  12445. {
  12446. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12447. }
  12448. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  12449. isKnowKey = TRUE;
  12450. }
  12451. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  12452. {
  12453. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  12454. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  12455. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12456. {
  12457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  12458. }
  12459. else
  12460. {
  12461. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  12462. }
  12463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  12464. isKnowKey = TRUE;
  12465. }
  12466. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  12467. {
  12468. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  12469. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  12470. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12471. {
  12472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  12473. }
  12474. else
  12475. {
  12476. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  12477. }
  12478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  12479. isKnowKey = TRUE;
  12480. }
  12481. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  12482. {
  12483. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  12484. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  12485. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12486. {
  12487. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  12488. }
  12489. else
  12490. {
  12491. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  12492. }
  12493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  12494. isKnowKey = TRUE;
  12495. }
  12496. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  12497. {
  12498. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  12499. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  12500. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12501. {
  12502. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12503. }
  12504. else
  12505. {
  12506. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12507. }
  12508. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  12509. isKnowKey = TRUE;
  12510. }
  12511. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  12512. {
  12513. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  12514. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  12515. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12516. {
  12517. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  12518. }
  12519. else
  12520. {
  12521. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  12522. }
  12523. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  12524. isKnowKey = TRUE;
  12525. }
  12526. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  12527. {
  12528. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  12529. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  12530. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12531. {
  12532. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12533. }
  12534. else
  12535. {
  12536. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12537. }
  12538. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  12539. isKnowKey = TRUE;
  12540. }
  12541. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  12542. {
  12543. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  12544. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  12545. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12546. {
  12547. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  12548. }
  12549. else
  12550. {
  12551. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  12552. }
  12553. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  12554. isKnowKey = TRUE;
  12555. }
  12556. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  12557. {
  12558. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  12559. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  12560. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12561. {
  12562. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12563. }
  12564. else
  12565. {
  12566. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12567. }
  12568. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  12569. isKnowKey = TRUE;
  12570. }
  12571. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  12572. {
  12573. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  12574. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  12575. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12576. {
  12577. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  12578. }
  12579. else
  12580. {
  12581. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  12582. }
  12583. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  12584. isKnowKey = TRUE;
  12585. }
  12586. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  12587. {
  12588. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  12589. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  12590. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12591. {
  12592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  12593. }
  12594. else
  12595. {
  12596. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  12597. }
  12598. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  12599. isKnowKey = TRUE;
  12600. }
  12601. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  12602. {
  12603. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  12604. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  12605. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12606. {
  12607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  12608. }
  12609. else
  12610. {
  12611. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  12612. }
  12613. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  12614. isKnowKey = TRUE;
  12615. }
  12616. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  12617. {
  12618. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  12619. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  12620. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12621. {
  12622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  12623. }
  12624. else
  12625. {
  12626. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  12627. }
  12628. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  12629. isKnowKey = TRUE;
  12630. }
  12631. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  12632. {
  12633. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  12634. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  12635. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12636. {
  12637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  12638. }
  12639. else
  12640. {
  12641. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  12642. }
  12643. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  12644. isKnowKey = TRUE;
  12645. }
  12646. /*
  12647. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  12648. {
  12649. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  12650. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  12651. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  12652. {
  12653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  12654. }
  12655. else
  12656. {
  12657. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  12658. }
  12659. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  12660. isKnowKey = TRUE;
  12661. }*/
  12662. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  12663. {
  12664. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  12665. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  12666. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  12667. {
  12668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  12669. }
  12670. else
  12671. {
  12672. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  12673. }
  12674. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  12675. isKnowKey = TRUE;
  12676. }
  12677. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  12678. {
  12679. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  12680. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  12681. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  12682. {
  12683. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  12684. }
  12685. else
  12686. {
  12687. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  12688. }
  12689. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  12690. isKnowKey = TRUE;
  12691. }
  12692. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  12693. {
  12694. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  12695. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  12696. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  12697. {
  12698. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  12699. }
  12700. else
  12701. {
  12702. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  12703. }
  12704. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  12705. isKnowKey = TRUE;
  12706. }
  12707. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  12708. {
  12709. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  12710. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  12711. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  12712. {
  12713. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  12714. }
  12715. else
  12716. {
  12717. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  12718. }
  12719. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  12720. isKnowKey = TRUE;
  12721. }
  12722. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  12723. {
  12724. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  12725. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  12726. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  12727. {
  12728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  12729. }
  12730. else
  12731. {
  12732. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  12733. }
  12734. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  12735. isKnowKey = TRUE;
  12736. }
  12737. #if 1
  12738. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  12739. {
  12740. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  12741. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  12742. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12743. {
  12744. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  12745. }
  12746. else
  12747. {
  12748. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  12749. }
  12750. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  12751. isKnowKey = TRUE;
  12752. }
  12753. #endif
  12754. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  12755. {
  12756. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  12757. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  12758. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12759. {
  12760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12761. }
  12762. else
  12763. {
  12764. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12765. }
  12766. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  12767. isKnowKey = TRUE;
  12768. }
  12769. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  12770. {
  12771. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  12772. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  12773. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12774. {
  12775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12776. }
  12777. else
  12778. {
  12779. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12780. }
  12781. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  12782. isKnowKey = TRUE;
  12783. }
  12784. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  12785. {
  12786. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  12787. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  12788. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12789. {
  12790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  12791. }
  12792. else
  12793. {
  12794. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  12795. }
  12796. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12797. isKnowKey = TRUE;
  12798. }
  12799. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  12800. {
  12801. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  12802. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  12803. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12804. {
  12805. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  12806. }
  12807. else
  12808. {
  12809. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  12810. }
  12811. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12812. isKnowKey = TRUE;
  12813. }
  12814. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  12815. {
  12816. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  12817. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  12818. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12819. {
  12820. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  12821. }
  12822. else
  12823. {
  12824. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  12825. }
  12826. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12827. isKnowKey = TRUE;
  12828. }
  12829. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  12830. {
  12831. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  12832. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  12833. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12834. {
  12835. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  12836. }
  12837. else
  12838. {
  12839. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  12840. }
  12841. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12842. isKnowKey = TRUE;
  12843. }
  12844. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  12845. {
  12846. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  12847. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  12848. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12849. {
  12850. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  12851. }
  12852. else
  12853. {
  12854. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  12855. }
  12856. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12857. isKnowKey = TRUE;
  12858. }
  12859. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  12860. {
  12861. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  12862. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  12863. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12864. {
  12865. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  12866. }
  12867. else
  12868. {
  12869. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  12870. }
  12871. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12872. isKnowKey = TRUE;
  12873. }
  12874. //=========================================================
  12875. if(!isEmpty && !isKnowKey)
  12876. {
  12877. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  12878. strcpy(unknownkey[UnknownKeynum], keyReq);
  12879. UnknownKeynum = UnknownKeynum + 1;
  12880. }
  12881. }
  12882. void processUnkownKey(void)
  12883. {
  12884. DEBUG_INFO("processUnkownKey...\n");
  12885. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  12886. for(int index=0; index < UnknownKeynum; index++)
  12887. {
  12888. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  12889. {
  12890. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  12891. }
  12892. }
  12893. }
  12894. int setKeyValue(char *key, char *value)
  12895. {
  12896. int isSuccess = NotSupported;
  12897. int check_ascii=0;
  12898. char str[256]={0};
  12899. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  12900. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  12901. {
  12902. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  12903. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  12904. {
  12905. strcpy(str, (const char*)value);
  12906. for(int i = 0; str[i]; i++){
  12907. str[i] = tolower(str[i]);
  12908. }
  12909. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12910. isSuccess = ConfigurationStatus_Accepted;
  12911. }
  12912. else
  12913. {
  12914. isSuccess = ConfigurationStatus_Rejected;
  12915. }
  12916. }
  12917. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  12918. {
  12919. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  12920. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  12921. {
  12922. strcpy(str, (const char*)value);
  12923. for(int i = 0; str[i]; i++){
  12924. str[i] = tolower(str[i]);
  12925. }
  12926. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12927. isSuccess = ConfigurationStatus_Accepted;
  12928. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  12929. }
  12930. else
  12931. {
  12932. isSuccess = ConfigurationStatus_Rejected;
  12933. }
  12934. }
  12935. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  12936. {
  12937. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  12938. {
  12939. strcpy(str, (const char*)value);
  12940. for(int i = 0; str[i]; i++)
  12941. {
  12942. str[i] = tolower(str[i]);
  12943. }
  12944. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  12945. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12946. isSuccess = ConfigurationStatus_Accepted;
  12947. }
  12948. else
  12949. {
  12950. isSuccess = ConfigurationStatus_Rejected;
  12951. }
  12952. }
  12953. if(strcmp(key, "BlinkRepeat") == 0)
  12954. {
  12955. //Charger.BlinkRepeat = Integer.parseInt(value);
  12956. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  12957. {
  12958. check_ascii = value[0];
  12959. if( (check_ascii < 48) || (check_ascii > 57) )
  12960. {
  12961. isSuccess = ConfigurationStatus_Rejected;
  12962. }
  12963. else
  12964. {
  12965. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  12966. isSuccess = ConfigurationStatus_Accepted;
  12967. }
  12968. }
  12969. else
  12970. {
  12971. isSuccess = ConfigurationStatus_Rejected;
  12972. }
  12973. }
  12974. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  12975. {
  12976. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  12977. {
  12978. check_ascii = value[0];
  12979. if( (check_ascii < 48) || (check_ascii > 57) )
  12980. {
  12981. isSuccess = ConfigurationStatus_Rejected;
  12982. }
  12983. else
  12984. {
  12985. if((atoi(value) == 0) || (atoi(value) >= 10))
  12986. {
  12987. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  12988. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  12989. isSuccess = ConfigurationStatus_Accepted;
  12990. }
  12991. else
  12992. isSuccess = ConfigurationStatus_Rejected;
  12993. }
  12994. }
  12995. else
  12996. {
  12997. isSuccess = ConfigurationStatus_Rejected;
  12998. }
  12999. }
  13000. if(strcmp(key, "ConnectionTimeOut") == 0 )
  13001. {
  13002. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13003. {
  13004. check_ascii = value[0];
  13005. if( (check_ascii < 48) || (check_ascii > 57) )
  13006. {
  13007. isSuccess = ConfigurationStatus_Rejected;
  13008. }
  13009. else
  13010. {
  13011. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  13012. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  13013. isSuccess = ConfigurationStatus_Accepted;
  13014. }
  13015. }
  13016. else
  13017. {
  13018. isSuccess = ConfigurationStatus_Rejected;
  13019. }
  13020. }
  13021. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  13022. {
  13023. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13024. {
  13025. check_ascii = value[0];
  13026. if( (check_ascii < 48) || (check_ascii > 57) )
  13027. {
  13028. isSuccess = ConfigurationStatus_Rejected;
  13029. }
  13030. else
  13031. {
  13032. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13033. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  13034. isSuccess = ConfigurationStatus_Accepted;
  13035. }
  13036. }
  13037. else
  13038. {
  13039. isSuccess = ConfigurationStatus_Rejected;
  13040. }
  13041. }
  13042. if(strcmp(key, "HeartbeatInterval") == 0)
  13043. {
  13044. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13045. {
  13046. check_ascii = value[0];
  13047. if( (check_ascii < 48) || (check_ascii > 57) )
  13048. {
  13049. isSuccess = ConfigurationStatus_Rejected;
  13050. }
  13051. else
  13052. {
  13053. if((atoi(value) == 0) || (atoi(value) >= 10))
  13054. {
  13055. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13056. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  13057. HeartBeatWaitTime = atoi(value);
  13058. isSuccess = ConfigurationStatus_Accepted;
  13059. }
  13060. else
  13061. {
  13062. isSuccess = ConfigurationStatus_Rejected;
  13063. }
  13064. }
  13065. }
  13066. else
  13067. {
  13068. isSuccess = ConfigurationStatus_Rejected;
  13069. }
  13070. }
  13071. if(strcmp(key, "LightIntensity") == 0)
  13072. {
  13073. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13074. {
  13075. check_ascii = value[0];
  13076. if( (check_ascii < 48) || (check_ascii > 57) )
  13077. {
  13078. isSuccess = ConfigurationStatus_Rejected;
  13079. }
  13080. else
  13081. {
  13082. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  13083. isSuccess = ConfigurationStatus_Accepted;
  13084. }
  13085. }
  13086. else
  13087. {
  13088. isSuccess = ConfigurationStatus_Rejected;
  13089. }
  13090. }
  13091. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  13092. {
  13093. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13094. {
  13095. strcpy(str, (const char*)value);
  13096. for(int i = 0; str[i]; i++)
  13097. {
  13098. str[i] = tolower(str[i]);
  13099. }
  13100. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13101. isSuccess = ConfigurationStatus_Accepted;
  13102. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13103. }
  13104. else
  13105. {
  13106. isSuccess = ConfigurationStatus_Rejected;
  13107. }
  13108. }
  13109. if(strcmp(key, "LocalPreAuthorize") == 0)
  13110. {
  13111. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13112. {
  13113. strcpy(str, (const char*)value);
  13114. for(int i = 0; str[i]; i++)
  13115. {
  13116. str[i] = tolower(str[i]);
  13117. }
  13118. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13119. isSuccess = ConfigurationStatus_Accepted;
  13120. }
  13121. else
  13122. {
  13123. isSuccess = ConfigurationStatus_Rejected;
  13124. }
  13125. }
  13126. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  13127. {
  13128. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13129. {
  13130. check_ascii = value[0];
  13131. if( (check_ascii < 48) || (check_ascii > 57) )
  13132. {
  13133. isSuccess = ConfigurationStatus_Rejected;
  13134. }
  13135. else
  13136. {
  13137. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  13138. isSuccess = ConfigurationStatus_Accepted;
  13139. }
  13140. }
  13141. else
  13142. {
  13143. isSuccess = ConfigurationStatus_Rejected;
  13144. }
  13145. }
  13146. if(strcmp(key, "MeterValuesAlignedData") == 0)
  13147. {
  13148. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13149. {
  13150. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  13151. isSuccess = ConfigurationStatus_Accepted;
  13152. }
  13153. else
  13154. {
  13155. isSuccess = ConfigurationStatus_Rejected;
  13156. }
  13157. }
  13158. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  13159. {
  13160. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13161. {
  13162. check_ascii = value[0];
  13163. if( (check_ascii < 48) || (check_ascii > 57) )
  13164. {
  13165. isSuccess = ConfigurationStatus_Rejected;
  13166. }
  13167. else
  13168. {
  13169. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13170. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  13171. isSuccess = ConfigurationStatus_Accepted;
  13172. }
  13173. }
  13174. else
  13175. {
  13176. isSuccess = ConfigurationStatus_Rejected;
  13177. }
  13178. }
  13179. if(strcmp(key, "MeterValuesSampledData") == 0 )
  13180. {
  13181. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13182. {
  13183. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  13184. isSuccess = ConfigurationStatus_Accepted;
  13185. }
  13186. else
  13187. {
  13188. isSuccess = ConfigurationStatus_Rejected;
  13189. }
  13190. }
  13191. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  13192. {
  13193. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13194. {
  13195. check_ascii = value[0];
  13196. if( (check_ascii < 48) || (check_ascii > 57) )
  13197. {
  13198. isSuccess = ConfigurationStatus_Rejected;
  13199. }
  13200. else
  13201. {
  13202. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13203. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  13204. isSuccess = ConfigurationStatus_Accepted;
  13205. }
  13206. }
  13207. else
  13208. {
  13209. isSuccess = ConfigurationStatus_Rejected;
  13210. }
  13211. }
  13212. if(strcmp(key, "MeterValueSampleInterval") == 0)
  13213. {
  13214. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13215. {
  13216. check_ascii = value[0];
  13217. if( (check_ascii < 48) || (check_ascii > 57) )
  13218. {
  13219. isSuccess = ConfigurationStatus_Rejected;
  13220. }
  13221. else
  13222. {
  13223. if((atoi(value) == 0) || (atoi(value) >= 10))
  13224. {
  13225. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13226. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  13227. isSuccess = ConfigurationStatus_Accepted;
  13228. }
  13229. else
  13230. {
  13231. isSuccess = ConfigurationStatus_Rejected;
  13232. }
  13233. }
  13234. }
  13235. else
  13236. {
  13237. isSuccess = ConfigurationStatus_Rejected;
  13238. }
  13239. }
  13240. if(strcmp(key, "MinimumStatusDuration") == 0)
  13241. {
  13242. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13243. {
  13244. check_ascii = value[0];
  13245. if( (check_ascii < 48) || (check_ascii > 57) )
  13246. {
  13247. isSuccess = ConfigurationStatus_Rejected;
  13248. }
  13249. else
  13250. {
  13251. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  13252. {
  13253. isSuccess = ConfigurationStatus_Rejected;
  13254. }
  13255. else
  13256. {
  13257. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  13258. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  13259. server_cycle_Status = atoi(value); //StatusNotification Cycle
  13260. isSuccess = ConfigurationStatus_Accepted;
  13261. }
  13262. }
  13263. }
  13264. else
  13265. {
  13266. isSuccess = ConfigurationStatus_Rejected;
  13267. }
  13268. }
  13269. if(strcmp(key, "NumberOfConnectors") == 0)
  13270. {
  13271. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13272. {
  13273. check_ascii = value[0];
  13274. if( (check_ascii < 48) || (check_ascii > 57) )
  13275. {
  13276. isSuccess = ConfigurationStatus_Rejected;
  13277. }
  13278. else
  13279. {
  13280. //Charger.ResetRetries = Integer.parseInt(value);
  13281. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  13282. isSuccess = ConfigurationStatus_Accepted;
  13283. }
  13284. }
  13285. else
  13286. {
  13287. isSuccess = ConfigurationStatus_Rejected;
  13288. }
  13289. }
  13290. if(strcmp(key, "ResetRetries") == 0)
  13291. {
  13292. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13293. {
  13294. check_ascii = value[0];
  13295. if( (check_ascii < 48) || (check_ascii > 57) )
  13296. {
  13297. isSuccess = ConfigurationStatus_Rejected;
  13298. }
  13299. else
  13300. {
  13301. //Charger.ResetRetries = Integer.parseInt(value);
  13302. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  13303. isSuccess = ConfigurationStatus_Accepted;
  13304. }
  13305. }
  13306. else
  13307. {
  13308. isSuccess = ConfigurationStatus_Rejected;
  13309. }
  13310. }
  13311. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  13312. {
  13313. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13314. {
  13315. strcpy(str, (const char*)value);
  13316. for(int i = 0; str[i]; i++)
  13317. {
  13318. str[i] = tolower(str[i]);
  13319. }
  13320. if(strcmp(str, "notapplicable")== 0)
  13321. {
  13322. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  13323. isSuccess = ConfigurationStatus_Accepted;
  13324. }
  13325. else if(strcmp(str, "unknown")== 0)
  13326. {
  13327. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  13328. isSuccess = ConfigurationStatus_Accepted;
  13329. }
  13330. else if(strcmp(str, "rst")== 0)
  13331. {
  13332. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  13333. isSuccess = ConfigurationStatus_Accepted;
  13334. }
  13335. else if(strcmp(str, "rts")== 0)
  13336. {
  13337. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  13338. isSuccess = ConfigurationStatus_Accepted;
  13339. }
  13340. else if(strcmp(str, "srt")== 0)
  13341. {
  13342. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  13343. isSuccess = ConfigurationStatus_Accepted;
  13344. }
  13345. else if(strcmp(str, "str")== 0)
  13346. {
  13347. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  13348. isSuccess = ConfigurationStatus_Accepted;
  13349. }
  13350. else if(strcmp(str, "trs")== 0)
  13351. {
  13352. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  13353. isSuccess = ConfigurationStatus_Accepted;
  13354. }
  13355. else if(strcmp(str, "tsr")== 0)
  13356. {
  13357. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  13358. isSuccess = ConfigurationStatus_Accepted;
  13359. }
  13360. else
  13361. {
  13362. isSuccess = ConfigurationStatus_Rejected;
  13363. }
  13364. }
  13365. else
  13366. {
  13367. isSuccess = ConfigurationStatus_Rejected;
  13368. }
  13369. }
  13370. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  13371. {
  13372. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13373. {
  13374. check_ascii = value[0];
  13375. if( (check_ascii < 48) || (check_ascii > 57) )
  13376. {
  13377. isSuccess = ConfigurationStatus_Rejected;
  13378. }
  13379. else
  13380. {
  13381. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  13382. isSuccess = ConfigurationStatus_Accepted;
  13383. }
  13384. }
  13385. else
  13386. {
  13387. isSuccess = ConfigurationStatus_Rejected;
  13388. }
  13389. }
  13390. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  13391. {
  13392. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13393. {
  13394. strcpy(str, (const char*)value);
  13395. for(int i = 0; str[i]; i++)
  13396. {
  13397. str[i] = tolower(str[i]);
  13398. }
  13399. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  13400. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13401. isSuccess = ConfigurationStatus_Accepted;
  13402. }
  13403. else
  13404. {
  13405. isSuccess = ConfigurationStatus_Rejected;
  13406. }
  13407. }
  13408. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  13409. {
  13410. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13411. {
  13412. strcpy(str, (const char*)value);
  13413. for(int i = 0; str[i]; i++)
  13414. {
  13415. str[i] = tolower(str[i]);
  13416. }
  13417. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  13418. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13419. isSuccess = ConfigurationStatus_Accepted;
  13420. }
  13421. else
  13422. {
  13423. isSuccess = ConfigurationStatus_Rejected;
  13424. }
  13425. }
  13426. if(strcmp(key, "StopTxnAlignedData") == 0)
  13427. {
  13428. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13429. {
  13430. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  13431. isSuccess = ConfigurationStatus_Accepted;
  13432. }
  13433. else
  13434. {
  13435. isSuccess = ConfigurationStatus_Rejected;
  13436. }
  13437. }
  13438. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  13439. {
  13440. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13441. {
  13442. check_ascii = value[0];
  13443. if( (check_ascii < 48) || (check_ascii > 57) )
  13444. {
  13445. isSuccess = ConfigurationStatus_Rejected;
  13446. }
  13447. else
  13448. {
  13449. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  13450. isSuccess = ConfigurationStatus_Accepted;
  13451. }
  13452. }
  13453. else
  13454. {
  13455. isSuccess = ConfigurationStatus_Rejected;
  13456. }
  13457. }
  13458. if(strcmp(key, "StopTxnSampledData") == 0)
  13459. {
  13460. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13461. {
  13462. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  13463. isSuccess = ConfigurationStatus_Accepted;
  13464. }
  13465. else
  13466. {
  13467. isSuccess = ConfigurationStatus_Rejected;
  13468. }
  13469. }
  13470. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  13471. {
  13472. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13473. {
  13474. check_ascii = value[0];
  13475. if( (check_ascii < 48) || (check_ascii > 57) )
  13476. {
  13477. isSuccess = ConfigurationStatus_Rejected;
  13478. }
  13479. else
  13480. {
  13481. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  13482. isSuccess = ConfigurationStatus_Accepted;
  13483. }
  13484. }
  13485. else
  13486. {
  13487. isSuccess = ConfigurationStatus_Rejected;
  13488. }
  13489. }
  13490. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  13491. {
  13492. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13493. {
  13494. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  13495. isSuccess = ConfigurationStatus_Accepted;
  13496. }
  13497. else
  13498. {
  13499. isSuccess = ConfigurationStatus_Rejected;
  13500. }
  13501. }
  13502. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  13503. {
  13504. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13505. {
  13506. check_ascii = value[0];
  13507. if( (check_ascii < 48) || (check_ascii > 57) )
  13508. {
  13509. isSuccess = ConfigurationStatus_Rejected;
  13510. }
  13511. else
  13512. {
  13513. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  13514. isSuccess = ConfigurationStatus_Accepted;
  13515. }
  13516. }
  13517. else
  13518. {
  13519. isSuccess = ConfigurationStatus_Rejected;
  13520. }
  13521. }
  13522. if(strcmp(key, "TransactionMessageAttempts") == 0)
  13523. {
  13524. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13525. {
  13526. check_ascii = value[0];
  13527. if( (check_ascii < 48) || (check_ascii > 57) )
  13528. {
  13529. isSuccess = ConfigurationStatus_Rejected;
  13530. }
  13531. else
  13532. {
  13533. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  13534. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  13535. TransactionMessageAttemptsValue = atoi(value);
  13536. isSuccess = ConfigurationStatus_Accepted;
  13537. }
  13538. }
  13539. else
  13540. {
  13541. isSuccess = ConfigurationStatus_Rejected;
  13542. }
  13543. }
  13544. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  13545. {
  13546. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13547. {
  13548. check_ascii = value[0];
  13549. if( (check_ascii < 48) || (check_ascii > 57) )
  13550. {
  13551. isSuccess = ConfigurationStatus_Rejected;
  13552. }
  13553. else
  13554. {
  13555. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  13556. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  13557. TransactionMessageRetryIntervalValue = atoi(value);
  13558. isSuccess = ConfigurationStatus_Accepted;
  13559. }
  13560. }
  13561. else
  13562. {
  13563. isSuccess = ConfigurationStatus_Rejected;
  13564. }
  13565. }
  13566. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  13567. {
  13568. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13569. {
  13570. strcpy(str, (const char*)value);
  13571. for(int i = 0; str[i]; i++)
  13572. {
  13573. str[i] = tolower(str[i]);
  13574. }
  13575. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  13576. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13577. isSuccess = ConfigurationStatus_Accepted;
  13578. }
  13579. else
  13580. {
  13581. isSuccess = ConfigurationStatus_Rejected;
  13582. }
  13583. }
  13584. if(strcmp(key, "WebSocketPingInterval") == 0)
  13585. {
  13586. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13587. {
  13588. check_ascii = value[0];
  13589. if( (check_ascii < 48) || (check_ascii > 57) )
  13590. {
  13591. isSuccess = ConfigurationStatus_Rejected;
  13592. }
  13593. else
  13594. {
  13595. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  13596. isSuccess = ConfigurationStatus_Accepted;
  13597. }
  13598. }
  13599. else
  13600. {
  13601. isSuccess = ConfigurationStatus_Rejected;
  13602. }
  13603. }
  13604. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  13605. {
  13606. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  13607. {
  13608. strcpy(str, (const char*)value);
  13609. for(int i = 0; str[i]; i++)
  13610. {
  13611. str[i] = tolower(str[i]);
  13612. }
  13613. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13614. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13615. isSuccess = ConfigurationStatus_Accepted;
  13616. }
  13617. else
  13618. {
  13619. isSuccess = ConfigurationStatus_Rejected;
  13620. }
  13621. }
  13622. if(strcmp(key, "AuthorizationKey") == 0)
  13623. {
  13624. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  13625. {
  13626. strcpy(str, (const char*)value);
  13627. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  13628. isSuccess = ConfigurationStatus_Accepted;
  13629. }
  13630. else
  13631. {
  13632. isSuccess = ConfigurationStatus_Rejected;
  13633. }
  13634. }
  13635. if(strcmp(key, "SecurityProfile") == 0)
  13636. {
  13637. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  13638. {
  13639. check_ascii = value[0];
  13640. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  13641. {
  13642. isSuccess = ConfigurationStatus_Rejected;
  13643. }
  13644. else if(check_ascii == 0x33)
  13645. {
  13646. isSuccess = NotSupported;
  13647. }
  13648. else
  13649. {
  13650. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  13651. {
  13652. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  13653. isSuccess = ConfigurationStatus_Accepted;
  13654. }
  13655. else
  13656. isSuccess = ConfigurationStatus_Rejected;
  13657. }
  13658. }
  13659. else
  13660. {
  13661. isSuccess = ConfigurationStatus_Rejected;
  13662. }
  13663. }
  13664. if(strcmp(key, "DefaultPrice") == 0)
  13665. {
  13666. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  13667. {
  13668. strcpy(str, (const char*)value);
  13669. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  13670. isSuccess = ConfigurationStatus_Accepted;
  13671. }
  13672. else
  13673. {
  13674. isSuccess = ConfigurationStatus_Rejected;
  13675. }
  13676. }
  13677. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  13678. {
  13679. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  13680. {
  13681. strcpy(str, (const char*)value);
  13682. for(int i = 0; str[i]; i++)
  13683. {
  13684. str[i] = tolower(str[i]);
  13685. }
  13686. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13687. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13688. isSuccess = ConfigurationStatus_Accepted;
  13689. }
  13690. else
  13691. {
  13692. isSuccess = ConfigurationStatus_Rejected;
  13693. }
  13694. }
  13695. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  13696. {
  13697. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  13698. {
  13699. strcpy(str, (const char*)value);
  13700. for(int i = 0; str[i]; i++)
  13701. {
  13702. str[i] = tolower(str[i]);
  13703. }
  13704. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13705. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13706. isSuccess = ConfigurationStatus_Accepted;
  13707. }
  13708. else
  13709. {
  13710. isSuccess = ConfigurationStatus_Rejected;
  13711. }
  13712. }
  13713. #if 0
  13714. //For OCPP Test Case
  13715. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  13716. {
  13717. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13718. {
  13719. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  13720. isSuccess = ConfigurationStatus_Accepted;
  13721. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13722. }
  13723. else
  13724. {
  13725. isSuccess = ConfigurationStatus_Rejected;
  13726. }
  13727. }
  13728. #endif
  13729. #if 1
  13730. if(strcmp(key, "LocalAuthListEnabled") == 0)
  13731. {
  13732. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13733. {
  13734. strcpy(str, (const char*)value);
  13735. for(int i = 0; str[i]; i++)
  13736. {
  13737. str[i] = tolower(str[i]);
  13738. }
  13739. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13740. isSuccess = ConfigurationStatus_Accepted;
  13741. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13742. }
  13743. else
  13744. {
  13745. isSuccess = ConfigurationStatus_Rejected;
  13746. }
  13747. }
  13748. #endif
  13749. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  13750. {
  13751. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  13752. {
  13753. check_ascii = value[0];
  13754. if( (check_ascii < 48) || (check_ascii > 57) )
  13755. {
  13756. isSuccess = ConfigurationStatus_Rejected;
  13757. }
  13758. else
  13759. {
  13760. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  13761. isSuccess = ConfigurationStatus_Accepted;
  13762. }
  13763. }
  13764. else
  13765. {
  13766. isSuccess = ConfigurationStatus_Rejected;
  13767. }
  13768. }
  13769. if(strcmp(key, "SendLocalListMaxLength") == 0)
  13770. {
  13771. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  13772. {
  13773. check_ascii = value[0];
  13774. if( (check_ascii < 48) || (check_ascii > 57) )
  13775. {
  13776. isSuccess = ConfigurationStatus_Rejected;
  13777. }
  13778. else
  13779. {
  13780. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  13781. isSuccess = ConfigurationStatus_Accepted;
  13782. }
  13783. }
  13784. else
  13785. {
  13786. isSuccess = ConfigurationStatus_Rejected;
  13787. }
  13788. }
  13789. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  13790. {
  13791. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  13792. {
  13793. strcpy(str, (const char*)value);
  13794. for(int i = 0; str[i]; i++)
  13795. {
  13796. str[i] = tolower(str[i]);
  13797. }
  13798. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13799. isSuccess = ConfigurationStatus_Accepted;
  13800. }
  13801. else
  13802. {
  13803. isSuccess = ConfigurationStatus_Rejected;
  13804. }
  13805. }
  13806. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  13807. {
  13808. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  13809. {
  13810. check_ascii = value[0];
  13811. if( (check_ascii < 48) || (check_ascii > 57) )
  13812. {
  13813. isSuccess = ConfigurationStatus_Rejected;
  13814. }
  13815. else
  13816. {
  13817. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  13818. isSuccess = ConfigurationStatus_Accepted;
  13819. }
  13820. }
  13821. else
  13822. {
  13823. isSuccess = ConfigurationStatus_Rejected;
  13824. }
  13825. }
  13826. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  13827. {
  13828. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  13829. {
  13830. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  13831. isSuccess = ConfigurationStatus_Accepted;
  13832. }
  13833. else
  13834. {
  13835. isSuccess = ConfigurationStatus_Rejected;
  13836. }
  13837. }
  13838. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  13839. {
  13840. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  13841. {
  13842. check_ascii = value[0];
  13843. if( (check_ascii < 48) || (check_ascii > 57) )
  13844. {
  13845. isSuccess = ConfigurationStatus_Rejected;
  13846. }
  13847. else
  13848. {
  13849. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  13850. isSuccess = ConfigurationStatus_Accepted;
  13851. }
  13852. }
  13853. else
  13854. {
  13855. isSuccess = ConfigurationStatus_Rejected;
  13856. }
  13857. }
  13858. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  13859. {
  13860. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  13861. {
  13862. strcpy(str, (const char*)value);
  13863. for(int i = 0; str[i]; i++)
  13864. {
  13865. str[i] = tolower(str[i]);
  13866. }
  13867. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13868. isSuccess = ConfigurationStatus_Accepted;
  13869. }
  13870. else
  13871. {
  13872. isSuccess = ConfigurationStatus_Rejected;
  13873. }
  13874. }
  13875. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  13876. {
  13877. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  13878. {
  13879. check_ascii = value[0];
  13880. if( (check_ascii < 48) || (check_ascii > 57) )
  13881. {
  13882. isSuccess = ConfigurationStatus_Rejected;
  13883. }
  13884. else
  13885. {
  13886. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  13887. isSuccess = ConfigurationStatus_Accepted;
  13888. }
  13889. }
  13890. else
  13891. {
  13892. isSuccess = ConfigurationStatus_Rejected;
  13893. }
  13894. }
  13895. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13896. return isSuccess;
  13897. }
  13898. int TransactionMessageAttemptsGet(void)
  13899. {
  13900. return TransactionMessageAttemptsValue;
  13901. }
  13902. int FirstHeartBeatResponse(void)
  13903. {
  13904. return FirstHeartBeat;
  13905. }
  13906. int TransactionMessageRetryIntervalGet(void)
  13907. {
  13908. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13909. }
  13910. int ReadHttpStatus(int sock)
  13911. {
  13912. //char c;
  13913. char buff[1024]="",*ptr=buff+1;
  13914. int bytes_received, status;
  13915. DEBUG_INFO("Begin Response ..\n");
  13916. while((bytes_received = recv(sock, ptr, 1, 0))){
  13917. if(bytes_received==-1){
  13918. perror("ReadHttpStatus");
  13919. exit(1);
  13920. }
  13921. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  13922. ptr++;
  13923. }
  13924. *ptr=0;
  13925. ptr=buff+1;
  13926. sscanf(ptr,"%*s %d ", &status);
  13927. DEBUG_INFO("%s\n",ptr);
  13928. DEBUG_INFO("status=%d\n",status);
  13929. DEBUG_INFO("End Response ..\n");
  13930. return (bytes_received>0)?status:0;
  13931. }
  13932. //the only filed that it parsed is 'Content-Length'
  13933. int ParseHeader(int sock)
  13934. {
  13935. //char c;
  13936. char buff[1024]="",*ptr=buff+4;
  13937. int bytes_received;
  13938. DEBUG_INFO("Begin HEADER ..\n");
  13939. while((bytes_received = recv(sock, ptr, 1, 0))){
  13940. if(bytes_received==-1){
  13941. perror("Parse Header");
  13942. exit(1);
  13943. }
  13944. if(
  13945. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  13946. (ptr[-1]=='\r') && (*ptr=='\n' )
  13947. ) break;
  13948. ptr++;
  13949. }
  13950. *ptr=0;
  13951. ptr=buff+4;
  13952. //printf("%s",ptr);
  13953. if(bytes_received){
  13954. ptr=strstr(ptr,"Content-Length:");
  13955. if(ptr){
  13956. sscanf(ptr,"%*s %d",&bytes_received);
  13957. }else
  13958. bytes_received=-1; //unknown size
  13959. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  13960. }
  13961. DEBUG_INFO("End HEADER ..\n");
  13962. return bytes_received ;
  13963. }
  13964. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  13965. {
  13966. int result = TRUE;
  13967. char rmFileCmd[100]={0};
  13968. char FilePath[100]={0};
  13969. char ftpbuf[200];
  13970. int systemresult;
  13971. //DEBUG_INFO("filename=%s\n",filename);
  13972. //DEBUG_INFO("url=%s\n",url);
  13973. sprintf(FilePath,"/mnt/%s",filename);
  13974. system("ping 8.8.8.8 &");
  13975. if((access(FilePath,F_OK))!=-1)
  13976. {
  13977. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13978. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13979. system(rmFileCmd);
  13980. }
  13981. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13982. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  13983. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13984. systemresult = system(ftpbuf);
  13985. //DEBUG_INFO("systemresult=%d\n",systemresult);
  13986. if(systemresult != 0)
  13987. {
  13988. DEBUG_INFO("http DownLoad error!\n");
  13989. result = FALSE;
  13990. }
  13991. system("pkill ping");
  13992. return result;
  13993. }
  13994. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  13995. {
  13996. int result = TRUE;
  13997. char rmFileCmd[100]={0};
  13998. char FilePath[100]={0};
  13999. char ftpbuf[200];
  14000. int systemresult;
  14001. //char temp[100];
  14002. sprintf(FilePath,"/mnt/%s",filename);
  14003. system("ping 8.8.8.8 &");
  14004. if((access(FilePath,F_OK))!=-1)
  14005. {
  14006. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14007. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14008. system(rmFileCmd);
  14009. }
  14010. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14011. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14012. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  14013. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14014. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14015. systemresult = system(ftpbuf);
  14016. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14017. if(systemresult != 0)
  14018. {
  14019. printf("wget error!\n");
  14020. result = FALSE;
  14021. }
  14022. system("pkill ping");
  14023. return result;
  14024. }
  14025. int httpUploadFile(char *location, char *path, char *filename,char *url)
  14026. {
  14027. char rmFileCmd[100]={0};
  14028. char FilePath[100]={0};
  14029. char buf[512];
  14030. int systemresult = 0;
  14031. //DEBUG_INFO("filename=%s\n",filename);
  14032. //DEBUG_INFO("url=%s\n",url);
  14033. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  14034. if((access(FilePath,F_OK))!=-1)
  14035. {
  14036. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14037. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14038. system(rmFileCmd);
  14039. }
  14040. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  14041. if(fp == NULL)
  14042. {
  14043. DEBUG_INFO("log is NULL\n");
  14044. return FALSE;
  14045. }
  14046. else
  14047. {
  14048. fprintf(fp, "%s\n", url);
  14049. fprintf(fp, "%s\n", filename);
  14050. fclose(fp);
  14051. }
  14052. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  14053. if(phpFP == NULL)
  14054. {
  14055. DEBUG_INFO("PHP upload fail.\n");
  14056. return FALSE;
  14057. }
  14058. else
  14059. {
  14060. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  14061. {
  14062. if(strstr(buf, "result") != NULL)
  14063. {
  14064. sscanf(buf, "result: %d", &systemresult);
  14065. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  14066. }
  14067. }
  14068. pclose(phpFP);
  14069. }
  14070. if(systemresult != 1)
  14071. {
  14072. DEBUG_INFO("HTTP upload error!\n");
  14073. return FALSE;
  14074. }
  14075. return TRUE;
  14076. }
  14077. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  14078. {
  14079. struct hostent* server;
  14080. char *IPbuffer;
  14081. char ftpbuf[200];
  14082. int systemresult;
  14083. // To retrieve host information
  14084. server = gethostbyname(location);
  14085. // To convert an Internet network
  14086. // address into ASCII string
  14087. IPbuffer = inet_ntoa(*((struct in_addr*)
  14088. server->h_addr_list[0]));
  14089. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14090. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  14091. /* format : ftpput -u username -p passwd IP target source*/
  14092. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  14093. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14094. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14095. systemresult = system(ftpbuf);
  14096. DEBUG_INFO("systemresult=%d\n",systemresult);
  14097. if(systemresult != 0)
  14098. {
  14099. DEBUG_INFO("ftpput error!\n");
  14100. return FALSE;
  14101. }
  14102. return TRUE;
  14103. }
  14104. int GetOcppServerURL()
  14105. {
  14106. int result = FALSE;
  14107. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  14108. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  14109. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  14110. struct yuarel url;
  14111. char urlStr[512];
  14112. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  14113. {
  14114. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  14115. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14116. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  14117. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  14118. if(yuarel_parse(&url, urlStr) != -1)
  14119. {
  14120. sprintf(OcppProtocol, "%s", url.scheme);
  14121. sprintf(OcppHost, "%s", url.host);
  14122. if(url.path == NULL)
  14123. OcppTempPath[0] = '\0';
  14124. else
  14125. {
  14126. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  14127. {
  14128. sprintf(OcppTempPath, "%s/", url.path);
  14129. }
  14130. else
  14131. {
  14132. sprintf(OcppTempPath, "%s", url.path);
  14133. }
  14134. }
  14135. if(url.port == 0)
  14136. {
  14137. if(strcmp(OcppProtocol, "wss") == 0)
  14138. OcppPort = 443;
  14139. else
  14140. OcppPort = 80;
  14141. }
  14142. else
  14143. OcppPort = url.port;
  14144. result = TRUE;
  14145. }
  14146. }
  14147. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  14148. {
  14149. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  14150. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14151. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  14152. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  14153. if(yuarel_parse(&url, urlStr) != -1)
  14154. {
  14155. sprintf(OcppProtocol, "%s", url.scheme);
  14156. sprintf(OcppHost, "%s", url.host);
  14157. if(url.path == NULL)
  14158. OcppTempPath[0] = '\0';
  14159. else
  14160. sprintf(OcppTempPath, "%s", url.path);
  14161. if(url.port == 0)
  14162. {
  14163. if(strcmp(OcppProtocol, "wss") == 0)
  14164. OcppPort = 443;
  14165. else
  14166. OcppPort = 80;
  14167. }
  14168. else
  14169. OcppPort = url.port;
  14170. result = TRUE;
  14171. }
  14172. }
  14173. else
  14174. {
  14175. strcpy(OcppHost,"");
  14176. }
  14177. return result;
  14178. }
  14179. int GetOcppPath()
  14180. {
  14181. int result = FALSE;
  14182. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  14183. {
  14184. if(OcppTempPath == NULL)
  14185. {
  14186. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  14187. }
  14188. else
  14189. {
  14190. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  14191. }
  14192. result = TRUE;
  14193. goto End;
  14194. }
  14195. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  14196. {
  14197. if(OcppTempPath == NULL)
  14198. {
  14199. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  14200. }
  14201. else
  14202. {
  14203. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  14204. }
  14205. result = TRUE;
  14206. goto End;
  14207. }
  14208. else
  14209. {
  14210. strcpy(OcppPath,"");
  14211. }
  14212. End:
  14213. return result;
  14214. }
  14215. int GetOcppPort()
  14216. {
  14217. return OcppPort;
  14218. }
  14219. int GetOcppConnStatus(void)
  14220. {
  14221. return ShmOCPP16Data->OcppConnStatus;
  14222. }
  14223. void SetOcppConnStatus(uint8_t status)
  14224. {
  14225. ShmOCPP16Data->OcppConnStatus = status;
  14226. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  14227. }
  14228. int GetHeartBeatWithNOResponse(void)
  14229. {
  14230. return HeartBeatWithNOResponse;
  14231. }
  14232. void SetHeartBeatWithNOResponse(void)
  14233. {
  14234. HeartBeatWithNOResponse = 0;
  14235. }
  14236. void GetStartTransactionIdTag(int gun_index)
  14237. {
  14238. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  14239. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  14240. }
  14241. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  14242. {
  14243. char ch;
  14244. FILE *fptr1;
  14245. int temptransactionId;
  14246. char str[100]={0};
  14247. temptransactionId = 0;
  14248. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  14249. {
  14250. DEBUG_INFO("IdTag is empty.\n");
  14251. return temptransactionId;
  14252. }
  14253. /*------ Read the file ----------------*/
  14254. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  14255. if (!fptr1)
  14256. {
  14257. DEBUG_INFO("QueueTransactionId file open error.\n");
  14258. //printf(" File not found or unable to open the input file!!\n");
  14259. return temptransactionId;
  14260. }
  14261. ch=fgetc(fptr1);
  14262. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  14263. rewind(fptr1);
  14264. if(ch!=EOF)
  14265. {
  14266. // printf("%c",ch);
  14267. while (fgets(str, 100, fptr1) != NULL)
  14268. {
  14269. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14270. if(str[0]=='\0')
  14271. {
  14272. break;
  14273. }
  14274. char *revbuf[8] = {0}; // Variable store string split
  14275. int num = 0;// Quantity after string split
  14276. DEBUG_INFO("Transaction queue data= %s\n", str);
  14277. splitstring(str,",",revbuf,&num); // String split
  14278. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  14279. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  14280. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  14281. DEBUG_INFO("------------------------------\n");
  14282. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  14283. {
  14284. if(isStopTransaction)
  14285. {
  14286. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  14287. {
  14288. temptransactionId = atoi(revbuf[2]);
  14289. //break;
  14290. }
  14291. }
  14292. else
  14293. {
  14294. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  14295. {
  14296. temptransactionId = atoi(revbuf[2]);
  14297. //break;
  14298. }
  14299. }
  14300. }
  14301. }
  14302. }
  14303. else
  14304. DEBUG_INFO("EOF\n");
  14305. fclose(fptr1);
  14306. /*------- End of reading ---------------*/
  14307. return temptransactionId;
  14308. }
  14309. void SetTransactionIdZero(int transactionId)
  14310. {
  14311. char ch;
  14312. FILE *fptr1, *fptr2;
  14313. int temptransactionId = 0;
  14314. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  14315. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  14316. if (!fptr1)
  14317. {
  14318. //printf(" File not found or unable to open the input file!!\n");
  14319. return ;
  14320. }
  14321. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  14322. if (!fptr2)
  14323. {
  14324. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  14325. fclose(fptr1);
  14326. return ;
  14327. }
  14328. ch=fgetc(fptr1);
  14329. rewind(fptr1);
  14330. if(ch!=EOF)
  14331. {
  14332. // copy all contents to the temporary file except the specific line
  14333. while (fgets(str, 100, fptr1) != NULL)
  14334. {
  14335. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14336. if(str[0]=='\0')
  14337. {
  14338. break;
  14339. }
  14340. char *revbuf[8] = {0};
  14341. int num = 0;
  14342. strcpy(strtemp, str);
  14343. splitstring(str,",",revbuf,&num);
  14344. if(revbuf[2][0] != '\0')
  14345. {
  14346. temptransactionId = atoi(revbuf[2]);
  14347. if(transactionId != temptransactionId)
  14348. {
  14349. fprintf(fptr2, "%s\n", strtemp);
  14350. }
  14351. }
  14352. }
  14353. }
  14354. fclose(fptr1);
  14355. fclose(fptr2);
  14356. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  14357. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  14358. /*------ Read the file ----------------*/
  14359. }
  14360. int InternetDisconnect(void)
  14361. {
  14362. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  14363. }
  14364. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  14365. void storeTempStopTransaction(int gun_index)
  14366. {
  14367. char guid[37]={0};
  14368. int tempIndex = 0;
  14369. char TempStopTransaction[256];
  14370. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  14371. DEBUG_INFO("storeTempStopTransaction...\n");
  14372. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  14373. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  14374. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  14375. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14376. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14377. {
  14378. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14379. {
  14380. tempIndex = ((gun_index==2) ? 1: 0);
  14381. }
  14382. else
  14383. {
  14384. tempIndex = gun_index;
  14385. }
  14386. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14387. {
  14388. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14389. {
  14390. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  14391. }
  14392. }// END OF CHAdeMO_QUANTITY
  14393. }
  14394. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14395. {
  14396. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14397. {
  14398. tempIndex = ((gun_index==2) ? 1: 0);
  14399. }
  14400. else
  14401. {
  14402. tempIndex = gun_index;
  14403. }
  14404. for (int index = 0; index < CCS_QUANTITY; index++)
  14405. {
  14406. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14407. {
  14408. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  14409. }
  14410. }// END OF CCS_QUANTITY
  14411. }
  14412. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14413. {
  14414. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14415. {
  14416. tempIndex = ((gun_index==2) ? 1: 0);
  14417. }
  14418. else
  14419. {
  14420. tempIndex = gun_index;
  14421. }
  14422. for (int index = 0; index < GB_QUANTITY; index++)
  14423. {
  14424. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14425. {
  14426. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  14427. }
  14428. }// END OF GB_QUANTITY
  14429. }
  14430. else if(gunType[gun_index] == GUN_TYPE_DO)
  14431. {
  14432. tempIndex = gun_index;
  14433. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14434. {
  14435. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14436. {
  14437. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  14438. }
  14439. }
  14440. }
  14441. else
  14442. {
  14443. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14444. {
  14445. tempIndex = 2;
  14446. }
  14447. else
  14448. {
  14449. tempIndex = gun_index;
  14450. }
  14451. for (int index = 0; index < AC_QUANTITY; index++)
  14452. {
  14453. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14454. {
  14455. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  14456. }
  14457. }// END OF AC_QUANTITY
  14458. }
  14459. //Stop Transaction Time
  14460. struct timeval tmnow;
  14461. struct tm *tm;
  14462. char buf[28];//, usec_buf[6];
  14463. gettimeofday(&tmnow, NULL);
  14464. time_t t;
  14465. t = time(NULL);
  14466. /*UTC time and date*/
  14467. tm = gmtime(&t);
  14468. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  14469. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  14470. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  14471. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  14472. random_uuid(guid);
  14473. /***********************************transactionData******************************************************/
  14474. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  14475. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  14476. //=================================
  14477. //1. Transaction_Begin
  14478. //=================================
  14479. //============================== Energy.Active.Import.Interval ===========================================
  14480. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  14481. {
  14482. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  14483. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  14484. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  14485. 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*/]);
  14486. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14487. 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))
  14488. {
  14489. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  14490. }
  14491. else
  14492. {
  14493. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  14494. }
  14495. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  14496. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14497. }
  14498. //=================================
  14499. //2. Transaction_End
  14500. //=================================
  14501. //2.1====================================== Current.Import L1 ==============================================
  14502. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  14503. {
  14504. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  14505. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14506. {
  14507. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14508. {
  14509. tempIndex = ((gun_index==2) ? 1: 0);
  14510. }
  14511. else
  14512. {
  14513. tempIndex = gun_index;
  14514. }
  14515. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14516. {
  14517. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14518. {
  14519. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14520. }
  14521. }// End of for CHAdeMO_QUANTITY
  14522. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14523. }
  14524. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14525. {
  14526. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14527. {
  14528. tempIndex = ((gun_index==2) ? 1: 0);
  14529. }
  14530. else
  14531. {
  14532. tempIndex = gun_index;
  14533. }
  14534. for (int index = 0; index < CCS_QUANTITY; index++)
  14535. {
  14536. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14537. {
  14538. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14539. }
  14540. }// End of for CCS_QUANTITY
  14541. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14542. }
  14543. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14544. {
  14545. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14546. {
  14547. tempIndex = ((gun_index==2) ? 1: 0);
  14548. }
  14549. else
  14550. {
  14551. tempIndex = gun_index;
  14552. }
  14553. for (int index = 0; index < GB_QUANTITY; index++)
  14554. {
  14555. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14556. {
  14557. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14558. }
  14559. }// End of for GB_QUANTITY
  14560. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14561. }
  14562. else if(gunType[gun_index] == GUN_TYPE_DO)
  14563. {
  14564. tempIndex = gun_index;
  14565. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14566. {
  14567. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14568. {
  14569. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14570. }
  14571. }
  14572. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14573. }
  14574. else
  14575. {
  14576. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14577. {
  14578. tempIndex = 2;
  14579. }
  14580. else
  14581. {
  14582. tempIndex = gun_index;
  14583. }
  14584. for (int index = 0; index < AC_QUANTITY; index++)
  14585. {
  14586. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14587. {
  14588. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  14589. }
  14590. }// End of for AC_QUANTITY
  14591. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  14592. }
  14593. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14594. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  14595. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  14596. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  14597. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  14598. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14599. }
  14600. //2.2===================================== Energy.Active.Import.Interval ==========================================
  14601. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  14602. {
  14603. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14604. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14605. {
  14606. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14607. {
  14608. tempIndex = ((gun_index==2) ? 1: 0);
  14609. }
  14610. else
  14611. {
  14612. tempIndex = gun_index;
  14613. }
  14614. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14615. {
  14616. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14617. {
  14618. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14619. }
  14620. }// END OF CHAdeMO_QUANTITY
  14621. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14622. }
  14623. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14624. {
  14625. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14626. {
  14627. tempIndex = ((gun_index==2) ? 1: 0);
  14628. }
  14629. else
  14630. {
  14631. tempIndex = gun_index;
  14632. }
  14633. for (int index = 0; index < CCS_QUANTITY; index++)
  14634. {
  14635. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14636. {
  14637. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14638. }
  14639. }// END OF CCS_QUANTITY
  14640. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14641. }
  14642. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14643. {
  14644. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14645. {
  14646. tempIndex = ((gun_index==2) ? 1: 0);
  14647. }
  14648. else
  14649. {
  14650. tempIndex = gun_index;
  14651. }
  14652. for (int index = 0; index < GB_QUANTITY; index++)
  14653. {
  14654. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14655. {
  14656. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14657. }
  14658. }// END OF GB_QUANTITY
  14659. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14660. }
  14661. else if(gunType[gun_index] == GUN_TYPE_DO)
  14662. {
  14663. tempIndex = gun_index;
  14664. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14665. {
  14666. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14667. {
  14668. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14669. }
  14670. }
  14671. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14672. }
  14673. else
  14674. {
  14675. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14676. {
  14677. tempIndex = 2;
  14678. }
  14679. else
  14680. {
  14681. tempIndex = gun_index;
  14682. }
  14683. for (int index = 0; index < AC_QUANTITY; index++)
  14684. {
  14685. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14686. {
  14687. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14688. }
  14689. }// END OF AC_QUANTITY
  14690. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14691. }
  14692. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14693. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  14694. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  14695. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14696. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  14697. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14698. }
  14699. //2.3====================================== Power.Active.Import =========================================
  14700. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  14701. {
  14702. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14703. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14704. {
  14705. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14706. {
  14707. tempIndex = ((gun_index==2) ? 1: 0);
  14708. }
  14709. else
  14710. {
  14711. tempIndex = gun_index;
  14712. }
  14713. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14714. {
  14715. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14716. {
  14717. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14718. }
  14719. } // End for CHAdeMO_QUANTITY
  14720. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14721. }
  14722. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14723. {
  14724. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14725. {
  14726. tempIndex = ((gun_index==2) ? 1: 0);
  14727. }
  14728. else
  14729. {
  14730. tempIndex = gun_index;
  14731. }
  14732. for (int index = 0; index < CCS_QUANTITY; index++)
  14733. {
  14734. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14735. {
  14736. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14737. }
  14738. } // END for CCS_QUANTITY
  14739. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14740. }
  14741. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14742. {
  14743. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14744. {
  14745. tempIndex = ((gun_index==2) ? 1: 0);
  14746. }
  14747. else
  14748. {
  14749. tempIndex = gun_index;
  14750. }
  14751. for (int index = 0; index < GB_QUANTITY; index++)
  14752. {
  14753. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14754. {
  14755. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14756. }
  14757. }// END for GB_QUANTITY
  14758. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14759. }
  14760. else if(gunType[gun_index] == GUN_TYPE_DO)
  14761. {
  14762. tempIndex = gun_index;
  14763. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14764. {
  14765. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14766. {
  14767. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14768. }
  14769. }
  14770. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14771. }
  14772. else
  14773. {
  14774. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14775. {
  14776. tempIndex = 2;
  14777. }
  14778. else
  14779. {
  14780. tempIndex = gun_index;
  14781. }
  14782. for (int index = 0; index < AC_QUANTITY; index++)
  14783. {
  14784. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14785. {
  14786. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14787. }
  14788. } // END for AC_QUANTITY
  14789. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14790. }
  14791. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14792. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  14793. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  14794. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14795. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  14796. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  14797. }
  14798. //2.4====================================== Voltage L1 ====================================================
  14799. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  14800. {
  14801. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14802. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14803. {
  14804. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14805. {
  14806. tempIndex = ((gun_index==2) ? 1: 0);
  14807. }
  14808. else
  14809. {
  14810. tempIndex = gun_index;
  14811. }
  14812. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14813. {
  14814. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14815. {
  14816. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14817. }
  14818. } // END OF FOR CHAdeMO_QUANTITY
  14819. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14820. }
  14821. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14822. {
  14823. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14824. {
  14825. tempIndex = ((gun_index==2) ? 1: 0);
  14826. }
  14827. else
  14828. {
  14829. tempIndex = gun_index;
  14830. }
  14831. for (int index = 0; index < CCS_QUANTITY; index++)
  14832. {
  14833. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14834. {
  14835. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14836. }
  14837. } // END OF FOR CCS_QUANTITY
  14838. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14839. }
  14840. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14841. {
  14842. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14843. {
  14844. tempIndex = ((gun_index==2) ? 1: 0);
  14845. }
  14846. else
  14847. {
  14848. tempIndex = gun_index;
  14849. }
  14850. for (int index = 0; index < GB_QUANTITY; index++)
  14851. {
  14852. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14853. {
  14854. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14855. }
  14856. } // END OF FOR GB_QUANTITY
  14857. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14858. }
  14859. else if(gunType[gun_index] == GUN_TYPE_DO)
  14860. {
  14861. tempIndex = gun_index;
  14862. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14863. {
  14864. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14865. {
  14866. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14867. }
  14868. }
  14869. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14870. }
  14871. else
  14872. {
  14873. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14874. {
  14875. tempIndex = 2;
  14876. }
  14877. else
  14878. {
  14879. tempIndex = gun_index;
  14880. }
  14881. for (int index = 0; index < AC_QUANTITY; index++)
  14882. {
  14883. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14884. {
  14885. 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
  14886. }
  14887. } // END OF FOR AC_QUANTITY
  14888. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  14889. }
  14890. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14891. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  14892. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  14893. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  14894. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  14895. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14896. }
  14897. //2.5============================================== End SoC =========================================================
  14898. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  14899. {
  14900. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14901. 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))
  14902. {
  14903. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  14904. {
  14905. tempIndex = ((gun_index==2) ? 1: 0);
  14906. }
  14907. else
  14908. {
  14909. tempIndex = gun_index;
  14910. }
  14911. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14912. {
  14913. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14914. {
  14915. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14916. {
  14917. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  14918. }
  14919. }
  14920. }
  14921. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14922. {
  14923. for (int index = 0; index < CCS_QUANTITY; index++)
  14924. {
  14925. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14926. {
  14927. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  14928. }
  14929. }
  14930. }
  14931. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14932. {
  14933. for (int index = 0; index < GB_QUANTITY; index++)
  14934. {
  14935. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14936. {
  14937. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  14938. }
  14939. }
  14940. }
  14941. else if(gunType[gun_index] == GUN_TYPE_DO)
  14942. {
  14943. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14944. {
  14945. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14946. {
  14947. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  14948. }
  14949. }
  14950. }
  14951. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14952. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  14953. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  14954. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  14955. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  14956. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  14957. } // END FOR DC CASE
  14958. }
  14959. //2.6====================================== Current.Import L2 ==============================================
  14960. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  14961. {
  14962. // AC 3 phase L2 current
  14963. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14964. {
  14965. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14966. {
  14967. tempIndex = 2;
  14968. }
  14969. else
  14970. {
  14971. tempIndex = gun_index;
  14972. }
  14973. for (int index = 0; index < AC_QUANTITY; index++)
  14974. {
  14975. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14976. {
  14977. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  14978. }
  14979. }// End of for AC_QUANTITY
  14980. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  14981. }
  14982. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14983. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  14984. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  14985. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  14986. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14987. }
  14988. //2.7====================================== Current.Import L3 ==============================================
  14989. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  14990. {
  14991. // AC 3 phase L3 current
  14992. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14993. {
  14994. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14995. {
  14996. tempIndex = 2;
  14997. }
  14998. else
  14999. {
  15000. tempIndex = gun_index;
  15001. }
  15002. for (int index = 0; index < AC_QUANTITY; index++)
  15003. {
  15004. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15005. {
  15006. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  15007. }
  15008. }// End of for AC_QUANTITY
  15009. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  15010. }
  15011. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15012. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  15013. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  15014. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  15015. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15016. }
  15017. //2.9====================================== Voltage L2 ====================================================
  15018. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15019. {
  15020. // AC 3 phase L2 volatge
  15021. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15022. {
  15023. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15024. {
  15025. tempIndex = 2;
  15026. }
  15027. else
  15028. {
  15029. tempIndex = gun_index;
  15030. }
  15031. for (int index = 0; index < AC_QUANTITY; index++)
  15032. {
  15033. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15034. {
  15035. 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
  15036. }
  15037. } // END OF FOR AC_QUANTITY
  15038. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  15039. }
  15040. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15041. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  15042. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  15043. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  15044. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15045. }
  15046. //2.10====================================== Voltage L3 ====================================================
  15047. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15048. {
  15049. // AC 3 phase L3 volatge
  15050. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15051. {
  15052. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15053. {
  15054. tempIndex = 2;
  15055. }
  15056. else
  15057. {
  15058. tempIndex = gun_index;
  15059. }
  15060. for (int index = 0; index < AC_QUANTITY; index++)
  15061. {
  15062. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15063. {
  15064. 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
  15065. }
  15066. } // END OF FOR AC_QUANTITY
  15067. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  15068. }
  15069. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15070. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  15071. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  15072. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  15073. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15074. }
  15075. //====================== Start SoC ================================
  15076. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  15077. {
  15078. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15079. 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))
  15080. {
  15081. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15082. {
  15083. tempIndex = ((gun_index==2) ? 1: 0);
  15084. }
  15085. else
  15086. {
  15087. tempIndex = gun_index;
  15088. }
  15089. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15090. {
  15091. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15092. {
  15093. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15094. {
  15095. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  15096. }
  15097. }
  15098. }
  15099. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15100. {
  15101. for (int index = 0; index < CCS_QUANTITY; index++)
  15102. {
  15103. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15104. {
  15105. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  15106. }
  15107. }
  15108. }
  15109. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15110. {
  15111. for (int index = 0; index < GB_QUANTITY; index++)
  15112. {
  15113. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15114. {
  15115. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  15116. }
  15117. }
  15118. }
  15119. else if(gunType[gun_index] == GUN_TYPE_DO)
  15120. {
  15121. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15122. {
  15123. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15124. {
  15125. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  15126. }
  15127. }
  15128. }
  15129. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15130. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  15131. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15132. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  15133. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  15134. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15135. } // END FOR DC CASE
  15136. }
  15137. //======================================== Message create ==============================================
  15138. json_object *StopTransaction = json_object_new_object();
  15139. json_object *transactionDatas = json_object_new_array();
  15140. json_object *sampledValues = json_object_new_array();
  15141. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  15142. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  15143. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  15144. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  15145. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  15146. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  15147. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  15148. {
  15149. json_object *transactionData = json_object_new_object();
  15150. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  15151. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  15152. {
  15153. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  15154. {
  15155. json_object *sampledValue = json_object_new_object();
  15156. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  15157. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  15158. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  15159. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  15160. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  15161. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  15162. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  15163. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  15164. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  15165. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  15166. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  15167. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  15168. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  15169. json_object_array_add(sampledValues, sampledValue);
  15170. }
  15171. }
  15172. json_object_object_add(transactionData, "sampledValue", sampledValues);
  15173. json_object_array_add(transactionDatas, transactionData);
  15174. }
  15175. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  15176. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  15177. ,MESSAGE_TYPE_CALL
  15178. ,guid
  15179. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  15180. json_object_put(StopTransaction);
  15181. // Check File "TempStopTransaction" Exist
  15182. if((access(TempStopTransaction,F_OK))!=-1)
  15183. {
  15184. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  15185. fclose(fopen(TempStopTransaction, "w"));
  15186. }
  15187. else
  15188. {
  15189. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  15190. FILE *log = fopen(TempStopTransaction, "w+");
  15191. if(log == NULL)
  15192. {
  15193. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  15194. return ;
  15195. }
  15196. else
  15197. {
  15198. fclose(log);
  15199. }
  15200. }
  15201. //Add TempStopTransaction | Update TempStopTransaction
  15202. // open file for writing
  15203. FILE *outfile;
  15204. outfile = fopen (TempStopTransaction, "a");
  15205. //DEBUG_INFO("data = %s\n", queuedata);
  15206. fputs(queuedata, outfile);
  15207. fputs("\n", outfile);
  15208. fclose (outfile);
  15209. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15210. }
  15211. void checkTempStopTransaction(int gun_index)
  15212. {
  15213. FILE *fptr1;
  15214. char ch;
  15215. char str[QUEUE_MESSAGE_LENGTH]={0};
  15216. char guid[37]={0};
  15217. char tempdata[65]={0};
  15218. char connectorStr[2]={0};
  15219. char TempStopTransaction[256];
  15220. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  15221. fptr1 = fopen(TempStopTransaction, "r");
  15222. //TempStopTransaction格式: 槍號,StopTransaction封包
  15223. if (!fptr1)
  15224. {
  15225. //printf(" File not found or unable to open the input file!!\n");
  15226. return ;
  15227. }
  15228. ch=fgetc(fptr1);
  15229. //printf(" Now the content of the file %s is : \n",fname);
  15230. rewind(fptr1);
  15231. if(ch!=EOF)
  15232. {
  15233. // copy all contents to the temporary file except the specific line
  15234. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  15235. {
  15236. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15237. if(str[0]=='\0')
  15238. {
  15239. break;
  15240. }
  15241. //TempStopTransaction格式: 槍號,StopTransaction封包
  15242. strncpy(connectorStr, str, 1);
  15243. if(atoi(connectorStr) != (gun_index+1))
  15244. {
  15245. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  15246. fclose(fptr1);
  15247. return ;
  15248. }
  15249. //random_uuid(guid);
  15250. strncpy(guid, str+6, 36); //copy guid
  15251. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  15252. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  15253. {
  15254. //DEBUG_INFO("StopTransaction mapitem pass\n");
  15255. }
  15256. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  15257. OCPP_insert_transaction_msg(NO, str);
  15258. memset(str,0,ARRAY_SIZE(str));
  15259. }
  15260. }
  15261. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  15262. fclose(fptr1);
  15263. remove(TempStopTransaction); // remove the original file
  15264. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15265. }
  15266. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  15267. {
  15268. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  15269. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  15270. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  15271. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  15272. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  15273. }
  15274. int GetWebSocketPingInterval(void)
  15275. {
  15276. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15277. }
  15278. int GetServerSign(void)
  15279. {
  15280. return server_sign;
  15281. }
  15282. uint8_t GetOcppSecurityProfile()
  15283. {
  15284. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15285. }
  15286. void GetOcppChargerBoxId(uint8_t *data)
  15287. {
  15288. sprintf((char*)data, "%s", ShmOCPP16Data->ChargeBoxId);
  15289. }
  15290. void GetOcppSecurityPassword(uint8_t *data)
  15291. {
  15292. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15293. }
  15294. void SetOcppVersion(uint8_t *version)
  15295. {
  15296. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  15297. DEBUG_INFO("ocpp version: %s\n", version);
  15298. if(strstr((char*)version, "ocpp1.6") != NULL)
  15299. {
  15300. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  15301. }
  15302. else if(strstr((char*)version, "ocpp2.0") != NULL)
  15303. {
  15304. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  15305. system("pkill OcppBackend");
  15306. }
  15307. }
  15308. void SetServerSign(int value)
  15309. {
  15310. server_sign = value;
  15311. }
  15312. int GetBootNotificationInterval(void)
  15313. {
  15314. return BootNotificationInterval;
  15315. }
  15316. int GetInternetConn(void)
  15317. {
  15318. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  15319. }
  15320. int isConnectorInitMode(int gun_index)
  15321. {
  15322. int tempIndex = 0;
  15323. int result = TRUE;
  15324. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15325. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15326. {
  15327. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15328. {
  15329. tempIndex = ((gun_index==2) ? 1: 0);
  15330. }
  15331. else
  15332. {
  15333. tempIndex = gun_index;
  15334. }
  15335. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15336. {
  15337. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  15338. {
  15339. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15340. } //end of the same index
  15341. }//end of for CHAdeMO_QUANTITY
  15342. }
  15343. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15344. {
  15345. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15346. {
  15347. tempIndex = ((gun_index==2) ? 1: 0);
  15348. }
  15349. else
  15350. {
  15351. tempIndex = gun_index;
  15352. }
  15353. for (int index = 0; index < CCS_QUANTITY; index++)
  15354. {
  15355. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15356. {
  15357. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15358. } //end of the same index
  15359. } // end of for CCS_QUANTITY
  15360. }
  15361. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15362. {
  15363. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15364. {
  15365. tempIndex = ((gun_index==2) ? 1: 0);
  15366. }
  15367. else
  15368. {
  15369. tempIndex = gun_index;
  15370. }
  15371. for (int index = 0; index < GB_QUANTITY; index++)
  15372. {
  15373. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15374. {
  15375. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15376. } //end of the same index
  15377. } // end of for GB_QUANTITY
  15378. }
  15379. else if(gunType[gun_index] == GUN_TYPE_DO)
  15380. {
  15381. tempIndex = gun_index;
  15382. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15383. {
  15384. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15385. {
  15386. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15387. } //end of the same index
  15388. }
  15389. }
  15390. else
  15391. {
  15392. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15393. {
  15394. tempIndex = 2;
  15395. }
  15396. else
  15397. {
  15398. tempIndex = gun_index;
  15399. }
  15400. for (int index = 0; index < AC_QUANTITY; index++)
  15401. {
  15402. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15403. {
  15404. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15405. }//end of the same index
  15406. }//end of for AC_QUANTITY
  15407. }
  15408. return result;
  15409. }
  15410. void refreshProcDogTimer()
  15411. {
  15412. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  15413. }
  15414. void InitialSystemValue(void)
  15415. {
  15416. int connectorIndex = 0;
  15417. //int valueASCII = 0;
  15418. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15419. gunTotalNumber=0;
  15420. SystemInitial = 0;
  15421. localversion=0;
  15422. BootNotificationInterval = 0;
  15423. authorizeRetryTimes = 0;
  15424. GunStatusInterval = 10;
  15425. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15426. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15427. //Hear Beat
  15428. HeartBeatWithNOResponse = 0;
  15429. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  15430. FirstHeartBeat = 0;
  15431. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  15432. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  15433. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  15434. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  15435. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  15436. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  15437. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  15438. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  15439. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  15440. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  15441. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  15442. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  15443. memset(gunType, 0, ARRAY_SIZE(gunType));
  15444. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  15445. {
  15446. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O')
  15447. {
  15448. // DO series
  15449. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  15450. {
  15451. SystemInitial = SystemInitial + 1;
  15452. gunTotalNumber = gunTotalNumber + 1;
  15453. gunType[connectorIndex] = GUN_TYPE_DO;
  15454. connectorIndex = connectorIndex + 1;
  15455. }
  15456. }
  15457. else
  15458. {
  15459. // DM, DW, DS series
  15460. //check connector / socket type (index: 8, 9, 10)
  15461. for(int index=7; index <10 ; index++)
  15462. {
  15463. if(index != 8)
  15464. {
  15465. // DC Connector
  15466. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  15467. {
  15468. SystemInitial = SystemInitial + 1;
  15469. gunTotalNumber = gunTotalNumber + 1;
  15470. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  15471. connectorIndex = connectorIndex + 1;
  15472. }
  15473. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  15474. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  15475. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  15476. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  15477. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  15478. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  15479. {
  15480. SystemInitial = SystemInitial + 1;
  15481. gunTotalNumber = gunTotalNumber + 1;
  15482. gunType[connectorIndex] = GUN_TYPE_CCS;
  15483. connectorIndex = connectorIndex + 1;
  15484. }
  15485. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  15486. {
  15487. SystemInitial = SystemInitial + 1;
  15488. gunTotalNumber = gunTotalNumber + 1;
  15489. gunType[connectorIndex] = GUN_TYPE_GBT;
  15490. connectorIndex = connectorIndex + 1;
  15491. }
  15492. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  15493. {
  15494. SystemInitial = SystemInitial + 1;
  15495. gunTotalNumber = gunTotalNumber + 1;
  15496. gunType[connectorIndex] = GUN_TYPE_DO;
  15497. connectorIndex = connectorIndex + 1;
  15498. }
  15499. }
  15500. else
  15501. {
  15502. // AC Connector
  15503. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15504. {
  15505. SystemInitial = SystemInitial + 1;
  15506. gunTotalNumber = gunTotalNumber + 1;
  15507. gunType[connectorIndex] = GUN_TYPE_AC;
  15508. connectorIndex = connectorIndex + 1;
  15509. }
  15510. }
  15511. }
  15512. }
  15513. //DEBUG_INFO("DC ...\n");
  15514. }
  15515. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  15516. {
  15517. //check connector / socket type (index: 8, 9, 10)
  15518. for(int index=7; index <10 ; index++)
  15519. {
  15520. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15521. {
  15522. SystemInitial = SystemInitial + 1;
  15523. gunTotalNumber = gunTotalNumber + 1;
  15524. gunType[connectorIndex] = GUN_TYPE_AC;
  15525. connectorIndex = connectorIndex + 1;
  15526. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  15527. }
  15528. }
  15529. }
  15530. //Status && ConnectorPlugIn Setting
  15531. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15532. {
  15533. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  15534. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  15535. }
  15536. for (int index = 0; index < CCS_QUANTITY; index++)
  15537. {
  15538. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  15539. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  15540. }
  15541. for (int index = 0; index < GB_QUANTITY; index++)
  15542. {
  15543. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  15544. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  15545. }
  15546. for (int index = 0; index < AC_QUANTITY; index++)
  15547. {
  15548. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  15549. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  15550. }
  15551. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15552. {
  15553. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  15554. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  15555. }
  15556. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  15557. {
  15558. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  15559. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  15560. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  15561. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  15562. }
  15563. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  15564. clientTime.Heartbeat=time((time_t*)NULL);
  15565. sleep(1);
  15566. }
  15567. void LWS_Send(char *str)
  15568. {
  15569. //=====================================================
  15570. // Check InternetConn 0: disconnected, 1: connected
  15571. //====================================================
  15572. if(GetOcppConnStatus() == 0)
  15573. {
  15574. DEBUG_INFO("offline now !!!\n");
  15575. return;
  15576. }
  15577. // Only disable isWebsocketSendable operation initiated by charger
  15578. if((strstr((char*)str, "\"Authorize\"") != NULL)
  15579. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  15580. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  15581. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  15582. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  15583. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  15584. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  15585. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  15586. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  15587. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  15588. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  15589. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  15590. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  15591. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  15592. {
  15593. isWebsocketSendable = 0;
  15594. }
  15595. pthread_mutex_lock(&lock_send);
  15596. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  15597. sprintf((char *)SendBuffer, "%s", str);
  15598. SendBufLen = strlen(str);
  15599. pthread_mutex_unlock(&lock_send);
  15600. lws_callback_on_writable(wsi_client);
  15601. //lws_service(context, 0);
  15602. //sleep(1);
  15603. }
  15604. void LWS_SendNow(char *str)
  15605. {
  15606. //=====================================================
  15607. // Check InternetConn 0: disconnected, 1: connected
  15608. //====================================================
  15609. if(GetOcppConnStatus() == 0)
  15610. {
  15611. DEBUG_INFO("offline now !!!\n");
  15612. return;
  15613. }
  15614. // Only disable isWebsocketSendable operation initiated by charger
  15615. if((strstr((char*)str, "\"Authorize\"") != NULL)
  15616. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  15617. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  15618. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  15619. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  15620. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  15621. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  15622. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  15623. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  15624. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  15625. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  15626. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  15627. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  15628. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  15629. {
  15630. isWebsocketSendable = 0;
  15631. }
  15632. pthread_mutex_lock(&lock_send);
  15633. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  15634. sprintf((char *)SendBuffer, "%s", str);
  15635. SendBufLen = strlen(str);
  15636. pthread_mutex_unlock(&lock_send);
  15637. lws_callback_on_writable(wsi_client);
  15638. lws_service(context, 0);
  15639. //sleep(1);
  15640. }