MessageHandler.c 674 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328
  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. #define TxDefaultProfile_1_JSON "/Storage/OCPP/TxDefaultProfile_1.json"
  8. #define TxDefaultProfile_2_JSON "/Storage/OCPP/TxDefaultProfile_2.json"
  9. //TxProfile
  10. #define TxProfile_1_JSON "/Storage/OCPP/TxProfile_1.json"
  11. #define TxProfile_2_JSON "/Storage/OCPP/TxProfile_2.json"
  12. #define ChargingProfile_0_JSON "/Storage/OCPP/chargingprofile_0.json"
  13. #define ChargingProfile_1_JSON "/Storage/OCPP/chargingprofile_1.json"
  14. #define ChargingProfile_2_JSON "/Storage/OCPP/chargingprofile_2.json"
  15. #define AuthorizationCache_JSON "/Storage/OCPP/AuthorizationCache.json"
  16. #define LocalAuthorizationList_JSON "/Storage/OCPP/LocalAuthorizationList.json"
  17. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  18. struct StatusCodeData *ShmStatusCodeData;
  19. struct PsuData *ShmPsuData ;
  20. struct OCPP16Data *ShmOCPP16Data;
  21. //ConfigurationMaxKeys
  22. #define GetConfigurationMaxKeysNUM 44
  23. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  24. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  25. //=================================
  26. // StatusNotification cycle
  27. //=================================
  28. static int server_cycle_Status = 120;
  29. //===============================
  30. // Configuration: unknownkey
  31. //===============================
  32. static char unknownkey[10][20] = {0};
  33. static int UnknownKeynum = 0;
  34. //===============================
  35. // Gun Total Numbers
  36. //===============================
  37. static int gunTotalNumber = 0;
  38. static uint8_t gunType[4] = {0};
  39. //===============================
  40. // Local List Version
  41. //===============================
  42. static int localversion=0;
  43. static char idTagAuthorization[32] = {0};
  44. //===============================
  45. // OCPP sign variable
  46. //===============================
  47. static int server_sign = FALSE;
  48. int server_pending = FALSE;
  49. static int BootNotificationInterval = 0;
  50. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  51. //===============================
  52. // OCPP auth variable
  53. //===============================
  54. static int authorizeRetryTimes = 0; //number of Retry times
  55. //===============================
  56. // OCPP other variables
  57. //===============================
  58. static int HeartBeatWaitTime = 10;
  59. static int FirstHeartBeat = 0;
  60. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  61. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  62. static char CurrentChargingProfileScheduleStr[30] = {0};
  63. //========================================
  64. // OCPP status/previous related variables
  65. //========================================
  66. static int GunStatusInterval = 10;
  67. static uint8_t statusModeChage[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY] = {FALSE};
  68. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  69. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  70. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  71. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  72. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  73. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  74. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  75. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  76. static int TransactionMessageAttemptsValue = 0;
  77. static int TransactionMessageRetryIntervalValue = 0;
  78. static int TempMeterValueInterval = 0;
  79. static struct OCPPAuthLocalElemet
  80. {
  81. int listVersionInt;
  82. char idTagstr[20];
  83. char parentIdTag[20];
  84. char expiryDate[30];
  85. char idTagstatus[16];
  86. }idTagQuery;
  87. //=============================================
  88. // OCPP HeartBeat Response Not Receive Counts
  89. //============================================
  90. static int HeartBeatWithNOResponse = 0;
  91. static int HeartBeatCountPerHour = 0;
  92. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  93. extern int GetTransactionQueueNum(void);
  94. extern struct Charger_Info Charger;
  95. extern sqlite3 *db;
  96. int TransactionMessageAttemptsGet(void);
  97. int TransactionMessageRetryIntervalGet(void);
  98. int GetOcppConnStatus(void);
  99. void SetOcppConnStatus(uint8_t status);
  100. int setKeyValue(char *key, char *value);
  101. void OCPP_get_TableAuthlocalAllData(void);
  102. void processUnkownKey(void);
  103. struct StructOCPPMeterValue
  104. {
  105. unsigned char TimeStamp[28];
  106. struct StructSampledValue SampledValue[10];
  107. };
  108. struct ClientTime
  109. {
  110. unsigned int Heartbeat;
  111. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  112. unsigned int StartTransaction;
  113. unsigned int StopTransaction;
  114. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  115. }clientTime;
  116. typedef union
  117. {
  118. //Operations Initiated by Central System
  119. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  120. struct
  121. {
  122. //CsMsgValue[0]
  123. unsigned char StatusNotificationReq:1; //bit 0,
  124. unsigned char StatusNotificationConf:1; //bit 1,
  125. unsigned char TriggerMeterValue:1; //bit 2,
  126. unsigned char :5; //bit 5~7
  127. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  128. }CpinitiateMsg;
  129. CpinitiateMsg cpinitateMsg;
  130. //GetConfiguration Array
  131. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  132. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  133. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  134. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  135. #if 0
  136. static char *ChargePointErrorCodeStr[] = {
  137. MACROSTR(ConnectorLockFailure),
  138. MACROSTR(EVCommunicationError),
  139. MACROSTR(GroundFailure),
  140. MACROSTR(HighTemperature),
  141. MACROSTR(InternalError),
  142. MACROSTR(LocalListConflict),
  143. MACROSTR(NoError),
  144. MACROSTR(OtherError),
  145. MACROSTR(OverCurrentFailure),
  146. MACROSTR(OverVoltage),
  147. MACROSTR(PowerMeterFailure),
  148. MACROSTR(PowerSwitchFailure),
  149. MACROSTR(ReaderFailure),
  150. MACROSTR(ResetFailure),
  151. MACROSTR(UnderVoltage),
  152. MACROSTR(WeakSignal)
  153. };
  154. #endif
  155. static char * ChargePointStatusStr[] = {
  156. MACROSTR(Available),
  157. MACROSTR(Preparing),
  158. MACROSTR(Charging),
  159. MACROSTR(SuspendedEVSE),
  160. MACROSTR(SuspendedEV),
  161. MACROSTR(Finishing),
  162. MACROSTR(Reserved),
  163. MACROSTR(Unavailable),
  164. MACROSTR(Faulted)
  165. };
  166. static char *RegistrationStatusStr[] = {
  167. MACROSTR(Accepted),
  168. MACROSTR(Pending),
  169. MACROSTR(Rejected)
  170. };
  171. static char *AvailabilityTypeStr[] = {
  172. MACROSTR(Inoperative),
  173. MACROSTR(Operative)
  174. };
  175. static char *AvailabilityStatusStr[] = {
  176. MACROSTR(Accepted),
  177. MACROSTR(Rejected),
  178. MACROSTR(Scheduled)
  179. };
  180. static char *ConfigurationStatusStr[] = {
  181. MACROSTR(Accepted),
  182. MACROSTR(Rejected),
  183. MACROSTR(RebootRequired),
  184. MACROSTR(NotSupported)
  185. };
  186. static char *ClearCacheStatusStr[] = {
  187. MACROSTR(Accepted),
  188. MACROSTR(Rejected)
  189. };
  190. static char *ChargingProfilePurposeTypeStr[] = {
  191. MACROSTR(ChargePointMaxProfile),
  192. MACROSTR(TxDefaultProfile),
  193. MACROSTR(TxProfile)
  194. };
  195. static char *ChargingProfileStatusStr[] = {
  196. MACROSTR(Accepted),
  197. MACROSTR(Rejected),
  198. MACROSTR(NotSupported)
  199. };
  200. static char *ClearChargingProfileStatusStr[] = {
  201. MACROSTR(Accepted),
  202. MACROSTR(Unknown)
  203. };
  204. static char *GetCompositeScheduleStatusStr[] = {
  205. MACROSTR(Accepted),
  206. MACROSTR(Rejected)
  207. };
  208. static char *UpdateTypeStr[] = {
  209. MACROSTR(Differential),
  210. MACROSTR(Full)
  211. };
  212. static char *UpdateStatusStr[] = {
  213. MACROSTR(Accepted),
  214. MACROSTR(Failed),
  215. MACROSTR(NotSupported),
  216. MACROSTR(VersionMismatch)
  217. };
  218. static char *RemoteStartStopStatusStr[] = {
  219. MACROSTR(Accepted),
  220. MACROSTR(Rejected)
  221. };
  222. static char *ReservationStatusStr[] = {
  223. MACROSTR(Accepted),
  224. MACROSTR(Faulted),
  225. MACROSTR(Occupied),
  226. MACROSTR(Rejected),
  227. MACROSTR(Unavailable)
  228. };
  229. static char *ResetTypeStr[] = {
  230. MACROSTR(Hard),
  231. MACROSTR(Soft)
  232. };
  233. static char *ResetStatusStr[] = {
  234. MACROSTR(Accepted),
  235. MACROSTR(Rejected)
  236. };
  237. static char * DiagnosticsStatusStr[] = {
  238. MACROSTR(Idle),
  239. MACROSTR(Uploaded),
  240. MACROSTR(UploadFailed),
  241. MACROSTR(Uploading)
  242. };
  243. static char * FirmwareStatusStr[] = {
  244. MACROSTR(Downloaded),
  245. MACROSTR(DownloadFailed),
  246. MACROSTR(Downloading),
  247. MACROSTR(Idle),
  248. MACROSTR(InstallationFailed),
  249. MACROSTR(Installing),
  250. MACROSTR(Installed)
  251. };
  252. static char * MessageTriggerStr[] = {
  253. MACROSTR(BootNotification),
  254. MACROSTR(DiagnosticsStatusNotification),
  255. MACROSTR(FirmwareStatusNotification),
  256. MACROSTR(Heartbeat),
  257. MACROSTR(MeterValues),
  258. MACROSTR(StatusNotification)
  259. };
  260. static char * TriggerMessageStatusStr[] = {
  261. MACROSTR(Accepted),
  262. MACROSTR(Rejected),
  263. MACROSTR(NotImplemented)
  264. };
  265. static char * UnlockStatusStr[] = {
  266. MACROSTR(Unlocked),
  267. MACROSTR(UnlockFailed),
  268. MACROSTR(NotSupported)
  269. };
  270. #if 0
  271. static char * StopTransactionReasonStr[] = {
  272. MACROSTR(EmergencyStop),
  273. MACROSTR(EVDisconnected),
  274. MACROSTR(HardReset),
  275. MACROSTR(Local),
  276. MACROSTR(Other),
  277. MACROSTR(PowerLoss),
  278. MACROSTR(Reboot),
  279. MACROSTR(Remote),
  280. MACROSTR(SoftReset),
  281. MACROSTR(UnlockCommand),
  282. MACROSTR(DeAuthorized)
  283. };
  284. #endif
  285. static char * CancelReservationStatusStr[] = {
  286. MACROSTR(Accepted),
  287. MACROSTR(Rejected)
  288. };
  289. static char * ReadingContextStr[] = {
  290. MACROSTR(Interruption.Begin),
  291. MACROSTR(Interruption.End),
  292. MACROSTR(Other),
  293. MACROSTR(Sample.Clock),
  294. MACROSTR(Sample.Periodic),
  295. MACROSTR(Transaction.Begin),
  296. MACROSTR(Transaction.End),
  297. MACROSTR(Trigger)
  298. };
  299. static char * ValueFormatStr[] = {
  300. MACROSTR(Raw),
  301. MACROSTR(SignedData)
  302. };
  303. static char * MeasurandStr[] = {
  304. MACROSTR(Current.Export),
  305. MACROSTR(Current.Import),
  306. MACROSTR(Current.Offered),
  307. MACROSTR(Energy.Active.Export.Register),
  308. MACROSTR(Energy.Active.Import.Register),
  309. MACROSTR(Energy.Reactive.Export.Register),
  310. MACROSTR(Energy.Reactive.Import.Register),
  311. MACROSTR(Energy.Active.Export.Interval),
  312. MACROSTR(Energy.Active.Import.Interval),
  313. MACROSTR(Energy.Reactive.Export.Interval),
  314. MACROSTR(Energy.Reactive.Import.Interval),
  315. MACROSTR(Frequency),
  316. MACROSTR(Power.Active.Export),
  317. MACROSTR(Power.Active.Import),
  318. MACROSTR(Power.Factor),
  319. MACROSTR(Power.Offered),
  320. MACROSTR(Power.Reactive.ExportMACROSTR),
  321. MACROSTR(Power.Reactive.Import),
  322. MACROSTR(RPM),
  323. MACROSTR(SoC),
  324. MACROSTR(Temperature),
  325. MACROSTR(Voltage)
  326. };
  327. static char * LocationStr[] = {
  328. MACROSTR(Body),
  329. MACROSTR(Cable),
  330. MACROSTR(EV),
  331. MACROSTR(Inlet),
  332. MACROSTR(Outlet)
  333. };
  334. static char * PhaseStr[] = {
  335. MACROSTR(L1),
  336. MACROSTR(L2),
  337. MACROSTR(L3),
  338. MACROSTR(N),
  339. MACROSTR(L1-N),
  340. MACROSTR(L2-N),
  341. MACROSTR(L3-N),
  342. MACROSTR(L1-L2),
  343. MACROSTR(L2-L3),
  344. MACROSTR(L3-L1)
  345. };
  346. static char * UnitOfMeasureStr[] = {
  347. MACROSTR(Wh),
  348. MACROSTR(kWh),
  349. MACROSTR(varh),
  350. MACROSTR(kvarh),
  351. MACROSTR(W),
  352. MACROSTR(kW),
  353. MACROSTR(VA),
  354. MACROSTR(kVA),
  355. MACROSTR(var),
  356. MACROSTR(kvar),
  357. MACROSTR(A),
  358. MACROSTR(V),
  359. MACROSTR(Celsius),
  360. MACROSTR(Fahrenheit),
  361. MACROSTR(K),
  362. MACROSTR(Percent)
  363. };
  364. //==========================================
  365. // Check time passed since today
  366. //==========================================
  367. long long DiffTimebWithNow(struct timeb ST)
  368. {
  369. //return milli-second
  370. struct timeb ET;
  371. long long StartTime,StopTime;
  372. ftime(&ET);
  373. StartTime=(long long)ST.time;
  374. StopTime=(long long)ET.time;
  375. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  376. }
  377. int getTimePassSinceToday()
  378. {
  379. int result = -1;
  380. time_t t;
  381. struct tm *tmStartToday;
  382. struct timeb tbStartToday;
  383. t=time(NULL);
  384. tmStartToday=localtime(&t);
  385. tmStartToday->tm_hour = 0;
  386. tmStartToday->tm_min = 0;
  387. tmStartToday->tm_sec = 0;
  388. tbStartToday.time = mktime(tmStartToday);
  389. tbStartToday.millitm = 0;
  390. result = DiffTimebWithNow(tbStartToday)/1000;
  391. return result;
  392. }
  393. //==========================================
  394. // GetCompositeSchedule logic related function
  395. //==========================================
  396. int DiffTimebSec(struct timeb ST, struct timeb ET)
  397. {
  398. //return milli-second
  399. unsigned int StartTime,StopTime;
  400. StartTime=(unsigned int)ST.time;
  401. StopTime=(unsigned int)ET.time;
  402. return (StopTime-StartTime);
  403. }
  404. int DiffTimebWithNowSec(struct timeb ST)
  405. {
  406. //return milli-second
  407. struct timeb ET;
  408. unsigned int StartTime,StopTime;
  409. ftime(&ET);
  410. StartTime=(unsigned int)ST.time;
  411. StopTime=(unsigned int)ET.time;
  412. return (StopTime-StartTime);
  413. }
  414. int getStartStop(uint8_t *start, uint8_t *stop)
  415. {
  416. int result = -1;
  417. struct tm tmStart;
  418. struct timeb tbStart;
  419. struct tm tmStop;
  420. struct timeb tbStop;
  421. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  422. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  423. {
  424. tmStart.tm_year -= 1900;
  425. tmStart.tm_mon -= 1;
  426. tbStart.time = mktime(&tmStart);
  427. tbStart.millitm = 0;
  428. tmStop.tm_year -= 1900;
  429. tmStop.tm_mon -= 1;
  430. tbStop.time = mktime(&tmStop);
  431. tbStop.millitm = 0;
  432. result = DiffTimebSec(tbStart, tbStop);
  433. }
  434. else
  435. {
  436. DEBUG_WARN("Start or stop date parsing error.\r\n");
  437. }
  438. return result;
  439. }
  440. int getStartSinceToday(uint8_t *stop)
  441. {
  442. int result = -1;
  443. time_t t;
  444. struct tm *tmStartToday;
  445. struct timeb tbStartToday;
  446. struct tm tmStop;
  447. struct timeb tbStop;
  448. if((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))
  449. {
  450. t=time(NULL);
  451. tmStartToday=localtime(&t);
  452. tmStartToday->tm_hour = 0;
  453. tmStartToday->tm_min = 0;
  454. tmStartToday->tm_sec = 0;
  455. tbStartToday.time = mktime(tmStartToday);
  456. tmStop.tm_year -= 1900;
  457. tmStop.tm_mon -= 1;
  458. tbStop.time = mktime(&tmStop);
  459. tbStop.millitm = 0;
  460. result = DiffTimebSec(tbStartToday, tbStop);
  461. }
  462. return result;
  463. }
  464. int getStartSinceWeek(uint8_t *stop)
  465. {
  466. int result = -1;
  467. time_t t;
  468. struct tm *tmStartWeek;
  469. struct timeb tbStartWeek;
  470. struct tm tmStop;
  471. struct timeb tbStop;
  472. if((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))
  473. {
  474. t=time(NULL);
  475. tmStartWeek=localtime(&t);
  476. t-=86400*tmStartWeek->tm_wday;
  477. tmStartWeek=localtime(&t);
  478. tmStartWeek->tm_hour = 0;
  479. tmStartWeek->tm_min = 0;
  480. tmStartWeek->tm_sec = 0;
  481. tbStartWeek.time = mktime(tmStartWeek);
  482. tmStop.tm_year -= 1900;
  483. tmStop.tm_mon -= 1;
  484. tbStop.time = mktime(&tmStop);
  485. tbStop.millitm = 0;
  486. result = DiffTimebSec(tbStartWeek, tbStop);
  487. }
  488. return result;
  489. }
  490. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile)
  491. {
  492. FILE *fp;
  493. char profileFileName[128];
  494. char *line = NULL;
  495. size_t len = 0;
  496. time_t CurrentTime;
  497. struct tm *tmComposite;
  498. struct StructChargingProfile maxProfile;
  499. struct StructChargingProfile defaultTxProfile;
  500. struct StructChargingProfile txProfile;
  501. struct StructChargingSchedulePeriod tmpPeriod;
  502. uint8_t limitMax=0;
  503. uint8_t limitDef=0;
  504. uint8_t limitTx=0;
  505. int compositePeriodIdx = 0;
  506. CurrentTime = time(NULL);
  507. tmComposite=localtime(&CurrentTime);
  508. 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);
  509. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  510. compositeProfile->ChargingSchedule.Duration = durationReq;
  511. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  512. {
  513. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  514. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  515. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  516. }
  517. compositeProfile->ChargingProfileId = 0;
  518. compositeProfile->StackLevel = 99 ;
  519. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  520. maxProfile.ChargingProfileId = -1;
  521. defaultTxProfile.ChargingProfileId = -1;
  522. txProfile.ChargingProfileId = -1;
  523. system("yes|rm /tmp/*.json");
  524. system("cp /Storage/OCPP/*.json /tmp");
  525. /*
  526. * Search valid charging profile
  527. */
  528. //DEBUG_INFO("====================================\n");
  529. // Search tx profile
  530. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  531. if((access(profileFileName, F_OK))!=-1)
  532. {
  533. fp = fopen(profileFileName, "r");
  534. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  535. {
  536. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  537. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  538. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  539. }
  540. txProfile.ChargingProfileId = -1;
  541. txProfile.StackLevel = -1;
  542. while(getline(&line, &len, fp) != -1)
  543. {
  544. json_object *obj = NULL;
  545. obj = json_tokener_parse(line);
  546. if(is_error(obj))
  547. {
  548. DEBUG_ERROR("Parse txProfile from file error.\n");
  549. }
  550. else
  551. {
  552. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  553. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  554. )
  555. {
  556. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  557. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  558. )
  559. {
  560. struct tm tmFrom, tmTo;
  561. struct timeb tbFrom, tbTo;
  562. 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) &&
  563. (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))
  564. {
  565. tmFrom.tm_year -= 1900;
  566. tmFrom.tm_mon -= 1;
  567. tbFrom.time = mktime(&tmFrom);
  568. tmTo.tm_year -= 1900;
  569. tmTo.tm_mon -= 1;
  570. tbTo.time = mktime(&tmTo);
  571. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  572. {
  573. if(txProfile.ChargingProfileId == -1)
  574. DEBUG_INFO("TxProfile found.\n");
  575. else
  576. DEBUG_INFO("TxProfile updated.\n");
  577. // Required item
  578. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  579. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  580. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  581. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  582. 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++)
  583. {
  584. 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"));
  585. 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: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")));
  586. 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?
  587. 3:
  588. 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")));
  589. }
  590. // Optional item
  591. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  592. {
  593. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  594. }
  595. else
  596. {
  597. sprintf((char*)txProfile.ValidFrom, " ");
  598. }
  599. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  600. {
  601. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  602. }
  603. else
  604. {
  605. sprintf((char*)txProfile.ValidTo, " ");
  606. }
  607. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  608. {
  609. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  610. }
  611. else
  612. {
  613. sprintf((char*)txProfile.RecurrencyKind, " ");
  614. }
  615. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  616. {
  617. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  618. }
  619. else
  620. {
  621. txProfile.TransactionId = -1;
  622. }
  623. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  624. {
  625. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  626. }
  627. else
  628. {
  629. txProfile.ChargingSchedule.Duration = 86400;
  630. }
  631. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  632. {
  633. 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")));
  634. }
  635. else
  636. {
  637. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, " ");
  638. }
  639. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  640. {
  641. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  642. }
  643. else
  644. {
  645. txProfile.ChargingSchedule.MinChargingRate = -1;
  646. }
  647. }
  648. }
  649. }
  650. else
  651. {
  652. if(txProfile.ChargingProfileId == -1)
  653. DEBUG_INFO("TxProfile found.\n");
  654. else
  655. DEBUG_INFO("TxProfile updated.\n");
  656. // Required item
  657. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  658. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  659. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  660. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  661. 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++)
  662. {
  663. 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"));
  664. 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: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")));
  665. 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?
  666. 3:
  667. 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")));
  668. }
  669. // Optional item
  670. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  671. {
  672. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  673. }
  674. else
  675. {
  676. sprintf((char*)txProfile.ValidFrom, " ");
  677. }
  678. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  679. {
  680. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  681. }
  682. else
  683. {
  684. sprintf((char*)txProfile.ValidTo, " ");
  685. }
  686. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  687. {
  688. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  689. }
  690. else
  691. {
  692. sprintf((char*)txProfile.RecurrencyKind, " ");
  693. }
  694. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  695. {
  696. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  697. }
  698. else
  699. {
  700. txProfile.TransactionId = -1;
  701. }
  702. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  703. {
  704. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  705. }
  706. else
  707. {
  708. txProfile.ChargingSchedule.Duration = 86400;
  709. }
  710. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  711. {
  712. 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")));
  713. }
  714. else
  715. {
  716. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, " ");
  717. }
  718. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  719. {
  720. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  721. }
  722. else
  723. {
  724. maxProfile.ChargingSchedule.MinChargingRate = -1;
  725. }
  726. }
  727. }
  728. }
  729. json_object_put(obj);
  730. }
  731. fclose(fp);
  732. /*
  733. if(defaultTxProfile.ChargingProfileId != -1)
  734. {
  735. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  736. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  737. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  738. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  739. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  740. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  741. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  742. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  743. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  744. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  745. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  746. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  747. {
  748. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  749. {
  750. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  751. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  752. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  753. }
  754. }
  755. }
  756. else
  757. DEBUG_INFO("TxProfile not found.\n");*/
  758. }
  759. // Search default tx profile
  760. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  761. if((access(profileFileName, F_OK))==-1)
  762. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  763. if((access(profileFileName, F_OK))!=-1)
  764. {
  765. fp = fopen(profileFileName, "r");
  766. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  767. {
  768. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  769. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  770. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  771. }
  772. defaultTxProfile.ChargingProfileId = -1;
  773. defaultTxProfile.StackLevel = -1;
  774. while(getline(&line, &len, fp) != -1)
  775. {
  776. json_object *obj = NULL;
  777. obj = json_tokener_parse(line);
  778. if(is_error(obj))
  779. {
  780. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  781. }
  782. else
  783. {
  784. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  785. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  786. )
  787. {
  788. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  789. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  790. )
  791. {
  792. struct tm tmFrom, tmTo;
  793. struct timeb tbFrom, tbTo;
  794. 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) &&
  795. (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))
  796. {
  797. tmFrom.tm_year -= 1900;
  798. tmFrom.tm_mon -= 1;
  799. tbFrom.time = mktime(&tmFrom);
  800. tmTo.tm_year -= 1900;
  801. tmTo.tm_mon -= 1;
  802. tbTo.time = mktime(&tmTo);
  803. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  804. {
  805. if(defaultTxProfile.ChargingProfileId == -1)
  806. DEBUG_INFO("TxDefaultProfile found.\n");
  807. else
  808. DEBUG_INFO("TxDefaultProfile updated.\n");
  809. // Required item
  810. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  811. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  812. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  813. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  814. 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++)
  815. {
  816. 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"));
  817. 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: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")));
  818. 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?
  819. 3:
  820. 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")));
  821. }
  822. // Optional item
  823. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  824. {
  825. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  826. }
  827. else
  828. {
  829. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  830. }
  831. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  832. {
  833. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  834. }
  835. else
  836. {
  837. sprintf((char*)defaultTxProfile.ValidTo, " ");
  838. }
  839. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  840. {
  841. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  842. }
  843. else
  844. {
  845. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  846. }
  847. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  848. {
  849. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  850. }
  851. else
  852. {
  853. defaultTxProfile.TransactionId = -1;
  854. }
  855. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  856. {
  857. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  858. }
  859. else
  860. {
  861. defaultTxProfile.ChargingSchedule.Duration = 86400;
  862. }
  863. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  864. {
  865. 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")));
  866. }
  867. else
  868. {
  869. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, " ");
  870. }
  871. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  872. {
  873. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  874. }
  875. else
  876. {
  877. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  878. }
  879. }
  880. }
  881. }
  882. else
  883. {
  884. if(defaultTxProfile.ChargingProfileId == -1)
  885. DEBUG_INFO("TxDefaultProfile found.\n");
  886. else
  887. DEBUG_INFO("TxDefaultProfile updated.\n");
  888. // Required item
  889. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  890. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  891. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  892. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  893. 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++)
  894. {
  895. 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"));
  896. 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: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")));
  897. 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?
  898. 3:
  899. 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")));
  900. }
  901. // Optional item
  902. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  903. {
  904. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  905. }
  906. else
  907. {
  908. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  909. }
  910. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  911. {
  912. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  913. }
  914. else
  915. {
  916. sprintf((char*)defaultTxProfile.ValidTo, " ");
  917. }
  918. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  919. {
  920. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  921. }
  922. else
  923. {
  924. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  925. }
  926. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  927. {
  928. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  929. }
  930. else
  931. {
  932. defaultTxProfile.TransactionId = -1;
  933. }
  934. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  935. {
  936. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  937. }
  938. else
  939. {
  940. defaultTxProfile.ChargingSchedule.Duration = 86400;
  941. }
  942. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  943. {
  944. 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")));
  945. }
  946. else
  947. {
  948. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, " ");
  949. }
  950. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  951. {
  952. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  953. }
  954. else
  955. {
  956. maxProfile.ChargingSchedule.MinChargingRate = -1;
  957. }
  958. }
  959. }
  960. }
  961. json_object_put(obj);
  962. }
  963. fclose(fp);
  964. /*
  965. if(defaultTxProfile.ChargingProfileId != -1)
  966. {
  967. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  968. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  969. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  970. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  971. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  972. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  973. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  974. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  975. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  976. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  977. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  978. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  979. {
  980. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  981. {
  982. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  983. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  984. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  985. }
  986. }
  987. }
  988. else
  989. DEBUG_INFO("TxDefaultProfile not found.\n");
  990. DEBUG_INFO("------------------------------------\n");*/
  991. }
  992. // Search max profile
  993. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  994. if((access(profileFileName, F_OK))!=-1)
  995. {
  996. fp = fopen(profileFileName, "r");
  997. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  998. {
  999. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1000. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1001. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1002. }
  1003. maxProfile.ChargingProfileId = -1;
  1004. maxProfile.StackLevel = -1;
  1005. while(getline(&line, &len, fp) != -1)
  1006. {
  1007. json_object *obj = NULL;
  1008. obj = json_tokener_parse(line);
  1009. if(is_error(obj))
  1010. {
  1011. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1012. }
  1013. else
  1014. {
  1015. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1016. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1017. )
  1018. {
  1019. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1020. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1021. )
  1022. {
  1023. struct tm tmFrom, tmTo;
  1024. struct timeb tbFrom, tbTo;
  1025. 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) &&
  1026. (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))
  1027. {
  1028. tmFrom.tm_year -= 1900;
  1029. tmFrom.tm_mon -= 1;
  1030. tbFrom.time = mktime(&tmFrom);
  1031. tmTo.tm_year -= 1900;
  1032. tmTo.tm_mon -= 1;
  1033. tbTo.time = mktime(&tmTo);
  1034. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1035. {
  1036. if(maxProfile.ChargingProfileId == -1)
  1037. DEBUG_INFO("MaxProfile found.\n");
  1038. else
  1039. DEBUG_INFO("MaxProfile updated.\n");
  1040. // Required item
  1041. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1042. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1043. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1044. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1045. 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++)
  1046. {
  1047. 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"));
  1048. 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: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")));
  1049. 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?
  1050. 3:
  1051. 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")));
  1052. }
  1053. // Optional item
  1054. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1055. {
  1056. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1057. }
  1058. else
  1059. {
  1060. sprintf((char*)maxProfile.ValidFrom, " ");
  1061. }
  1062. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1063. {
  1064. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1065. }
  1066. else
  1067. {
  1068. sprintf((char*)maxProfile.ValidTo, " ");
  1069. }
  1070. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1071. {
  1072. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1073. }
  1074. else
  1075. {
  1076. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1077. }
  1078. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1079. {
  1080. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1081. }
  1082. else
  1083. {
  1084. maxProfile.TransactionId = -1;
  1085. }
  1086. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1087. {
  1088. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1089. }
  1090. else
  1091. {
  1092. maxProfile.ChargingSchedule.Duration = 86400;
  1093. }
  1094. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1095. {
  1096. 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")));
  1097. }
  1098. else
  1099. {
  1100. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, " ");
  1101. }
  1102. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1103. {
  1104. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1105. }
  1106. else
  1107. {
  1108. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1109. }
  1110. }
  1111. }
  1112. }
  1113. else
  1114. {
  1115. if(maxProfile.ChargingProfileId == -1)
  1116. DEBUG_INFO("MaxProfile found.\n");
  1117. else
  1118. DEBUG_INFO("MaxProfile updated.\n");
  1119. // Required item
  1120. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1121. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1122. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1123. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1124. 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++)
  1125. {
  1126. 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"));
  1127. 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: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")));
  1128. 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?
  1129. 3:
  1130. 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")));
  1131. }
  1132. // Optional item
  1133. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1134. {
  1135. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1136. }
  1137. else
  1138. {
  1139. sprintf((char*)maxProfile.ValidFrom, " ");
  1140. }
  1141. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1142. {
  1143. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1144. }
  1145. else
  1146. {
  1147. sprintf((char*)maxProfile.ValidTo, " ");
  1148. }
  1149. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1150. {
  1151. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1152. }
  1153. else
  1154. {
  1155. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1156. }
  1157. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1158. {
  1159. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1160. }
  1161. else
  1162. {
  1163. maxProfile.TransactionId = -1;
  1164. }
  1165. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1166. {
  1167. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1168. }
  1169. else
  1170. {
  1171. maxProfile.ChargingSchedule.Duration = 86400;
  1172. }
  1173. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1174. {
  1175. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1176. }
  1177. else
  1178. {
  1179. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, " ");
  1180. }
  1181. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1182. {
  1183. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1184. }
  1185. else
  1186. {
  1187. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1188. }
  1189. }
  1190. }
  1191. }
  1192. json_object_put(obj);
  1193. }
  1194. fclose(fp);
  1195. /*
  1196. if(maxProfile.ChargingProfileId !=-1)
  1197. {
  1198. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1199. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1200. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1201. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1202. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1203. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1204. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1205. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1206. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1207. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1208. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1209. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1210. {
  1211. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1212. {
  1213. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1214. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1215. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1216. }
  1217. }
  1218. }
  1219. else
  1220. DEBUG_INFO("MaxProfile not found.\n");
  1221. DEBUG_INFO("------------------------------------\n");*/
  1222. }
  1223. /*
  1224. * Align found profile start schedule & periods
  1225. */
  1226. //DEBUG_INFO("====================================\n");
  1227. /*
  1228. // For local test usage, force modify found profile start schedule info
  1229. 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);
  1230. 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);
  1231. 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);
  1232. */
  1233. if(txProfile.ChargingProfileId != -1)
  1234. {
  1235. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1236. {
  1237. if(txProfile.ChargingSchedule.Duration != -1)
  1238. {
  1239. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1240. 0:
  1241. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1242. }
  1243. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1244. {
  1245. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1246. {
  1247. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1248. 0:
  1249. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1250. if(idxPeriod > 0)
  1251. {
  1252. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1253. {
  1254. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit;
  1255. }
  1256. }
  1257. }
  1258. }
  1259. }
  1260. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1261. {
  1262. if(txProfile.ChargingSchedule.Duration != -1)
  1263. {
  1264. 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?
  1265. 0:
  1266. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1267. }
  1268. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1269. {
  1270. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1271. {
  1272. 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?
  1273. 0:
  1274. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1275. if(idxPeriod > 0)
  1276. {
  1277. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1278. {
  1279. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit;
  1280. }
  1281. }
  1282. }
  1283. }
  1284. }
  1285. else
  1286. {
  1287. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1288. {
  1289. if(txProfile.ChargingSchedule.Duration != -1)
  1290. {
  1291. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1292. 0:
  1293. (txProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1294. }
  1295. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1296. {
  1297. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1298. {
  1299. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1300. 0:
  1301. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1302. if(idxPeriod > 0)
  1303. {
  1304. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1305. {
  1306. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit;
  1307. }
  1308. }
  1309. }
  1310. }
  1311. }
  1312. else
  1313. {
  1314. if(txProfile.ChargingSchedule.Duration != -1)
  1315. {
  1316. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1317. 0:
  1318. (txProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1319. }
  1320. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1321. {
  1322. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1323. {
  1324. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1325. 0:
  1326. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1327. if(idxPeriod > 0)
  1328. {
  1329. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1330. {
  1331. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit;
  1332. }
  1333. }
  1334. }
  1335. }
  1336. }
  1337. }
  1338. /*
  1339. DEBUG_INFO("txProfile after align.\n");
  1340. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1341. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1342. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1343. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1344. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1345. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1346. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1347. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1348. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1349. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1350. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1351. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1352. {
  1353. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1354. {
  1355. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1356. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1357. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1358. }
  1359. }*/
  1360. }
  1361. if(defaultTxProfile.ChargingProfileId != -1)
  1362. {
  1363. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1364. {
  1365. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1366. {
  1367. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1368. 0:
  1369. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1370. }
  1371. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1372. {
  1373. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1374. {
  1375. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1376. 0:
  1377. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1378. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1379. {
  1380. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1381. }
  1382. if(idxPeriod > 0)
  1383. {
  1384. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1385. {
  1386. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit;
  1387. }
  1388. }
  1389. }
  1390. }
  1391. }
  1392. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1393. {
  1394. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1395. {
  1396. 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?
  1397. 0:
  1398. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1399. }
  1400. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1401. {
  1402. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1403. {
  1404. 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?
  1405. 0:
  1406. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1407. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1408. {
  1409. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1410. }
  1411. if(idxPeriod > 0)
  1412. {
  1413. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1414. {
  1415. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit;
  1416. }
  1417. }
  1418. }
  1419. }
  1420. }
  1421. else
  1422. {
  1423. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1424. {
  1425. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1426. {
  1427. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1428. 0:
  1429. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1430. }
  1431. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1432. {
  1433. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1434. {
  1435. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1436. 0:
  1437. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1438. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1439. {
  1440. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1441. }
  1442. if(idxPeriod > 0)
  1443. {
  1444. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1445. {
  1446. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit;
  1447. }
  1448. }
  1449. }
  1450. }
  1451. }
  1452. else
  1453. {
  1454. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1455. {
  1456. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1457. 0:
  1458. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1459. }
  1460. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1461. {
  1462. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1463. {
  1464. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1465. 0:
  1466. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1467. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1468. {
  1469. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1470. }
  1471. if(idxPeriod > 0)
  1472. {
  1473. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1474. {
  1475. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit;
  1476. }
  1477. }
  1478. }
  1479. }
  1480. }
  1481. }
  1482. /*
  1483. DEBUG_INFO("defaultTxProfile after align.\n");
  1484. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1485. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1486. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1487. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1488. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1489. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1490. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1491. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1492. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1493. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1494. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1495. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1496. {
  1497. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1498. {
  1499. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1500. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1501. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1502. }
  1503. }
  1504. DEBUG_INFO("------------------------------------\n");*/
  1505. }
  1506. if(maxProfile.ChargingProfileId != -1)
  1507. {
  1508. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1509. {
  1510. if(maxProfile.ChargingSchedule.Duration != -1)
  1511. {
  1512. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1513. 0:
  1514. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1515. }
  1516. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1517. {
  1518. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1519. {
  1520. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1521. 0:
  1522. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1523. if(idxPeriod > 0)
  1524. {
  1525. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1526. {
  1527. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit;
  1528. }
  1529. }
  1530. }
  1531. }
  1532. }
  1533. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1534. {
  1535. if(maxProfile.ChargingSchedule.Duration != -1)
  1536. {
  1537. 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?
  1538. 0:
  1539. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1540. }
  1541. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1542. {
  1543. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1544. {
  1545. 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?
  1546. 0:
  1547. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1548. if(idxPeriod > 0)
  1549. {
  1550. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1551. {
  1552. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit;
  1553. }
  1554. }
  1555. }
  1556. }
  1557. }
  1558. else
  1559. {
  1560. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1561. {
  1562. if(maxProfile.ChargingSchedule.Duration != -1)
  1563. {
  1564. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1565. 0:
  1566. (maxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1567. }
  1568. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1569. {
  1570. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1571. {
  1572. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1573. 0:
  1574. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1575. if(idxPeriod > 0)
  1576. {
  1577. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1578. {
  1579. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit;
  1580. }
  1581. }
  1582. }
  1583. }
  1584. }
  1585. else
  1586. {
  1587. if(maxProfile.ChargingSchedule.Duration != -1)
  1588. {
  1589. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1590. 0:
  1591. (maxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1592. }
  1593. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1594. {
  1595. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1596. {
  1597. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1598. 0:
  1599. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1600. if(idxPeriod > 0)
  1601. {
  1602. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1603. {
  1604. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit;
  1605. }
  1606. }
  1607. }
  1608. }
  1609. }
  1610. }
  1611. /*
  1612. DEBUG_INFO("MaxProfile after align.\n");
  1613. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1614. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1615. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1616. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1617. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1618. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1619. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1620. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1621. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1622. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1623. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1624. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1625. {
  1626. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1627. {
  1628. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1629. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1630. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1631. }
  1632. }
  1633. DEBUG_INFO("------------------------------------\n");*/
  1634. }
  1635. /*
  1636. * Merge to conposite schedule
  1637. */
  1638. //DEBUG_INFO("====================================\n");
  1639. // Find each profile period quantity
  1640. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1641. {
  1642. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1643. limitMax = idx+1;
  1644. }
  1645. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1646. {
  1647. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1648. limitDef = idx+1;
  1649. }
  1650. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1651. {
  1652. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1653. limitTx = idx+1;
  1654. }
  1655. // TxProfile found, composite schedule based on it
  1656. if(txProfile.ChargingProfileId != -1)
  1657. {
  1658. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  1659. {
  1660. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  1661. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  1662. (txProfile.ChargingSchedule.Duration > 0))
  1663. {
  1664. if(maxProfile.ChargingProfileId != -1)
  1665. {
  1666. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1667. {
  1668. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  1669. {
  1670. if((maxProfile.ChargingSchedule.Duration > 0))
  1671. {
  1672. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1673. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1674. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1675. }
  1676. else
  1677. {
  1678. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1679. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1680. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  1681. }
  1682. }
  1683. if(idxMaxPeriod == (limitMax-1))
  1684. {
  1685. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1686. {
  1687. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1688. {
  1689. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1690. compositePeriodIdx++;
  1691. }
  1692. else
  1693. {
  1694. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1695. }
  1696. }
  1697. }
  1698. }
  1699. }
  1700. else
  1701. {
  1702. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1703. {
  1704. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1705. compositePeriodIdx++;
  1706. }
  1707. else
  1708. {
  1709. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1710. }
  1711. }
  1712. }
  1713. if(idxTxPeriod == (limitTx-1))
  1714. {
  1715. if(defaultTxProfile.ChargingProfileId != -1)
  1716. {
  1717. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1718. {
  1719. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  1720. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  1721. (defaultTxProfile.ChargingSchedule.Duration>0))
  1722. {
  1723. if(maxProfile.ChargingProfileId != -1)
  1724. {
  1725. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1726. {
  1727. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1728. {
  1729. if((maxProfile.ChargingSchedule.Duration > 0))
  1730. {
  1731. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1732. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1733. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1734. }
  1735. else
  1736. {
  1737. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1738. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1739. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  1740. }
  1741. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1742. {
  1743. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1744. {
  1745. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1746. compositePeriodIdx++;
  1747. }
  1748. else
  1749. {
  1750. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1751. }
  1752. }
  1753. break;
  1754. }
  1755. }
  1756. }
  1757. else
  1758. {
  1759. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1760. {
  1761. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1762. compositePeriodIdx++;
  1763. }
  1764. else
  1765. {
  1766. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1767. }
  1768. }
  1769. }
  1770. }
  1771. }
  1772. }
  1773. }
  1774. }
  1775. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  1776. else if(defaultTxProfile.ChargingProfileId != -1)
  1777. {
  1778. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1779. {
  1780. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  1781. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  1782. (defaultTxProfile.ChargingSchedule.Duration > 0))
  1783. {
  1784. if(maxProfile.ChargingProfileId != -1)
  1785. {
  1786. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1787. {
  1788. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1789. {
  1790. if((maxProfile.ChargingSchedule.Duration > 0))
  1791. {
  1792. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1793. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1794. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  1795. }
  1796. else
  1797. {
  1798. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1799. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1800. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  1801. }
  1802. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1803. {
  1804. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1805. {
  1806. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1807. compositePeriodIdx++;
  1808. }
  1809. else
  1810. {
  1811. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1812. }
  1813. }
  1814. break;
  1815. }
  1816. }
  1817. }
  1818. else
  1819. {
  1820. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1821. {
  1822. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1823. compositePeriodIdx++;
  1824. }
  1825. else
  1826. {
  1827. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1828. }
  1829. }
  1830. }
  1831. }
  1832. }
  1833. // Fill other period by MaxProfile
  1834. if(maxProfile.ChargingProfileId != -1)
  1835. {
  1836. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1837. {
  1838. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1839. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1840. (maxProfile.ChargingSchedule.Duration > 0))
  1841. {
  1842. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  1843. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  1844. {
  1845. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  1846. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  1847. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1848. }
  1849. if((maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  1850. {
  1851. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.Duration;
  1852. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  1853. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1854. }
  1855. if(tmpPeriod.Limit != -1)
  1856. {
  1857. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1858. {
  1859. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1860. {
  1861. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1862. compositePeriodIdx++;
  1863. }
  1864. else
  1865. {
  1866. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1867. }
  1868. }
  1869. }
  1870. }
  1871. }
  1872. }
  1873. DEBUG_INFO("Composite schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1874. DEBUG_INFO("Composite schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1875. DEBUG_INFO("Composite rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1876. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1877. {
  1878. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1879. {
  1880. compositeProfile->ChargingProfileId = 1;
  1881. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1882. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1883. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1884. }
  1885. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1886. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1887. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1888. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1889. }
  1890. if(line)
  1891. free(line);
  1892. }
  1893. //==========================================
  1894. // Init all share memory
  1895. //==========================================
  1896. int InitShareMemory()
  1897. {
  1898. int result = PASS;
  1899. int MeterSMId;
  1900. //creat ShmSysConfigAndInfo
  1901. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  1902. {
  1903. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  1904. result = FAIL;
  1905. }
  1906. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1907. {
  1908. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  1909. result = FAIL;
  1910. }
  1911. else
  1912. {}
  1913. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  1914. {
  1915. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  1916. result = FAIL;
  1917. }
  1918. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1919. {
  1920. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  1921. result = FAIL;
  1922. }
  1923. else
  1924. {}
  1925. //creat ShmPsuData
  1926. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  1927. {
  1928. DEBUG_ERROR("shmget ShmPsuData NG\n");
  1929. result = FAIL;
  1930. }
  1931. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1932. {
  1933. DEBUG_ERROR("shmat ShmPsuData NG\n");
  1934. result = FAIL;
  1935. }
  1936. else
  1937. {}
  1938. //creat ShmOCPP16Data
  1939. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  1940. {
  1941. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  1942. result = FAIL;
  1943. }
  1944. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1945. {
  1946. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  1947. result = FAIL;
  1948. }
  1949. else
  1950. {}
  1951. /****************************** For Initial Settings************************************************/
  1952. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  1953. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  1954. // allocate Configuration memory address
  1955. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  1956. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  1957. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  1958. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  1959. //offline MeterValue Interval
  1960. TempMeterValueInterval = 0;
  1961. return result;
  1962. }
  1963. int ProcessShareMemory()
  1964. {
  1965. if(InitShareMemory() == FAIL)
  1966. {
  1967. DEBUG_ERROR("InitShareMemory NG\n");
  1968. if(ShmStatusCodeData!=NULL)
  1969. {
  1970. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  1971. }
  1972. sleep(5);
  1973. return FAIL;
  1974. }
  1975. return PASS;
  1976. }
  1977. //---------------------common routine---------------------------//
  1978. int isOFFline(void)
  1979. {
  1980. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  1981. {
  1982. if(TempMeterValueInterval >= 2 )
  1983. {
  1984. TempMeterValueInterval = 0;
  1985. return TRUE;
  1986. }
  1987. else
  1988. {
  1989. TempMeterValueInterval = TempMeterValueInterval+ 1;
  1990. return FALSE;
  1991. }
  1992. }
  1993. else
  1994. {
  1995. return FALSE;
  1996. }
  1997. }
  1998. //---------------------------------------------
  1999. // new:
  2000. // enum SYSTEM_STATUS
  2001. // {
  2002. // SYS_MODE_BOOTING = 0,
  2003. // SYS_MODE_IDLE = 1,
  2004. // SYS_MODE_AUTHORIZING = 2,
  2005. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  2006. // SYS_MODE_REASSIGN = 4,
  2007. // SYS_MODE_PREPARING = 5,
  2008. // SYS_MODE_PREPARE_FOR_EV = 6,
  2009. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  2010. // SYS_MODE_CHARGING = 8,
  2011. // SYS_MODE_TERMINATING = 9,
  2012. // SYS_MODE_COMPLETE = 10,
  2013. // SYS_MODE_ALARM = 11,
  2014. // SYS_MODE_FAULT = 12,
  2015. // SYS_MODE_RESERVATION = 13,
  2016. // SYS_MODE_BOOKING = 14,
  2017. // SYS_MODE_MAINTAIN = 15,
  2018. // SYS_MODE_DEBUG = 16,
  2019. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  2020. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  2021. // SYS_MODE_UPDATE = 19
  2022. // };
  2023. //
  2024. //
  2025. //-----------------------------------------
  2026. void CheckSystemValue(void)
  2027. {
  2028. uint8_t reqSampleMeter[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  2029. uint8_t reqClockAlignMeter[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  2030. char filenmae[100]={0};
  2031. char str[100]={0};
  2032. int tempIndex = 0;
  2033. //===============================
  2034. // send Heartbeat
  2035. //===============================
  2036. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2037. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2038. {
  2039. clientTime.Heartbeat=time((time_t*)NULL);
  2040. if(server_sign == TRUE)
  2041. {
  2042. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2043. }
  2044. else
  2045. {
  2046. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2047. }
  2048. }
  2049. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  2050. {
  2051. //parameter for test
  2052. sendHeartbeatRequest(0);
  2053. //==============================================
  2054. // Reset Waiting Time
  2055. //==============================================
  2056. clientTime.Heartbeat=time((time_t*)NULL);
  2057. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  2058. }
  2059. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2060. {
  2061. //===============================
  2062. // CSU Trigger Reset Conf
  2063. //===============================
  2064. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  2065. {
  2066. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  2067. }
  2068. //===============================
  2069. // CSU Trigger Authorize Request
  2070. //===============================
  2071. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2072. {
  2073. sendAuthorizeRequest(0);
  2074. authorizeRetryTimes = authorizeRetryTimes + 1;
  2075. if(authorizeRetryTimes < 3)
  2076. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2077. }
  2078. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  2079. {
  2080. authorizeRetryTimes = 0;
  2081. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  2082. server_sign = FALSE;
  2083. }
  2084. 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))
  2085. {
  2086. sendAuthorizeRequest(0);
  2087. }
  2088. //===============================
  2089. // CSU Trigger Smart Charging Profilw
  2090. //===============================
  2091. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2092. {
  2093. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2094. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index]);
  2095. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  2096. }
  2097. //==============================================
  2098. // Charger start transaction
  2099. //==============================================
  2100. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2101. {
  2102. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  2103. sendStartTransactionRequest(gun_index);
  2104. clientTime.StartTransaction = time((time_t*)NULL);
  2105. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2106. }
  2107. //==============================================
  2108. // Charger stop transaction
  2109. //==============================================
  2110. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2111. {
  2112. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  2113. sendStopTransactionRequest(gun_index);
  2114. clientTime.StopTransaction = time((time_t*)NULL);
  2115. }
  2116. //==============================================
  2117. // Charger status report
  2118. //==============================================
  2119. //--- Check Mode Change ---//
  2120. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2121. if(gunType[gun_index] == 'J')
  2122. {
  2123. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2124. {
  2125. tempIndex = ((gun_index==2) ? 1: 0);
  2126. }
  2127. else
  2128. {
  2129. tempIndex = gun_index;
  2130. }
  2131. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2132. {
  2133. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2134. {
  2135. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  2136. {
  2137. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2138. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2139. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2140. statusModeChage[gun_index] = TRUE;
  2141. }
  2142. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2143. {
  2144. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2145. if((access(filenmae,F_OK))!=-1)
  2146. {
  2147. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2148. sprintf(str,"rm -f %s",filenmae);
  2149. system(str);
  2150. }
  2151. }
  2152. #if 1 // for TempStopTransaction
  2153. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2154. {
  2155. checkTempStopTransaction(gun_index);
  2156. }
  2157. #endif
  2158. }
  2159. }
  2160. }
  2161. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2162. {
  2163. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2164. {
  2165. tempIndex = ((gun_index==2) ? 1: 0);
  2166. }
  2167. else
  2168. {
  2169. tempIndex = gun_index;
  2170. }
  2171. for (int index = 0; index < CCS_QUANTITY; index++)
  2172. {
  2173. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2174. {
  2175. 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]*/ )
  2176. {
  2177. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2178. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2179. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2180. statusModeChage[gun_index] = TRUE;
  2181. }
  2182. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2183. {
  2184. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2185. if((access(filenmae,F_OK))!=-1)
  2186. {
  2187. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2188. sprintf(str,"rm -f %s",filenmae);
  2189. system(str);
  2190. }
  2191. }
  2192. #if 1 // for TempStopTransaction
  2193. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2194. {
  2195. checkTempStopTransaction(gun_index);
  2196. }
  2197. #endif
  2198. }
  2199. }
  2200. }
  2201. else if(gunType[gun_index] == 'G')
  2202. {
  2203. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2204. {
  2205. tempIndex = ((gun_index==2) ? 1: 0);
  2206. }
  2207. else
  2208. {
  2209. tempIndex = gun_index;
  2210. }
  2211. for (int index = 0; index < GB_QUANTITY; index++)
  2212. {
  2213. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2214. {
  2215. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2216. {
  2217. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2218. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2219. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2220. statusModeChage[gun_index] = TRUE;
  2221. }
  2222. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2223. {
  2224. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2225. if((access(filenmae,F_OK))!=-1)
  2226. {
  2227. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2228. sprintf(str,"rm -f %s",filenmae);
  2229. system(str);
  2230. }
  2231. }
  2232. #if 1 // for TempStopTransaction
  2233. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2234. {
  2235. checkTempStopTransaction(gun_index);
  2236. }
  2237. #endif
  2238. }
  2239. }
  2240. }
  2241. else
  2242. {
  2243. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2244. {
  2245. tempIndex = 2;
  2246. }
  2247. else
  2248. {
  2249. tempIndex = gun_index;
  2250. }
  2251. for (int index = 0; index < AC_QUANTITY; index++)
  2252. {
  2253. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2254. {
  2255. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2256. {
  2257. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2258. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2259. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2260. statusModeChage[gun_index] = TRUE;
  2261. }
  2262. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2263. {
  2264. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2265. if((access(filenmae,F_OK))!=-1)
  2266. {
  2267. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2268. sprintf(str,"rm -f %s",filenmae);
  2269. system(str);
  2270. }
  2271. }
  2272. #if 1 // for TempStopTransaction
  2273. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2274. {
  2275. checkTempStopTransaction(gun_index);
  2276. }
  2277. #endif
  2278. }
  2279. }// END
  2280. }
  2281. if(isWebsocketSendable &&
  2282. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) || ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index))) || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))) )
  2283. {
  2284. if(SystemInitial > 0)
  2285. SystemInitial -= 1;
  2286. sendStatusNotificationRequest(gun_index);
  2287. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2288. statusModeChage[gun_index] = FALSE;
  2289. }
  2290. //==============================================
  2291. // Meter report
  2292. //==============================================
  2293. if(cpinitateMsg.bits[gun_index].TriggerMeterValue)
  2294. {
  2295. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  2296. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  2297. }
  2298. if(/*(server_sign == TRUE) &&(isOFFline() == TRUE) ||*/
  2299. (((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1)) || ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE)))
  2300. {
  2301. //check Transaction active
  2302. if(gunType[gun_index] == 'J')
  2303. {
  2304. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2305. {
  2306. tempIndex = ((gun_index==2) ? 1: 0);
  2307. }
  2308. else
  2309. {
  2310. tempIndex = gun_index;
  2311. }
  2312. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2313. {
  2314. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2315. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2316. {
  2317. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2318. {
  2319. reqSampleMeter[gun_index] = 1;
  2320. }
  2321. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2322. {
  2323. reqClockAlignMeter[gun_index] = 1;
  2324. }
  2325. }
  2326. }// End for CHAdeMO
  2327. }
  2328. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2329. {
  2330. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2331. {
  2332. tempIndex = ((gun_index==2) ? 1: 0);
  2333. }
  2334. else
  2335. {
  2336. tempIndex = gun_index;
  2337. }
  2338. for (int index = 0; index < CCS_QUANTITY; index++)
  2339. {
  2340. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2341. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2342. {
  2343. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2344. {
  2345. reqSampleMeter[gun_index] = 1;
  2346. }
  2347. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2348. {
  2349. reqClockAlignMeter[gun_index] = 1;
  2350. }
  2351. }
  2352. } // End for CCS
  2353. }
  2354. else if(gunType[gun_index] == 'G')
  2355. {
  2356. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2357. {
  2358. tempIndex = ((gun_index==2) ? 1: 0);
  2359. }
  2360. else
  2361. {
  2362. tempIndex = gun_index;
  2363. }
  2364. for (int index = 0; index < GB_QUANTITY; index++)
  2365. {
  2366. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2367. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2368. {
  2369. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2370. {
  2371. reqSampleMeter[gun_index] = 1;
  2372. }
  2373. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2374. {
  2375. reqClockAlignMeter[gun_index] = 1;
  2376. }
  2377. }
  2378. }// End for GB
  2379. }
  2380. else
  2381. {
  2382. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2383. {
  2384. tempIndex = 2;
  2385. }
  2386. else
  2387. {
  2388. tempIndex = gun_index;
  2389. }
  2390. for (int index = 0; index < AC_QUANTITY; index++)
  2391. {
  2392. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2393. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2394. {
  2395. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2396. {
  2397. reqSampleMeter[gun_index] = 1;
  2398. }
  2399. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2400. {
  2401. reqClockAlignMeter[gun_index] = 1;
  2402. }
  2403. }
  2404. }//End for AC
  2405. }
  2406. if(reqSampleMeter[gun_index] == 1)
  2407. {
  2408. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  2409. storeTempStopTransaction(gun_index);
  2410. }
  2411. else if(reqClockAlignMeter[gun_index] == 1)
  2412. {
  2413. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2414. }
  2415. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2416. sleep(1);
  2417. }
  2418. //==============================================
  2419. // Check Connector reserved
  2420. //==============================================
  2421. //===============================
  2422. // Check if Reserve is expired
  2423. //===============================
  2424. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  2425. {
  2426. double diff_t;
  2427. struct tm tp;
  2428. // current time
  2429. time_t t = time(NULL);
  2430. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  2431. tp.tm_isdst = -1;
  2432. time_t utc = mktime(&tp);
  2433. diff_t = difftime(utc, t);
  2434. if(diff_t <= 0)
  2435. {
  2436. DEBUG_INFO("reserve expired.\n");
  2437. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  2438. }
  2439. }//END OF Check if Reserve is expired
  2440. //==========================================
  2441. // csu trigger FirmwareStatusNotificationReq
  2442. //==========================================
  2443. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  2444. {
  2445. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  2446. }
  2447. //==========================================
  2448. // csu trigger CancelReservationConf
  2449. //==========================================
  2450. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  2451. {
  2452. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  2453. }
  2454. //==========================================
  2455. // csu trigger ChangeAvailabilityConf
  2456. //==========================================
  2457. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  2458. {
  2459. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  2460. }
  2461. //==========================================
  2462. // csu trigger UnlockConnectorConf
  2463. //==========================================
  2464. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  2465. {
  2466. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  2467. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  2468. }
  2469. //==========================================
  2470. // csu trigger ReserveNowConf
  2471. //==========================================
  2472. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  2473. {
  2474. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  2475. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  2476. }
  2477. //==========================================
  2478. // csu trigger DataTransferReq
  2479. //==========================================
  2480. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2481. {
  2482. sendDataTransferRequest(gun_index);
  2483. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2484. }
  2485. }
  2486. }
  2487. //==========================================
  2488. // send request routine
  2489. //==========================================
  2490. int sendAuthorizeRequest(int gun_index)
  2491. {
  2492. mtrace();
  2493. int result = FAIL;
  2494. char message[100]={0};
  2495. char guid[37];
  2496. char tempdata[65]={0};
  2497. DEBUG_INFO("sendAuthorizeRequest...\n");
  2498. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  2499. //Local Authorize
  2500. if ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  2501. {
  2502. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  2503. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2504. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  2505. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  2506. result = PASS;
  2507. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2508. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2509. authorizeRetryTimes = 0;
  2510. return result;
  2511. }
  2512. 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))||
  2513. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  2514. {
  2515. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2516. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  2517. {
  2518. if(strcmp(idTagQuery.idTagstr,"") == 0)
  2519. {
  2520. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  2521. }
  2522. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  2523. {
  2524. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  2525. }
  2526. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  2527. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2528. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2529. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  2530. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2531. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2532. authorizeRetryTimes = 0;
  2533. return result;
  2534. }
  2535. else
  2536. {
  2537. DEBUG_INFO("offline Local Authorization Pass !!!!\n");
  2538. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  2539. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2540. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  2541. result = PASS;
  2542. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2543. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2544. authorizeRetryTimes = 0;
  2545. return result;
  2546. }
  2547. }
  2548. //initailize struct Authorize
  2549. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  2550. //get data from shared memory
  2551. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2552. random_uuid(guid);
  2553. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  2554. LWS_Send(message);
  2555. sprintf(tempdata, "Authorize,%d", gun_index);
  2556. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2557. {
  2558. result = PASS;
  2559. DEBUG_INFO("Authorize mapItem pass\n");
  2560. }
  2561. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2562. return result;
  2563. }
  2564. int sendBootNotificationRequest(void)
  2565. {
  2566. mtrace();
  2567. int result = FAIL;
  2568. char message[500]={0}, payload[700]={0};
  2569. char guid[37]={0};
  2570. char tempdata[65]={0};
  2571. /*
  2572. int IsGunCharging = FALSE;
  2573. //check Transaction active
  2574. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2575. {
  2576. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2577. {
  2578. IsGunCharging = TRUE;
  2579. }
  2580. }
  2581. for (int index = 0; index < CCS_QUANTITY; index++)
  2582. {
  2583. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2584. {
  2585. IsGunCharging = TRUE;
  2586. }
  2587. }
  2588. for (int index = 0; index < GB_QUANTITY; index++)
  2589. {
  2590. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2591. {
  2592. IsGunCharging = TRUE;
  2593. }
  2594. }
  2595. for (int index = 0; index < AC_QUANTITY; index++)
  2596. {
  2597. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2598. {
  2599. IsGunCharging = TRUE;
  2600. }
  2601. }
  2602. if(IsGunCharging == TRUE)
  2603. {
  2604. server_sign = TRUE;
  2605. return result;
  2606. }
  2607. */
  2608. // Fill BootNotification fields
  2609. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  2610. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  2611. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  2612. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2613. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  2614. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  2615. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  2616. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  2617. ShmOCPP16Data->ChargeBoxId
  2618. ,ShmSysConfigAndInfo->SysConfig.ModelName
  2619. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  2620. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  2621. ,ShmOCPP16Data->BootNotification.CpFwVersion
  2622. ,ShmOCPP16Data->BootNotification.CpIccid
  2623. ,ShmOCPP16Data->BootNotification.CpImsi);
  2624. random_uuid(guid);
  2625. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  2626. LWS_Send(message);
  2627. sprintf(tempdata, "BootNotification,0");
  2628. 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*/)
  2629. {
  2630. result = PASS;
  2631. }
  2632. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  2633. strcpy(queuedata,message);
  2634. return result;
  2635. }
  2636. int sendDataTransferRequest(int gun_index)
  2637. {
  2638. mtrace();
  2639. char message[1000]={0};
  2640. char guid[37]={0};
  2641. char tempdata[65]={0};
  2642. int result = FAIL;
  2643. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  2644. random_uuid(guid);
  2645. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  2646. MESSAGE_TYPE_CALL,
  2647. guid,
  2648. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  2649. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  2650. ShmOCPP16Data->DataTransfer[gun_index].Data);
  2651. LWS_Send(message);
  2652. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  2653. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2654. {
  2655. result = PASS;
  2656. DEBUG_INFO("DataTransfer mapItem pass\n");
  2657. }
  2658. return result;
  2659. }
  2660. int sendDiagnosticsStatusNotificationRequest(char *status)
  2661. {
  2662. mtrace();
  2663. int result = FAIL;
  2664. char message[110]={0};
  2665. char guid[37]={0};
  2666. char tempdata[65]={0};
  2667. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  2668. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  2669. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  2670. random_uuid(guid);
  2671. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  2672. LWS_Send(message);
  2673. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  2674. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2675. {
  2676. result = PASS;
  2677. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  2678. }
  2679. //#ifdef SystemLogMessage
  2680. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  2681. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2682. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  2683. //#endif
  2684. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  2685. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  2686. //record status
  2687. if(strcmp(status,"Idle")==0)
  2688. {
  2689. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  2690. }
  2691. else if(strcmp(status,"Uploaded")==0)
  2692. {
  2693. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  2694. }
  2695. else if(strcmp(status,"UploadFailed")==0)
  2696. {
  2697. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  2698. }
  2699. else if(strcmp(status,"Uploading")==0)
  2700. {
  2701. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  2702. }
  2703. return result;
  2704. }
  2705. int sendFirmwareStatusNotificationRequest(char *status)
  2706. {
  2707. mtrace();
  2708. int result = FAIL;
  2709. char message[110]={0};
  2710. char guid[37]={0};
  2711. char tempdata[65]={0};
  2712. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  2713. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  2714. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  2715. random_uuid(guid);
  2716. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  2717. LWS_Send(message);
  2718. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  2719. 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*/)
  2720. {
  2721. result = PASS;
  2722. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  2723. }
  2724. //#ifdef SystemLogMessage
  2725. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  2726. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2727. //#endif
  2728. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  2729. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  2730. //record status
  2731. if(strcmp(status,"Downloaded")==0)
  2732. {
  2733. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  2734. }
  2735. else if(strcmp(status,"DownloadFailed")==0)
  2736. {
  2737. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  2738. }
  2739. else if(strcmp(status,"Downloading")==0)
  2740. {
  2741. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  2742. }
  2743. else if(strcmp(status,"Idle")==0)
  2744. {
  2745. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  2746. }
  2747. else if(strcmp(status,"InstallationFailed")==0)
  2748. {
  2749. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  2750. }
  2751. else if(strcmp(status,"Installing")==0)
  2752. {
  2753. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  2754. }
  2755. else if(strcmp(status,"Installed")==0)
  2756. {
  2757. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  2758. }
  2759. return result;
  2760. }
  2761. int sendHeartbeatRequest(int gun_index)
  2762. {
  2763. mtrace();
  2764. int result = FAIL;
  2765. char message[80]={0};
  2766. char guid[37]={0};
  2767. char tempdata[65]={0};
  2768. random_uuid(guid);
  2769. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  2770. , MESSAGE_TYPE_CALL
  2771. , guid );
  2772. LWS_Send(message);
  2773. sprintf(tempdata, "Heartbeat,%d", 0);
  2774. 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*/)
  2775. {
  2776. result = PASS;
  2777. }
  2778. return result;
  2779. }
  2780. int sendStartTransactionRequest(int gun_index)
  2781. {
  2782. mtrace();
  2783. int result = FAIL;
  2784. char message[250]={0};
  2785. char guid[37]={0};
  2786. struct timeval tmnow;
  2787. struct tm *tm;
  2788. char buf[28];//, usec_buf[6];
  2789. char tempdata[65]={0};
  2790. int tempIndex = 0;
  2791. DEBUG_INFO("sendStartTransactionRequest...\n");
  2792. gettimeofday(&tmnow, NULL);
  2793. time_t t;
  2794. t = time(NULL);
  2795. /*UTC time and date*/
  2796. tm = gmtime(&t);
  2797. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2798. #if 0 // remove temporally
  2799. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2800. strcat(buf,".");
  2801. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2802. strcat(buf,usec_buf);
  2803. #endif
  2804. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  2805. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  2806. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2807. // clear StartTransaction Response
  2808. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  2809. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  2810. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  2811. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  2812. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2813. if(gunType[gun_index] == 'J')
  2814. {
  2815. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2816. {
  2817. tempIndex = ((gun_index==2) ? 1: 0);
  2818. }
  2819. else
  2820. {
  2821. tempIndex = gun_index;
  2822. }
  2823. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2824. {
  2825. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2826. {
  2827. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  2828. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  2829. }
  2830. }
  2831. }
  2832. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2833. {
  2834. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2835. {
  2836. tempIndex = ((gun_index==2) ? 1: 0);
  2837. }
  2838. else
  2839. {
  2840. tempIndex = gun_index;
  2841. }
  2842. for (int index = 0; index < CCS_QUANTITY; index++)
  2843. {
  2844. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2845. {
  2846. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  2847. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  2848. }
  2849. }
  2850. }
  2851. else if(gunType[gun_index] == 'G')
  2852. {
  2853. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2854. {
  2855. tempIndex = ((gun_index==2) ? 1: 0);
  2856. }
  2857. else
  2858. {
  2859. tempIndex = gun_index;
  2860. }
  2861. for (int index = 0; index < GB_QUANTITY; index++)
  2862. {
  2863. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2864. {
  2865. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  2866. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  2867. }
  2868. }
  2869. }
  2870. else
  2871. {
  2872. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2873. {
  2874. tempIndex = 2;
  2875. }
  2876. else
  2877. {
  2878. tempIndex = gun_index;
  2879. }
  2880. for (int index = 0; index < AC_QUANTITY; index++)
  2881. {
  2882. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2883. {
  2884. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  2885. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  2886. }
  2887. }
  2888. }
  2889. random_uuid(guid);
  2890. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  2891. {
  2892. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  2893. , gun_index +1
  2894. , MESSAGE_TYPE_CALL
  2895. , guid
  2896. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  2897. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  2898. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  2899. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  2900. }
  2901. else
  2902. {
  2903. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  2904. , gun_index +1
  2905. , MESSAGE_TYPE_CALL
  2906. , guid
  2907. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  2908. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  2909. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  2910. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  2911. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  2912. }
  2913. #if 1
  2914. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  2915. if(hashmap_operation(0, 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*/)
  2916. {
  2917. result = PASS;
  2918. }
  2919. #endif
  2920. strcpy(queuedata, message);
  2921. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2922. /*
  2923. if(GetTransactionQueueNum() == 1)
  2924. {
  2925. LWS_Send(message + 2);
  2926. }*/
  2927. return result;
  2928. }
  2929. int sendStatusNotificationRequest(int gun_index)
  2930. {
  2931. mtrace();
  2932. int result = FAIL;
  2933. char message[600]={0};
  2934. char guid[37];
  2935. int currentStatus = 0;
  2936. struct timeval tmnow;
  2937. struct tm *tm;
  2938. char buf[28];//, usec_buf[6];
  2939. char tempdata[65]={0};
  2940. int tempIndex = 0;
  2941. gettimeofday(&tmnow, NULL);
  2942. time_t t;
  2943. t = time(NULL);
  2944. /*UTC time and date*/
  2945. tm = gmtime(&t);
  2946. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2947. #if 0 // remove temporally
  2948. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2949. strcat(buf,".");
  2950. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2951. strcat(buf,usec_buf);
  2952. #endif
  2953. printf("%s",buf);
  2954. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  2955. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  2956. // it's option
  2957. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  2958. /*
  2959. enum _SYSTEM_STATUS
  2960. {
  2961. S_BOOTING = 0,
  2962. S_IDLE, = 1
  2963. S_AUTHORIZING, =2
  2964. S_REASSIGN_CHECK, =3
  2965. S_REASSIGN, =4
  2966. S_PRECHARGE, =5
  2967. S_PREPARING_FOR_EV, =6
  2968. S_PREPARING_FOR_EVSE, =7
  2969. S_CHARGING, =8
  2970. S_TERMINATING, =9
  2971. S_COMPLETE, =10
  2972. S_ALARM, =11
  2973. S_FAULT =12
  2974. }
  2975. */
  2976. //check Transaction active
  2977. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2978. if(gunType[gun_index] == 'J')
  2979. {
  2980. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2981. {
  2982. tempIndex = ((gun_index==2) ? 1: 0);
  2983. }
  2984. else
  2985. {
  2986. tempIndex = gun_index;
  2987. }
  2988. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2989. {
  2990. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  2991. {
  2992. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  2993. {
  2994. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  2995. {
  2996. currentStatus = 1; //OCPP Status: Preparing
  2997. }
  2998. else
  2999. {
  3000. currentStatus = 0; //OCPP Status: Available
  3001. }
  3002. }
  3003. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3004. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3005. ) //S_PRECHARGE
  3006. {
  3007. currentStatus = 1; //OCPP Status: Preparing
  3008. }
  3009. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3010. {
  3011. currentStatus = 2; //OCPP Status: Charging
  3012. }
  3013. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3014. {
  3015. currentStatus = 5; //OCPP Status: Finishing
  3016. }
  3017. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3018. {
  3019. currentStatus = 4; //OCPP Status: SuspendedEV
  3020. }
  3021. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  3022. {
  3023. currentStatus = 7; //OCPP Status: Unavailable
  3024. }
  3025. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3026. {
  3027. currentStatus = 8; //OCPP Status: Faulted
  3028. }
  3029. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3030. {
  3031. currentStatus = 6; //OCPP Status: Reserved
  3032. }
  3033. } //end of the same index
  3034. }//end of for CHAdeMO_QUANTITY
  3035. }
  3036. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3037. {
  3038. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3039. {
  3040. tempIndex = ((gun_index==2) ? 1: 0);
  3041. }
  3042. else
  3043. {
  3044. tempIndex = gun_index;
  3045. }
  3046. for (int index = 0; index < CCS_QUANTITY; index++)
  3047. {
  3048. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3049. {
  3050. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3051. {
  3052. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3053. {
  3054. currentStatus = 1; //OCPP Status: Preparing
  3055. }
  3056. else
  3057. {
  3058. currentStatus = 0; //OCPP Status: Available
  3059. }
  3060. }
  3061. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3062. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3063. ) //S_PRECHARGE
  3064. {
  3065. currentStatus = 1; //OCPP Status: Preparing
  3066. }
  3067. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3068. {
  3069. currentStatus = 2; //OCPP Status: Charging
  3070. }
  3071. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3072. {
  3073. currentStatus = 5; //OCPP Status: Finishing
  3074. }
  3075. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3076. {
  3077. currentStatus = 4; //OCPP Status: SuspendedEV
  3078. }
  3079. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  3080. {
  3081. currentStatus = 7; //OCPP Status : Unavailable
  3082. }
  3083. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3084. {
  3085. currentStatus = 8; //OCPP Status: Faulted
  3086. }
  3087. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3088. {
  3089. currentStatus = 6; //OCPP Status: Reserved
  3090. }
  3091. } //end of the same index
  3092. } // end of for CCS_QUANTITY
  3093. }
  3094. else if(gunType[gun_index] == 'G')
  3095. {
  3096. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3097. {
  3098. tempIndex = ((gun_index==2) ? 1: 0);
  3099. }
  3100. else
  3101. {
  3102. tempIndex = gun_index;
  3103. }
  3104. for (int index = 0; index < GB_QUANTITY; index++)
  3105. {
  3106. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3107. {
  3108. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3109. {
  3110. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3111. {
  3112. currentStatus = 1; //OCPP Status: Preparing
  3113. }
  3114. else
  3115. {
  3116. currentStatus = 0; //OCPP Status: Available
  3117. }
  3118. }
  3119. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3120. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3121. ) //S_PRECHARGE
  3122. {
  3123. currentStatus = 1; //OCPP Status: Preparing
  3124. }
  3125. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3126. {
  3127. currentStatus = 2; //OCPP Status: Charging
  3128. }
  3129. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3130. {
  3131. currentStatus = 5; //OCPP Status: Finishing
  3132. }
  3133. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3134. {
  3135. currentStatus = 4; //OCPP Status: SuspendedEV
  3136. }
  3137. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  3138. {
  3139. currentStatus = 7; //OCPP Status: Unavailable
  3140. }
  3141. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3142. {
  3143. currentStatus = 8; //OCPP Status: Faulted
  3144. }
  3145. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3146. {
  3147. currentStatus = 6; //OCPP Status: Reserved
  3148. }
  3149. } //end of the same index
  3150. } // end of for GB_QUANTITY
  3151. }
  3152. else
  3153. {
  3154. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3155. {
  3156. tempIndex = 2;
  3157. }
  3158. else
  3159. {
  3160. tempIndex = gun_index;
  3161. }
  3162. for (int index = 0; index < AC_QUANTITY; index++)
  3163. {
  3164. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3165. {
  3166. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3167. {
  3168. 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))
  3169. {
  3170. currentStatus = 1; //OCPP Status: Preparing
  3171. }
  3172. else
  3173. {
  3174. currentStatus = 0; //OCPP Status: Available
  3175. }
  3176. }
  3177. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3178. {
  3179. currentStatus = 1; //OCPP Status: Preparing
  3180. }
  3181. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3182. {
  3183. currentStatus = 2; //OCPP Status: Charging
  3184. }
  3185. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3186. {
  3187. currentStatus = 5; //OCPP Status: Finishing
  3188. }
  3189. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3190. {
  3191. currentStatus = 4; //OCPP Status: SuspendedEV
  3192. }
  3193. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  3194. {
  3195. currentStatus = 7; //OCPP Status: Unavailable
  3196. }
  3197. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3198. {
  3199. currentStatus = 8; //OCPP Status: Faulted
  3200. }
  3201. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3202. {
  3203. currentStatus = 6; //OCPP Status: Reserved
  3204. }
  3205. }//end of the same index
  3206. }//end of for AC_QUANTITY
  3207. }
  3208. //it's option
  3209. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3210. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  3211. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3212. random_uuid(guid);
  3213. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3214. , MESSAGE_TYPE_CALL
  3215. , guid
  3216. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3217. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3218. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3219. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3220. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3221. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3222. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3223. LWS_Send(message);
  3224. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3225. if(hashmap_operation(0, 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*/)
  3226. {
  3227. //DEBUG_ERROR("statusNotification mapitem pass");
  3228. result = PASS;
  3229. }
  3230. return result;
  3231. }
  3232. int sendStopTransactionRequest(int gun_index)
  3233. {
  3234. mtrace();
  3235. int result = FAIL;
  3236. //char message[1500]={0};
  3237. char guid[37]={0};
  3238. char tempdata[65]={0};
  3239. int tempIndex = 0;
  3240. //int idx_sample=0;
  3241. DEBUG_ERROR("sendStopTransactionRequest \n");
  3242. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3243. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3244. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3245. if(gunType[gun_index] == 'J')
  3246. {
  3247. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3248. {
  3249. tempIndex = ((gun_index==2) ? 1: 0);
  3250. }
  3251. else
  3252. {
  3253. tempIndex = gun_index;
  3254. }
  3255. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3256. {
  3257. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3258. {
  3259. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3260. }
  3261. }// END OF CHAdeMO_QUANTITY
  3262. }
  3263. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3264. {
  3265. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3266. {
  3267. tempIndex = ((gun_index==2) ? 1: 0);
  3268. }
  3269. else
  3270. {
  3271. tempIndex = gun_index;
  3272. }
  3273. for (int index = 0; index < CCS_QUANTITY; index++)
  3274. {
  3275. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3276. {
  3277. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3278. }
  3279. }// END OF CCS_QUANTITY
  3280. }
  3281. else if(gunType[gun_index] == 'G')
  3282. {
  3283. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3284. {
  3285. tempIndex = ((gun_index==2) ? 1: 0);
  3286. }
  3287. else
  3288. {
  3289. tempIndex = gun_index;
  3290. }
  3291. for (int index = 0; index < GB_QUANTITY; index++)
  3292. {
  3293. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3294. {
  3295. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3296. }
  3297. }// END OF GB_QUANTITY
  3298. }
  3299. else
  3300. {
  3301. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3302. {
  3303. tempIndex = 2;
  3304. }
  3305. else
  3306. {
  3307. tempIndex = gun_index;
  3308. }
  3309. for (int index = 0; index < AC_QUANTITY; index++)
  3310. {
  3311. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3312. {
  3313. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3314. }
  3315. }// END OF AC_QUANTITY
  3316. }
  3317. //====================================== Stop Transaction Time =====================================================
  3318. struct timeval tmnow;
  3319. struct tm *tm;
  3320. char buf[28];//, usec_buf[6];
  3321. gettimeofday(&tmnow, NULL);
  3322. time_t t;
  3323. t = time(NULL);
  3324. /*UTC time and date*/
  3325. tm = gmtime(&t);
  3326. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3327. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  3328. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  3329. random_uuid(guid);
  3330. /***********************************transactionData******************************************************/
  3331. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  3332. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  3333. //=================================
  3334. // Transaction_Begin
  3335. //=================================
  3336. //============================================ Energy.Active.Import.Interval ================================
  3337. //idx_sample=0;
  3338. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  3339. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  3340. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  3341. 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*/]);
  3342. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3343. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3344. {
  3345. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  3346. }
  3347. else
  3348. {
  3349. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  3350. }
  3351. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  3352. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3353. //=================================
  3354. // Transaction_End
  3355. //=================================
  3356. // ================================= Current.Import L1 ===============================================
  3357. //idx_sample=1;
  3358. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  3359. if(gunType[gun_index] == 'J')
  3360. {
  3361. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3362. {
  3363. tempIndex = ((gun_index==2) ? 1: 0);
  3364. }
  3365. else
  3366. {
  3367. tempIndex = gun_index;
  3368. }
  3369. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3370. {
  3371. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3372. {
  3373. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3374. }
  3375. }// End of for CHAdeMO_QUANTITY
  3376. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3377. }
  3378. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3379. {
  3380. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3381. {
  3382. tempIndex = ((gun_index==2) ? 1: 0);
  3383. }
  3384. else
  3385. {
  3386. tempIndex = gun_index;
  3387. }
  3388. for (int index = 0; index < CCS_QUANTITY; index++)
  3389. {
  3390. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3391. {
  3392. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3393. }
  3394. }// End of for CCS_QUANTITY
  3395. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3396. }
  3397. else if(gunType[gun_index] == 'G')
  3398. {
  3399. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3400. {
  3401. tempIndex = ((gun_index==2) ? 1: 0);
  3402. }
  3403. else
  3404. {
  3405. tempIndex = gun_index;
  3406. }
  3407. for (int index = 0; index < GB_QUANTITY; index++)
  3408. {
  3409. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3410. {
  3411. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3412. }
  3413. }// End of for GB_QUANTITY
  3414. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3415. }
  3416. else
  3417. {
  3418. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3419. {
  3420. tempIndex = 2;
  3421. }
  3422. else
  3423. {
  3424. tempIndex = gun_index;
  3425. }
  3426. for (int index = 0; index < AC_QUANTITY; index++)
  3427. {
  3428. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3429. {
  3430. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  3431. }
  3432. }// End of for AC_QUANTITY
  3433. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  3434. }
  3435. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3436. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  3437. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  3438. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  3439. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3440. // ================================= Energy.Active.Import.Interval ==============================================
  3441. //idx_sample=2;
  3442. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3443. if(gunType[gun_index] == 'J')
  3444. {
  3445. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3446. {
  3447. tempIndex = ((gun_index==2) ? 1: 0);
  3448. }
  3449. else
  3450. {
  3451. tempIndex = gun_index;
  3452. }
  3453. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3454. {
  3455. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3456. {
  3457. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3458. }
  3459. }// END OF CHAdeMO_QUANTITY
  3460. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3461. }
  3462. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3463. {
  3464. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3465. {
  3466. tempIndex = ((gun_index==2) ? 1: 0);
  3467. }
  3468. else
  3469. {
  3470. tempIndex = gun_index;
  3471. }
  3472. for (int index = 0; index < CCS_QUANTITY; index++)
  3473. {
  3474. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3475. {
  3476. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3477. }
  3478. }// END OF CCS_QUANTITY
  3479. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3480. }
  3481. else if(gunType[gun_index] == 'G')
  3482. {
  3483. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3484. {
  3485. tempIndex = ((gun_index==2) ? 1: 0);
  3486. }
  3487. else
  3488. {
  3489. tempIndex = gun_index;
  3490. }
  3491. for (int index = 0; index < GB_QUANTITY; index++)
  3492. {
  3493. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3494. {
  3495. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3496. }
  3497. }// END OF GB_QUANTITY
  3498. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3499. }
  3500. else
  3501. {
  3502. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3503. {
  3504. tempIndex = 2;
  3505. }
  3506. else
  3507. {
  3508. tempIndex = gun_index;
  3509. }
  3510. for (int index = 0; index < AC_QUANTITY; index++)
  3511. {
  3512. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3513. {
  3514. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3515. }
  3516. }// END OF AC_QUANTITY
  3517. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  3518. }
  3519. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3520. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  3521. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  3522. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  3523. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3524. //=================================== Power.Active.Import ==================================================
  3525. //idx_sample=3;
  3526. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3527. if(gunType[gun_index] == 'J')
  3528. {
  3529. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3530. {
  3531. tempIndex = ((gun_index==2) ? 1: 0);
  3532. }
  3533. else
  3534. {
  3535. tempIndex = gun_index;
  3536. }
  3537. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3538. {
  3539. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3540. {
  3541. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3542. }
  3543. } // End for CHAdeMO_QUANTITY
  3544. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3545. }
  3546. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3547. {
  3548. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3549. {
  3550. tempIndex = ((gun_index==2) ? 1: 0);
  3551. }
  3552. else
  3553. {
  3554. tempIndex = gun_index;
  3555. }
  3556. for (int index = 0; index < CCS_QUANTITY; index++)
  3557. {
  3558. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3559. {
  3560. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3561. }
  3562. } // END for CCS_QUANTITY
  3563. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3564. }
  3565. else if(gunType[gun_index] == 'G')
  3566. {
  3567. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3568. {
  3569. tempIndex = ((gun_index==2) ? 1: 0);
  3570. }
  3571. else
  3572. {
  3573. tempIndex = gun_index;
  3574. }
  3575. for (int index = 0; index < GB_QUANTITY; index++)
  3576. {
  3577. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3578. {
  3579. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3580. }
  3581. }// END for GB_QUANTITY
  3582. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3583. }
  3584. else
  3585. {
  3586. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3587. {
  3588. tempIndex = 2;
  3589. }
  3590. else
  3591. {
  3592. tempIndex = gun_index;
  3593. }
  3594. for (int index = 0; index < AC_QUANTITY; index++)
  3595. {
  3596. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3597. {
  3598. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3599. }
  3600. } // END for AC_QUANTITY
  3601. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  3602. }
  3603. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3604. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  3605. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  3606. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  3607. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  3608. //============================ Voltage L1 ====================================
  3609. //idx_sample=4;
  3610. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3611. if(gunType[gun_index] == 'J')
  3612. {
  3613. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3614. {
  3615. tempIndex = ((gun_index==2) ? 1: 0);
  3616. }
  3617. else
  3618. {
  3619. tempIndex = gun_index;
  3620. }
  3621. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3622. {
  3623. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3624. {
  3625. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3626. }
  3627. } // END OF FOR CHAdeMO_QUANTITY
  3628. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3629. }
  3630. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3631. {
  3632. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3633. {
  3634. tempIndex = ((gun_index==2) ? 1: 0);
  3635. }
  3636. else
  3637. {
  3638. tempIndex = gun_index;
  3639. }
  3640. for (int index = 0; index < CCS_QUANTITY; index++)
  3641. {
  3642. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3643. {
  3644. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3645. }
  3646. } // END OF FOR CCS_QUANTITY
  3647. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3648. }
  3649. else if(gunType[gun_index] == 'G')
  3650. {
  3651. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3652. {
  3653. tempIndex = ((gun_index==2) ? 1: 0);
  3654. }
  3655. else
  3656. {
  3657. tempIndex = gun_index;
  3658. }
  3659. for (int index = 0; index < GB_QUANTITY; index++)
  3660. {
  3661. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3662. {
  3663. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3664. }
  3665. } // END OF FOR GB_QUANTITY
  3666. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3667. }
  3668. else
  3669. {
  3670. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3671. {
  3672. tempIndex = 2;
  3673. }
  3674. else
  3675. {
  3676. tempIndex = gun_index;
  3677. }
  3678. for (int index = 0; index < AC_QUANTITY; index++)
  3679. {
  3680. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3681. {
  3682. 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
  3683. }
  3684. } // END OF FOR AC_QUANTITY
  3685. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  3686. }
  3687. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3688. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  3689. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  3690. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  3691. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3692. //====================== SoC ================================
  3693. //idx_sample=5;
  3694. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3695. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3696. {
  3697. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3698. {
  3699. tempIndex = ((gun_index==2) ? 1: 0);
  3700. }
  3701. else
  3702. {
  3703. tempIndex = gun_index;
  3704. }
  3705. if(gunType[gun_index] == 'J')
  3706. {
  3707. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3708. {
  3709. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3710. {
  3711. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  3712. }
  3713. }
  3714. }
  3715. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3716. {
  3717. for (int index = 0; index < CCS_QUANTITY; index++)
  3718. {
  3719. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3720. {
  3721. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  3722. }
  3723. }
  3724. }
  3725. else if(gunType[gun_index] == 'G')
  3726. {
  3727. for (int index = 0; index < GB_QUANTITY; index++)
  3728. {
  3729. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3730. {
  3731. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  3732. }
  3733. }
  3734. }
  3735. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3736. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  3737. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  3738. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  3739. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  3740. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  3741. } // END FOR DC CASE
  3742. // ================================= Current.Import L2 ===============================================
  3743. //idx_sample=6;
  3744. // AC 3 phse L2 current
  3745. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3746. {
  3747. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3748. {
  3749. tempIndex = 2;
  3750. }
  3751. else
  3752. {
  3753. tempIndex = gun_index;
  3754. }
  3755. for (int index = 0; index < AC_QUANTITY; index++)
  3756. {
  3757. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3758. {
  3759. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  3760. }
  3761. }// End of for AC_QUANTITY
  3762. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  3763. }
  3764. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3765. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  3766. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  3767. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  3768. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3769. // ================================= Current.Import L3 ===============================================
  3770. //idx_sample=7;
  3771. // AC 3 phse L3 current
  3772. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3773. {
  3774. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3775. {
  3776. tempIndex = 2;
  3777. }
  3778. else
  3779. {
  3780. tempIndex = gun_index;
  3781. }
  3782. for (int index = 0; index < AC_QUANTITY; index++)
  3783. {
  3784. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3785. {
  3786. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  3787. }
  3788. }// End of for AC_QUANTITY
  3789. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  3790. }
  3791. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3792. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  3793. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  3794. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  3795. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3796. //============================ Voltage L2 ====================================
  3797. //idx_sample=8;
  3798. // AC 3 phse L2 voltage
  3799. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3800. {
  3801. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3802. {
  3803. tempIndex = 2;
  3804. }
  3805. else
  3806. {
  3807. tempIndex = gun_index;
  3808. }
  3809. for (int index = 0; index < AC_QUANTITY; index++)
  3810. {
  3811. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3812. {
  3813. 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
  3814. }
  3815. } // END OF FOR AC_QUANTITY
  3816. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  3817. }
  3818. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3819. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  3820. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  3821. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  3822. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3823. //============================ Voltage L3 ====================================
  3824. //idx_sample=8;
  3825. // AC 3 phse L3 voltage
  3826. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3827. {
  3828. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3829. {
  3830. tempIndex = 2;
  3831. }
  3832. else
  3833. {
  3834. tempIndex = gun_index;
  3835. }
  3836. for (int index = 0; index < AC_QUANTITY; index++)
  3837. {
  3838. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3839. {
  3840. 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
  3841. }
  3842. } // END OF FOR AC_QUANTITY
  3843. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  3844. }
  3845. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3846. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  3847. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  3848. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  3849. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3850. //================================================ Message create ====================================================
  3851. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3852. {
  3853. sprintf(queuedata,"%d,[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  3854. ,gun_index+1
  3855. ,MESSAGE_TYPE_CALL
  3856. ,guid
  3857. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3858. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3859. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3860. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3861. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3862. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3863. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3864. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3865. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3866. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3867. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3868. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3869. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3870. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3871. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3872. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3873. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3874. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3875. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3876. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3877. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3878. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3879. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3880. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3881. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3882. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3883. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3884. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3885. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3886. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3887. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3888. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3889. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3890. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3891. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3892. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3893. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3894. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3895. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3896. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3897. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3898. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  3899. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  3900. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  3901. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  3902. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  3903. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  3904. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  3905. );
  3906. }
  3907. else
  3908. {
  3909. if((ShmSysConfigAndInfo->SysConfig.ModelName[2]!='Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2]!='W'))
  3910. {
  3911. sprintf(queuedata,"%d,[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  3912. ,gun_index+1
  3913. ,MESSAGE_TYPE_CALL
  3914. ,guid
  3915. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3916. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3917. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3918. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3919. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3920. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3921. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3922. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3923. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3924. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3925. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3926. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3927. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3928. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3929. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3930. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3931. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3932. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3933. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3934. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3935. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3936. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3937. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3938. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3939. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3940. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3941. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3942. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3943. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3944. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3945. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3946. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3947. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3948. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3949. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3950. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3951. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3952. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3953. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3954. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3955. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3956. );
  3957. }
  3958. else
  3959. {
  3960. sprintf(queuedata,"%d,[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  3961. ,gun_index+1
  3962. ,MESSAGE_TYPE_CALL
  3963. ,guid
  3964. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3965. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3966. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3967. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3968. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3969. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3970. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3971. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3972. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3973. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3974. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3975. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3976. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3977. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3978. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3979. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3980. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3981. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3982. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3983. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3984. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3985. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3986. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3987. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3988. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3989. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3990. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3991. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3992. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3993. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3994. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3995. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3996. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3997. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3998. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3999. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  4000. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  4001. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  4002. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  4003. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  4004. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  4005. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value
  4006. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context
  4007. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format
  4008. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand
  4009. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase
  4010. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location
  4011. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit
  4012. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value
  4013. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context
  4014. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format
  4015. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand
  4016. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase
  4017. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location
  4018. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit
  4019. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value
  4020. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context
  4021. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format
  4022. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand
  4023. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase
  4024. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location
  4025. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit
  4026. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value
  4027. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context
  4028. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format
  4029. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand
  4030. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase
  4031. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location
  4032. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit
  4033. );
  4034. }
  4035. }
  4036. #if 1 // for TempStopTransaction
  4037. //Delete TempStopTransaction
  4038. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  4039. {
  4040. remove("/Storage/OCPP/TempStopTransaction"); // remove file "TempStopTransaction"
  4041. }
  4042. #endif
  4043. #if 1
  4044. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4045. if(hashmap_operation(0, guid, tempdata) == 1)
  4046. {
  4047. result = PASS;
  4048. DEBUG_INFO("StopTransaction mapitem pass\n");
  4049. }
  4050. #endif
  4051. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4052. /*
  4053. if(GetTransactionQueueNum() == 1)
  4054. {
  4055. LWS_Send(queuedata+2);
  4056. }*/
  4057. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4058. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4059. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  4060. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4061. {
  4062. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4063. }
  4064. //for test
  4065. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4066. return result;
  4067. }
  4068. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4069. {
  4070. mtrace();
  4071. int result = FAIL;
  4072. char guid[37]={0};
  4073. char tempdata[65]={0};
  4074. int tempIndex = 0;
  4075. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4076. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4077. //set value
  4078. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4079. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ((strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging") != NULL) ? ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId : 0);
  4080. random_uuid(guid);
  4081. //UTC Date time
  4082. struct timeval tmnow;
  4083. struct tm *tm;
  4084. char buf[28];//, usec_buf[6];
  4085. gettimeofday(&tmnow, NULL);
  4086. time_t t;
  4087. t = time(NULL);
  4088. /*UTC time and date*/
  4089. tm = gmtime(&t);
  4090. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4091. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4092. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4093. //idx_sample=0;
  4094. //********************************(1)Current.Import L1************************************************/
  4095. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4096. if(gunType[gun_index] == 'J')
  4097. {
  4098. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4099. {
  4100. tempIndex = ((gun_index==2) ? 1: 0);
  4101. }
  4102. else
  4103. {
  4104. tempIndex = gun_index;
  4105. }
  4106. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4107. {
  4108. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4109. {
  4110. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4111. }
  4112. }
  4113. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4114. }
  4115. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4116. {
  4117. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4118. {
  4119. tempIndex = ((gun_index==2) ? 1: 0);
  4120. }
  4121. else
  4122. {
  4123. tempIndex = gun_index;
  4124. }
  4125. for (int index = 0; index < CCS_QUANTITY; index++)
  4126. {
  4127. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4128. {
  4129. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4130. }
  4131. }
  4132. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4133. }
  4134. else if(gunType[gun_index] == 'G')
  4135. {
  4136. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4137. {
  4138. tempIndex = ((gun_index==2) ? 1: 0);
  4139. }
  4140. else
  4141. {
  4142. tempIndex = gun_index;
  4143. }
  4144. for (int index = 0; index < GB_QUANTITY; index++)
  4145. {
  4146. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4147. {
  4148. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4149. }
  4150. }
  4151. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4152. }
  4153. else
  4154. {
  4155. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4156. {
  4157. tempIndex = 2;
  4158. }
  4159. else
  4160. {
  4161. tempIndex = gun_index;
  4162. }
  4163. for (int index = 0; index < AC_QUANTITY; index++)
  4164. {
  4165. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4166. {
  4167. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4168. }
  4169. }
  4170. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4171. }
  4172. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4173. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4174. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4175. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4176. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4177. //idx_sample=1;
  4178. //********************************(2)Energy.Active.Import.Register ************************************************/
  4179. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4180. if(gunType[gun_index] == 'J')
  4181. {
  4182. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4183. {
  4184. tempIndex = ((gun_index==2) ? 1: 0);
  4185. }
  4186. else
  4187. {
  4188. tempIndex = gun_index;
  4189. }
  4190. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4191. {
  4192. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4193. {
  4194. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4195. }
  4196. }
  4197. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4198. }
  4199. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4200. {
  4201. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4202. {
  4203. tempIndex = ((gun_index==2) ? 1: 0);
  4204. }
  4205. else
  4206. {
  4207. tempIndex = gun_index;
  4208. }
  4209. for (int index = 0; index < CCS_QUANTITY; index++)
  4210. {
  4211. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4212. {
  4213. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4214. }
  4215. }
  4216. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4217. }
  4218. else if(gunType[gun_index] == 'G')
  4219. {
  4220. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4221. {
  4222. tempIndex = ((gun_index==2) ? 1: 0);
  4223. }
  4224. else
  4225. {
  4226. tempIndex = gun_index;
  4227. }
  4228. for (int index = 0; index < GB_QUANTITY; index++)
  4229. {
  4230. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4231. {
  4232. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4233. }
  4234. }
  4235. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4236. }
  4237. else
  4238. {
  4239. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4240. {
  4241. tempIndex = 2;
  4242. }
  4243. else
  4244. {
  4245. tempIndex = gun_index;
  4246. }
  4247. for (int index = 0; index < AC_QUANTITY; index++)
  4248. {
  4249. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4250. {
  4251. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4252. }
  4253. }
  4254. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4255. }
  4256. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  4257. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4258. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4259. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4260. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4261. //idx_sample=2;
  4262. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  4263. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4264. if(gunType[gun_index] == 'J')
  4265. {
  4266. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4267. {
  4268. tempIndex = ((gun_index==2) ? 1: 0);
  4269. }
  4270. else
  4271. {
  4272. tempIndex = gun_index;
  4273. }
  4274. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4275. {
  4276. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4277. {
  4278. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4279. }
  4280. } // END OF FOR CHAdeMO_QUANTITY
  4281. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4282. }
  4283. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4284. {
  4285. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4286. {
  4287. tempIndex = ((gun_index==2) ? 1: 0);
  4288. }
  4289. else
  4290. {
  4291. tempIndex = gun_index;
  4292. }
  4293. for (int index = 0; index < CCS_QUANTITY; index++)
  4294. {
  4295. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4296. {
  4297. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  4298. }
  4299. } // END OF CCS_QUANTITY
  4300. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4301. }
  4302. else if(gunType[gun_index] == 'G')
  4303. {
  4304. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4305. {
  4306. tempIndex = ((gun_index==2) ? 1: 0);
  4307. }
  4308. else
  4309. {
  4310. tempIndex = gun_index;
  4311. }
  4312. for (int index = 0; index < GB_QUANTITY; index++)
  4313. {
  4314. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4315. {
  4316. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  4317. }
  4318. } // END OF GB_QUANTITY
  4319. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4320. }
  4321. else
  4322. {
  4323. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4324. {
  4325. tempIndex = 2;
  4326. }
  4327. else
  4328. {
  4329. tempIndex = gun_index;
  4330. }
  4331. for (int index = 0; index < AC_QUANTITY; index++)
  4332. {
  4333. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4334. {
  4335. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  4336. }
  4337. }
  4338. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  4339. }
  4340. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  4341. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  4342. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  4343. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  4344. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4345. //idx_sample=3;
  4346. //********************************(4)Power.Active.Import************************************************/
  4347. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4348. if(gunType[gun_index] == 'J')
  4349. {
  4350. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4351. {
  4352. tempIndex = ((gun_index==2) ? 1: 0);
  4353. }
  4354. else
  4355. {
  4356. tempIndex = gun_index;
  4357. }
  4358. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4359. {
  4360. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4361. {
  4362. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  4363. }
  4364. } // END OF FOR
  4365. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4366. }
  4367. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4368. {
  4369. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4370. {
  4371. tempIndex = ((gun_index==2) ? 1: 0);
  4372. }
  4373. else
  4374. {
  4375. tempIndex = gun_index;
  4376. }
  4377. for (int index = 0; index < CCS_QUANTITY; index++)
  4378. {
  4379. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4380. {
  4381. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  4382. }
  4383. }
  4384. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4385. }
  4386. else if(gunType[gun_index] == 'G')
  4387. {
  4388. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4389. {
  4390. tempIndex = ((gun_index==2) ? 1: 0);
  4391. }
  4392. else
  4393. {
  4394. tempIndex = gun_index;
  4395. }
  4396. for (int index = 0; index < GB_QUANTITY; index++)
  4397. {
  4398. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4399. {
  4400. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4401. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  4402. }
  4403. }
  4404. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4405. }
  4406. else
  4407. {
  4408. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4409. {
  4410. tempIndex = 2;
  4411. }
  4412. else
  4413. {
  4414. tempIndex = gun_index;
  4415. }
  4416. for (int index = 0; index < AC_QUANTITY; index++)
  4417. {
  4418. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4419. {
  4420. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  4421. }
  4422. }
  4423. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  4424. }
  4425. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  4426. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  4427. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  4428. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  4429. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  4430. //idx_sample=4;
  4431. //***********************************************(5)VOLTAGE L1******************************************************/
  4432. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4433. if(gunType[gun_index] == 'J')
  4434. {
  4435. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4436. {
  4437. tempIndex = ((gun_index==2) ? 1: 0);
  4438. }
  4439. else
  4440. {
  4441. tempIndex = gun_index;
  4442. }
  4443. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4444. {
  4445. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4446. {
  4447. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  4448. }
  4449. }
  4450. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4451. }
  4452. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4453. {
  4454. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4455. {
  4456. tempIndex = ((gun_index==2) ? 1: 0);
  4457. }
  4458. else
  4459. {
  4460. tempIndex = gun_index;
  4461. }
  4462. for (int index = 0; index < CCS_QUANTITY; index++)
  4463. {
  4464. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4465. {
  4466. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  4467. }
  4468. }
  4469. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4470. }
  4471. else if(gunType[gun_index] == 'G')
  4472. {
  4473. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4474. {
  4475. tempIndex = ((gun_index==2) ? 1: 0);
  4476. }
  4477. else
  4478. {
  4479. tempIndex = gun_index;
  4480. }
  4481. for (int index = 0; index < GB_QUANTITY; index++)
  4482. {
  4483. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4484. {
  4485. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  4486. }
  4487. }
  4488. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4489. }
  4490. else
  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->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  4505. }
  4506. }
  4507. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  4508. }
  4509. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  4510. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  4511. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  4512. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  4513. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4514. //***********************************************(6)SOC******************************************************/
  4515. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  4516. {
  4517. //idx_sample=5;
  4518. //sampledValue = NULL;
  4519. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4520. {
  4521. tempIndex = ((gun_index==2) ? 1: 0);
  4522. }
  4523. else
  4524. {
  4525. tempIndex = gun_index;
  4526. }
  4527. if(gunType[gun_index] == 'J')
  4528. {
  4529. //tempIndex = ((gun_index==2) ? 1: 0);
  4530. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4531. {
  4532. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4533. {
  4534. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  4535. }
  4536. }
  4537. }
  4538. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4539. {
  4540. //tempIndex = ((gun_index==2) ? 1: 0);
  4541. for (int index = 0; index < CCS_QUANTITY; index++)
  4542. {
  4543. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4544. {
  4545. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  4546. }
  4547. }
  4548. }
  4549. else if(gunType[gun_index] == 'G')
  4550. {
  4551. //tempIndex = ((gun_index==2) ? 1: 0);
  4552. for (int index = 0; index < GB_QUANTITY; index++)
  4553. {
  4554. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4555. {
  4556. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  4557. }
  4558. }
  4559. }
  4560. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4561. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  4562. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  4563. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  4564. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_Outlet]);
  4565. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  4566. }
  4567. //********************************(7)Current.Import L2************************************************/
  4568. // Only for AC 3 phase
  4569. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4570. {
  4571. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4572. {
  4573. tempIndex = 2;
  4574. }
  4575. else
  4576. {
  4577. tempIndex = gun_index;
  4578. }
  4579. for (int index = 0; index < AC_QUANTITY; index++)
  4580. {
  4581. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4582. {
  4583. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  4584. }
  4585. }
  4586. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  4587. }
  4588. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  4589. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  4590. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  4591. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  4592. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4593. //********************************(8)Current.Import L3************************************************/
  4594. // Only for AC 3 phase
  4595. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4596. {
  4597. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4598. {
  4599. tempIndex = 2;
  4600. }
  4601. else
  4602. {
  4603. tempIndex = gun_index;
  4604. }
  4605. for (int index = 0; index < AC_QUANTITY; index++)
  4606. {
  4607. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4608. {
  4609. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  4610. }
  4611. }
  4612. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  4613. }
  4614. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  4615. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  4616. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  4617. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  4618. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4619. //***********************************************(9)VOLTAGE L2******************************************************/
  4620. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4621. {
  4622. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4623. {
  4624. tempIndex = 2;
  4625. }
  4626. else
  4627. {
  4628. tempIndex = gun_index;
  4629. }
  4630. for (int index = 0; index < AC_QUANTITY; index++)
  4631. {
  4632. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4633. {
  4634. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  4635. }
  4636. }
  4637. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  4638. }
  4639. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  4640. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  4641. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  4642. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  4643. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4644. //***********************************************(10)VOLTAGE L3******************************************************/
  4645. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4646. {
  4647. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4648. {
  4649. tempIndex = 2;
  4650. }
  4651. else
  4652. {
  4653. tempIndex = gun_index;
  4654. }
  4655. for (int index = 0; index < AC_QUANTITY; index++)
  4656. {
  4657. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4658. {
  4659. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  4660. }
  4661. }
  4662. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  4663. }
  4664. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  4665. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  4666. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  4667. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  4668. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4669. // Message create ====================================================================================================
  4670. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  4671. {
  4672. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",{\"connectorId\":%d,\"transactionId\":%d,\"meterValue\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  4673. ,gun_index + 1
  4674. ,MESSAGE_TYPE_CALL
  4675. ,guid
  4676. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4677. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4678. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4679. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4680. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4681. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4682. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4683. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4684. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4685. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4686. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4687. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4688. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4689. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4690. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4691. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4692. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4693. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4694. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4695. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4696. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4697. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4698. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4699. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4700. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4701. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4702. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4703. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4704. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4705. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4706. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4707. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4708. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4709. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4710. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4711. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4712. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4713. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4714. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value
  4715. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context
  4716. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format
  4717. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand
  4718. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase
  4719. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location
  4720. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit
  4721. );
  4722. }
  4723. else
  4724. {
  4725. if((ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'W'))
  4726. {
  4727. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",{\"connectorId\":%d,\"transactionId\":%d,\"meterValue\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  4728. ,gun_index + 1
  4729. ,MESSAGE_TYPE_CALL
  4730. ,guid
  4731. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4732. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4733. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4734. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4735. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4736. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4737. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4738. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4739. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4740. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4741. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4742. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4743. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4744. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4745. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4746. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4747. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4748. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4749. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4750. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4751. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4752. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4753. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4754. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4755. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4756. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4757. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4758. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4759. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4760. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4761. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4762. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4763. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4764. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4765. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4766. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4767. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4768. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4769. );
  4770. }
  4771. else
  4772. {
  4773. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",{\"connectorId\":%d,\"transactionId\":%d,\"meterValue\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  4774. ,gun_index + 1
  4775. ,MESSAGE_TYPE_CALL
  4776. ,guid
  4777. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4778. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4779. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4780. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4781. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4782. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4783. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4784. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4785. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4786. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4787. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4788. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4789. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4790. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4791. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4792. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4793. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4794. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4795. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4796. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4797. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4798. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4799. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4800. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4801. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4802. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4803. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4804. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4805. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4806. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4807. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4808. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4809. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4810. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4811. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4812. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4813. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4814. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4815. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value
  4816. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context
  4817. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format
  4818. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand
  4819. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase
  4820. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location
  4821. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit
  4822. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value
  4823. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context
  4824. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format
  4825. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand
  4826. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase
  4827. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location
  4828. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit
  4829. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value
  4830. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context
  4831. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format
  4832. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand
  4833. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase
  4834. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location
  4835. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit
  4836. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value
  4837. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context
  4838. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format
  4839. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand
  4840. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase
  4841. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location
  4842. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit
  4843. );
  4844. }
  4845. }
  4846. // Put request guid to hash map
  4847. sprintf(tempdata, "MeterValues,%d", (gun_index));
  4848. 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*/)
  4849. {
  4850. result = PASS;
  4851. DEBUG_INFO("MeterValues mapitem pass\n");
  4852. }
  4853. if(dataType != ReadingContext_Trigger)
  4854. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4855. else
  4856. LWS_Send(queuedata +2);
  4857. /*
  4858. if(GetTransactionQueueNum() == 1)
  4859. {
  4860. LWS_Send(queuedata +2);
  4861. }*/
  4862. return result;
  4863. }
  4864. //==========================================
  4865. // send confirm routine
  4866. //==========================================
  4867. int sendCancelReservationConfirmation(char *uuid,char *payload)
  4868. {
  4869. mtrace();
  4870. int result = FAIL;
  4871. char message[100]={0};
  4872. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  4873. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4874. LWS_Send(message);
  4875. result = TRUE;
  4876. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  4877. return result;
  4878. }
  4879. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  4880. {
  4881. mtrace();
  4882. int result = FAIL;
  4883. char message[100]={0};
  4884. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  4885. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4886. LWS_Send(message);
  4887. result = TRUE;
  4888. return result;
  4889. }
  4890. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  4891. {
  4892. mtrace();
  4893. int result = FAIL;
  4894. char message[100]={0};
  4895. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  4896. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4897. LWS_Send(message);
  4898. result = TRUE;
  4899. return result;
  4900. }
  4901. int sendClearCacheConfirmation(char *uuid,char *payload)
  4902. {
  4903. mtrace();
  4904. int result = FAIL;
  4905. char message[500]={0};
  4906. DEBUG_INFO("sendClearCacheConfirmation...\n");
  4907. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4908. LWS_Send(message);
  4909. return result;
  4910. }
  4911. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  4912. {
  4913. mtrace();
  4914. int result = FAIL;
  4915. char message[500]={0};
  4916. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  4917. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4918. LWS_Send(message);
  4919. return result;
  4920. }
  4921. int sendDataTransferConfirmation(char *uuid,char *payload)
  4922. {
  4923. mtrace();
  4924. char statusStr[20]={0};
  4925. char dataStr[10]={0};
  4926. char sstr[20]={0};
  4927. int c = 0;
  4928. char *loc;
  4929. int result = FAIL;
  4930. DEBUG_INFO("sendDataTransferConfirmation...\n");
  4931. /**********************status**************************/
  4932. loc = strstr(payload, "status");
  4933. memset(sstr ,0, ARRAY_SIZE(sstr) );
  4934. c = 0;
  4935. while (loc[3+strlen("status")+c] != '\"')
  4936. {
  4937. sstr[c] = loc[3+strlen("status")+c];
  4938. c++;
  4939. }
  4940. sstr[c] = '\0';
  4941. strcpy(statusStr, sstr);
  4942. /**********************data**************************/
  4943. loc = strstr(payload, "data");
  4944. memset(sstr ,0, ARRAY_SIZE(sstr) );
  4945. c = 0;
  4946. while (loc[3+strlen("data")+c] != '\"')
  4947. {
  4948. sstr[c] = loc[3+strlen("data")+c];
  4949. c++;
  4950. }
  4951. sstr[c] = '\0';
  4952. strcpy(dataStr, sstr);
  4953. return result;
  4954. }
  4955. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  4956. {
  4957. mtrace();
  4958. int result = FAIL;
  4959. char message[1000]={0};
  4960. int CompositeScheduleIndex = 0;
  4961. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  4962. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  4963. if(nPeriod == 0)
  4964. {
  4965. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  4966. {
  4967. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  4968. ,MESSAGE_TYPE_CALLRESULT
  4969. ,uuid
  4970. ,payload
  4971. ,connectorIdInt);
  4972. }
  4973. else
  4974. {
  4975. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  4976. ,MESSAGE_TYPE_CALLRESULT
  4977. ,uuid
  4978. ,payload
  4979. ,connectorIdInt
  4980. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4981. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  4982. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4983. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  4984. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  4985. }
  4986. }
  4987. else
  4988. {
  4989. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  4990. ,MESSAGE_TYPE_CALLRESULT
  4991. ,uuid
  4992. ,payload
  4993. ,connectorIdInt
  4994. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4995. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  4996. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4997. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  4998. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  4999. {
  5000. if (idx_sample == 0)
  5001. {
  5002. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5003. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5004. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5005. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5006. }
  5007. else
  5008. {
  5009. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5010. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5011. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5012. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5013. }
  5014. }
  5015. sprintf(message + strlen(message), "]}}]");
  5016. }
  5017. LWS_Send(message);
  5018. result = TRUE;
  5019. return result;
  5020. }
  5021. int sendGetConfigurationConfirmation(char *uuid)
  5022. {
  5023. mtrace();
  5024. int result = FAIL;
  5025. int MaxKeySupported = 0;
  5026. int sentConfigurationNumber= 0;
  5027. int sentunConfigurationNumber= 0;
  5028. char message[4000]={0};
  5029. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5030. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5031. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5032. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5033. ,MESSAGE_TYPE_CALLRESULT
  5034. ,uuid );
  5035. //configuration key
  5036. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5037. {
  5038. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5039. {
  5040. if (sentConfigurationNumber == 0)
  5041. {
  5042. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5043. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5044. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5045. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5046. }
  5047. else
  5048. {
  5049. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5050. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5051. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5052. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5053. }
  5054. sentConfigurationNumber = sentConfigurationNumber + 1;
  5055. }
  5056. }
  5057. sprintf(message + strlen(message), "]");
  5058. if(UnknownKeynum != 0)
  5059. {
  5060. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5061. //unkown key
  5062. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5063. {
  5064. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5065. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5066. if(sentunConfigurationNumber == 0)
  5067. {
  5068. sprintf(message + strlen(message), "\"%s\""
  5069. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5070. }
  5071. else
  5072. {
  5073. sprintf(message + strlen(message), ",\"%s\""
  5074. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5075. }
  5076. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5077. }
  5078. sprintf(message + strlen(message), "]");
  5079. }
  5080. sprintf(message + strlen(message), "}]");
  5081. LWS_Send(message);
  5082. return result;
  5083. }
  5084. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5085. {
  5086. mtrace();
  5087. int result = FAIL;
  5088. char message[400]={0};
  5089. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5090. if(strcmp(payload,"")==0)
  5091. {
  5092. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5093. }
  5094. else
  5095. {
  5096. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5097. }
  5098. LWS_Send(message);
  5099. result = TRUE;
  5100. return result;
  5101. }
  5102. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5103. {
  5104. mtrace();
  5105. int result = FAIL;
  5106. char message[80]={0};
  5107. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5108. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  5109. LWS_Send(message);
  5110. result = TRUE;
  5111. return result;
  5112. }
  5113. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5114. {
  5115. mtrace();
  5116. int result = FAIL;
  5117. char message[80]={0};
  5118. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5119. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5120. LWS_Send(message);
  5121. result = TRUE;
  5122. return result;
  5123. }
  5124. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5125. {
  5126. mtrace();
  5127. int result = FAIL;
  5128. char message[80]={0};
  5129. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5130. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5131. LWS_Send(message);
  5132. result = TRUE;
  5133. return result;
  5134. }
  5135. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5136. {
  5137. mtrace();
  5138. int result = FAIL;
  5139. char message[80]={0};
  5140. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5141. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5142. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5143. LWS_Send(message);
  5144. result = TRUE;
  5145. return result;
  5146. }
  5147. int sendResetConfirmation(char *uuid,char *payload)
  5148. {
  5149. mtrace();
  5150. int result = FAIL;
  5151. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  5152. char message[80]={0};
  5153. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  5154. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5155. LWS_Send(message);
  5156. result = TRUE;
  5157. return result;
  5158. }
  5159. int sendSendLocalListConfirmation(char *uuid,char *payload)
  5160. {
  5161. mtrace();
  5162. int result = FAIL;
  5163. char message[500]={0};
  5164. // [ 3, "1571284266109", { "status": "Accepted" } ]
  5165. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5166. LWS_Send(message);
  5167. result = TRUE;
  5168. return result;
  5169. }
  5170. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  5171. {
  5172. mtrace();
  5173. int result = FAIL;
  5174. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  5175. char message[80]={0};
  5176. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  5177. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5178. LWS_Send(message);
  5179. result = TRUE;
  5180. return result;
  5181. }
  5182. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  5183. {
  5184. mtrace();
  5185. int result = FAIL;
  5186. char message[80]={0};
  5187. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  5188. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5189. LWS_Send(message);
  5190. result = TRUE;
  5191. return result;
  5192. }
  5193. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  5194. {
  5195. mtrace();
  5196. int result = FAIL;
  5197. char message[80]={0};
  5198. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5199. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  5200. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5201. LWS_Send(message);
  5202. result = TRUE;
  5203. return result;
  5204. }
  5205. int sendUpdateFirmwareConfirmation(char *uuid)
  5206. {
  5207. mtrace();
  5208. int result = FAIL;
  5209. char message[60]={0};
  5210. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5211. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  5212. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5213. LWS_Send(message);
  5214. result = TRUE;
  5215. return result;
  5216. }
  5217. //==========================================
  5218. // send CallError routine
  5219. //==========================================
  5220. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  5221. {
  5222. mtrace();
  5223. char message[220]={0};
  5224. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  5225. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  5226. LWS_Send(message);
  5227. }
  5228. //==========================================
  5229. // Handle server request routine Start
  5230. //==========================================
  5231. int handleCancelReservationRequest(char *uuid, char *payload)
  5232. {
  5233. mtrace();
  5234. int result = FAIL;
  5235. int gunNO = 0;
  5236. int reservationIdInt =0;
  5237. char comfirmstr[20];
  5238. DEBUG_INFO("handleCancelReservationRequest...\n");
  5239. json_object *CancelReservation;
  5240. CancelReservation = json_tokener_parse(payload);
  5241. if(!is_error(CancelReservation))
  5242. {
  5243. // Required data
  5244. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  5245. }
  5246. json_object_put(CancelReservation);
  5247. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5248. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  5249. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  5250. //check Transaction active
  5251. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5252. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5253. {
  5254. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  5255. {
  5256. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5257. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5258. if(gunType[2] == 'J')
  5259. {
  5260. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  5261. }
  5262. else
  5263. {
  5264. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  5265. }
  5266. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5267. goto end;
  5268. }
  5269. }
  5270. for (int index = 0; index < CCS_QUANTITY; index++)
  5271. {
  5272. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  5273. {
  5274. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5275. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5276. if((gunType[2] == 'U') || (gunType[2] == 'E'))
  5277. {
  5278. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  5279. }
  5280. else
  5281. {
  5282. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  5283. }
  5284. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5285. goto end;
  5286. }
  5287. }
  5288. for (int index = 0; index < GB_QUANTITY; index++)
  5289. {
  5290. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  5291. {
  5292. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5293. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5294. if(gunType[2] == 'G')
  5295. {
  5296. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  5297. }
  5298. else
  5299. {
  5300. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  5301. }
  5302. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5303. goto end;
  5304. }
  5305. }
  5306. for (int index = 0; index < AC_QUANTITY; index++)
  5307. {
  5308. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  5309. {
  5310. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5311. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5312. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5313. {
  5314. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  5315. }
  5316. else
  5317. {
  5318. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  5319. }
  5320. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5321. goto end;
  5322. }
  5323. }
  5324. //The reservationId does NOT match the reservationId
  5325. sendCancelReservationConfirmation(uuid, comfirmstr);
  5326. end:
  5327. // Fill in ocpp packet uuid
  5328. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  5329. return result;
  5330. }
  5331. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  5332. {
  5333. mtrace();
  5334. int result = FAIL;
  5335. int gunIndex = 0;
  5336. char typeStr[16]={0};
  5337. char comfirmstr[20];
  5338. int specificId = FALSE;
  5339. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  5340. json_object *ChangeAvailability;
  5341. ChangeAvailability = json_tokener_parse(payload);
  5342. if(!is_error(ChangeAvailability))
  5343. {
  5344. // Required data
  5345. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  5346. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  5347. }
  5348. json_object_put(ChangeAvailability);
  5349. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5350. {
  5351. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  5352. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  5353. }
  5354. else if(gunIndex == 0)
  5355. {
  5356. for(int i=0; i < gunTotalNumber; i++)
  5357. {
  5358. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  5359. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  5360. }
  5361. }
  5362. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5363. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5364. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  5365. {
  5366. specificId = TRUE;
  5367. }
  5368. if(specificId == FALSE)
  5369. goto end;
  5370. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  5371. {
  5372. //----------------------gunIndex is 0 ------------------------------------------------//
  5373. if(gunIndex == 0)
  5374. {
  5375. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5376. {
  5377. for(int i=0; i < gunTotalNumber; i++)
  5378. {
  5379. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5380. {
  5381. if ((gunType[i] == 'J')&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  5382. {
  5383. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5384. {
  5385. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5386. goto end;
  5387. }
  5388. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5389. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5390. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5391. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5392. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5393. {
  5394. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5395. goto end;
  5396. }
  5397. }
  5398. }//END FOR CHAdeMO_QUANTITY
  5399. for (int index = 0; index < CCS_QUANTITY; index++)
  5400. {
  5401. if (((gunType[i] == 'U')||(gunType[i] == 'E'))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  5402. {
  5403. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  5404. {
  5405. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5406. goto end;
  5407. }
  5408. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5409. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5410. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5411. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5412. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5413. {
  5414. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5415. goto end;
  5416. }
  5417. }
  5418. }//END FOR CCS_QUANTITY
  5419. for (int index = 0; index < GB_QUANTITY; index++)
  5420. {
  5421. if ((gunType[i] == 'G')&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  5422. {
  5423. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5424. {
  5425. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5426. goto end;
  5427. }
  5428. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5429. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5430. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5431. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5432. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5433. {
  5434. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5435. goto end;
  5436. }
  5437. }
  5438. }// END FOR GB_QUANTITY
  5439. for (int index = 0; index < AC_QUANTITY; index++)
  5440. {
  5441. if (((gunType[i] > '0')&&(gunType[i] <= '9'))&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  5442. {
  5443. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5444. {
  5445. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5446. goto end;
  5447. }
  5448. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5449. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5450. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5451. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5452. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5453. {
  5454. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5455. goto end;
  5456. }
  5457. }
  5458. }//END FOR AC_QUANTITY
  5459. }// END FOR gunTotalNumber
  5460. }
  5461. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5462. {
  5463. for(int i=0; i < gunTotalNumber; i++)
  5464. {
  5465. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5466. {
  5467. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5468. goto end;
  5469. }
  5470. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5471. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  5472. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  5473. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  5474. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5475. {
  5476. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5477. goto end;
  5478. }
  5479. }
  5480. }
  5481. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5482. goto end;
  5483. }
  5484. //----------------------gunIndex is not 0 ------------------------------------------------//
  5485. //check Transaction active
  5486. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5487. {
  5488. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J'))
  5489. {
  5490. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  5491. {
  5492. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5493. goto end;
  5494. }
  5495. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5496. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5497. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5498. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5499. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5500. {
  5501. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5502. goto end;
  5503. }
  5504. else
  5505. {
  5506. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  5507. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5508. goto end;
  5509. }
  5510. }
  5511. }//END FOR CHAdeMO_QUANTITY
  5512. for (int index = 0; index < CCS_QUANTITY; index++)
  5513. {
  5514. if ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E')))
  5515. {
  5516. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  5517. {
  5518. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5519. goto end;
  5520. }
  5521. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5522. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5523. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5524. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5525. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5526. {
  5527. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5528. goto end;
  5529. }
  5530. else
  5531. {
  5532. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  5533. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5534. goto end;
  5535. }
  5536. }
  5537. }//END FOR CCS_QUANTITY
  5538. for (int index = 0; index < GB_QUANTITY; index++)
  5539. {
  5540. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))
  5541. {
  5542. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5543. {
  5544. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5545. goto end;
  5546. }
  5547. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5548. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5549. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5550. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5551. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5552. {
  5553. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5554. goto end;
  5555. }
  5556. else
  5557. {
  5558. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  5559. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5560. goto end;
  5561. }
  5562. }
  5563. }// END FOR GB_QUANTITY
  5564. for (int index = 0; index < AC_QUANTITY; index++)
  5565. {
  5566. if ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))
  5567. {
  5568. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5569. {
  5570. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5571. goto end;
  5572. }
  5573. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5574. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5575. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5576. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5577. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5578. {
  5579. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5580. goto end;
  5581. }
  5582. else
  5583. {
  5584. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  5585. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5586. goto end;
  5587. }
  5588. }
  5589. }//END FOR AC_QUANTITY
  5590. }//END FOR AvailabilityTypeStr[Inoperative]
  5591. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  5592. {
  5593. //----------------------gunIndex is 0 ------------------------------------------------//
  5594. if(gunIndex == 0)
  5595. {
  5596. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5597. {
  5598. for(int i=0; i < gunTotalNumber; i++)
  5599. {
  5600. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5601. {
  5602. if ((gunType[i] == 'J' )&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J')) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5603. {
  5604. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5605. goto end;
  5606. }
  5607. }//END FOR CHAdeMO_QUANTITY
  5608. for (int index = 0; index < CCS_QUANTITY; index++)
  5609. {
  5610. if (((gunType[i] == 'U')||(gunType[i] == 'E'))&&(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
  5611. {
  5612. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5613. goto end;
  5614. }
  5615. }//END FOR CCS_QUANTITY
  5616. for (int index = 0; index < GB_QUANTITY; index++)
  5617. {
  5618. if ((gunType[i] == 'G')&&(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
  5619. {
  5620. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5621. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5622. goto end;
  5623. }
  5624. }// END FOR GB_QUANTITY
  5625. for (int index = 0; index < AC_QUANTITY; index++)
  5626. {
  5627. if (((gunType[i] > '0')&&(gunType[i] <= '9')) &&(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
  5628. {
  5629. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5630. goto end;
  5631. }
  5632. }//END FOR CHAdeMO_QUANTITY
  5633. }// END FOR gunTotalNumber
  5634. }
  5635. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5636. {
  5637. for(int i=0; i < gunTotalNumber; i++)
  5638. {
  5639. for (int index = 0; index < AC_QUANTITY; index++)
  5640. {
  5641. if (((gunType[i] > '0')&&(gunType[i] <= '9')) &&(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
  5642. {
  5643. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5644. goto end;
  5645. }
  5646. }//END FOR CHAdeMO_QUANTITY
  5647. } // END FOR gunTotalNumber
  5648. }
  5649. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5650. goto end;
  5651. }
  5652. //----------------------gunIndex is not 0 ------------------------------------------------//
  5653. //check Transaction active
  5654. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5655. {
  5656. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'J') ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5657. {
  5658. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5659. goto end;
  5660. }
  5661. }//END FOR CHAdeMO_QUANTITY
  5662. for (int index = 0; index < CCS_QUANTITY; index++)
  5663. {
  5664. if ((((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5665. {
  5666. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5667. goto end;
  5668. }
  5669. }//END FOR CCS_QUANTITY
  5670. for (int index = 0; index < GB_QUANTITY; index++)
  5671. {
  5672. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5673. {
  5674. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5675. goto end;
  5676. }
  5677. }// END FOR GB_QUANTITY
  5678. for (int index = 0; index < AC_QUANTITY; index++)
  5679. {
  5680. if (((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9'))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5681. {
  5682. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5683. goto end;
  5684. }
  5685. }//END FOR AC_QUANTITY
  5686. }//END FOR AvailabilityTypeStr[Operative]
  5687. end:
  5688. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5689. {
  5690. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  5691. }
  5692. else
  5693. {
  5694. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  5695. }
  5696. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5697. {
  5698. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5699. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5700. }
  5701. else if(gunIndex == 0)
  5702. {
  5703. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5704. {
  5705. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  5706. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  5707. }
  5708. }
  5709. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  5710. return result;
  5711. }
  5712. int handleChangeConfigurationRequest(char *uuid, char *payload)
  5713. {
  5714. mtrace();
  5715. int result = FAIL;
  5716. char keystr[40]={0};
  5717. char valuestr[100]={0};
  5718. char comfirmstr[20]={0};
  5719. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  5720. json_object *ChangeConfiguration;
  5721. ChangeConfiguration = json_tokener_parse(payload);
  5722. if(!is_error(ChangeConfiguration))
  5723. {
  5724. // Required data
  5725. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  5726. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  5727. }
  5728. json_object_put(ChangeConfiguration);
  5729. if((uuid==NULL) || (payload ==NULL) )
  5730. {
  5731. DEBUG_ERROR("Payload is null\n");
  5732. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5733. }
  5734. else
  5735. {
  5736. int status = setKeyValue(keystr, valuestr);
  5737. switch(status)
  5738. {
  5739. case ConfigurationStatus_Accepted:
  5740. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  5741. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  5742. StoreConfigurationTable();
  5743. break;
  5744. case ConfigurationStatus_Rejected:
  5745. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5746. break;
  5747. case RebootRequired:
  5748. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  5749. StoreConfigurationTable();
  5750. break;
  5751. case NotSupported:
  5752. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  5753. break;
  5754. default:
  5755. break;
  5756. }
  5757. }
  5758. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  5759. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  5760. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  5761. {
  5762. ChageWebSocketPingInterval(atoi(valuestr));
  5763. }
  5764. return result;
  5765. }
  5766. int handleClearCacheRequest(char *uuid, char *payload)
  5767. {
  5768. mtrace();
  5769. int result = FAIL;
  5770. char comfirmstr[20];
  5771. int fd;
  5772. char rmFileCmd[100]={0};
  5773. struct stat stats;
  5774. DEBUG_INFO("handleClearCacheRequest...\n");
  5775. stat("/Storage/OCPP", &stats);
  5776. // Check for directory existence
  5777. if (S_ISDIR(stats.st_mode) == 1)
  5778. {}
  5779. else
  5780. {
  5781. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  5782. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  5783. system(rmFileCmd);
  5784. }
  5785. memset(rmFileCmd, 0, ARRAY_SIZE(rmFileCmd));
  5786. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  5787. {
  5788. DEBUG_INFO("AuthorizationCache file exist.\n");
  5789. }
  5790. else
  5791. {
  5792. DEBUG_INFO("AuthorizationCache file not exist\n");
  5793. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  5794. if(log == NULL)
  5795. {
  5796. DEBUG_INFO("AuthorizationCache file is NULL\n");
  5797. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5798. goto end;
  5799. }
  5800. else
  5801. {
  5802. fclose(log);
  5803. }
  5804. }
  5805. if((fd = open(AuthorizationCache_JSON,O_RDWR)) < 0)
  5806. {
  5807. DEBUG_INFO("open AuthorizationCache file failed\n");
  5808. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5809. }
  5810. else
  5811. {
  5812. DEBUG_INFO("open AuthorizationCache file successful\n");
  5813. ftruncate(fd,0);
  5814. lseek(fd,0,SEEK_SET);
  5815. close(fd);
  5816. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  5817. }
  5818. end:
  5819. sendClearCacheConfirmation(uuid, comfirmstr);
  5820. return result;
  5821. }
  5822. int handleClearChargingProfileRequest(char *uuid, char *payload)
  5823. {
  5824. mtrace();
  5825. int result = FAIL;
  5826. int resultRename;
  5827. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  5828. char chargingProfilePurposeStr[26]={0};
  5829. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  5830. char tempchargingProfilePurposeStr[26]={0};
  5831. char sstr[160]={0};
  5832. char str[100]={0};
  5833. int c = 0;
  5834. char *loc;
  5835. char fname[200]={0};
  5836. char comfirmstr[20]={0};
  5837. char word[1600]={0};
  5838. int clearflag = FALSE;
  5839. int chargingProfileIdIsNULL = FALSE;
  5840. int connectorIsNULL = FALSE;
  5841. int chargingProfilePurposeIsNULL = FALSE;
  5842. int stackLevelIsNULL = FALSE;
  5843. //int GotoEnd = FALSE;
  5844. FILE *fptr1, *fptr2;
  5845. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  5846. int n_chargingProfile=0;
  5847. int isEmptyFile = FALSE;
  5848. char sLineWord[1600]={0};
  5849. char chargingProfiles[10][100]={0};
  5850. int ChargeProfileCount = 0;
  5851. char ch;
  5852. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  5853. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  5854. json_object *ClearChargingProfile;
  5855. ClearChargingProfile = json_tokener_parse(payload);
  5856. if(!is_error(ClearChargingProfile))
  5857. {
  5858. // Optional data
  5859. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  5860. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  5861. else
  5862. chargingProfileIdIsNULL = TRUE;
  5863. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  5864. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  5865. else
  5866. connectorIsNULL = TRUE;
  5867. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  5868. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  5869. else
  5870. chargingProfilePurposeIsNULL = TRUE;
  5871. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  5872. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  5873. else
  5874. stackLevelIsNULL = TRUE;
  5875. }
  5876. json_object_put(ClearChargingProfile);
  5877. if(connectorIsNULL == FALSE)
  5878. {
  5879. switch(connectorIdInt)
  5880. {
  5881. case 0:
  5882. if(chargingProfilePurposeIsNULL == TRUE)
  5883. {
  5884. int l = 0;
  5885. strcpy(fname, ChargePointMaxProfile_JSON);
  5886. if((access(fname,F_OK))!=-1)
  5887. {
  5888. strcpy(chargingProfiles[l], fname);
  5889. l = l + 1;
  5890. }
  5891. strcpy(fname, TxDefaultProfile_0_JSON);
  5892. if((access(fname,F_OK))!=-1)
  5893. {
  5894. strcpy(chargingProfiles[l], fname);
  5895. l = l + 1;
  5896. }
  5897. ChargeProfileCount = l;
  5898. }
  5899. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  5900. {
  5901. strcpy(fname, ChargePointMaxProfile_JSON);
  5902. if((access(fname,F_OK))!=-1)
  5903. {
  5904. strcpy(chargingProfiles[0], fname);
  5905. ChargeProfileCount = 1;
  5906. }
  5907. }
  5908. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5909. {
  5910. strcpy(fname, TxDefaultProfile_0_JSON);
  5911. if((access(fname,F_OK))!=-1)
  5912. {
  5913. strcpy(chargingProfiles[0], fname);
  5914. ChargeProfileCount = 1;
  5915. }
  5916. }
  5917. break;
  5918. default:
  5919. if(chargingProfilePurposeIsNULL == TRUE)
  5920. {
  5921. int m = 0;
  5922. memset(fname, 0, ARRAY_SIZE(fname));
  5923. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5924. if((access(fname,F_OK))!=-1)
  5925. {
  5926. strcpy(chargingProfiles[m], fname);
  5927. m = m + 1;
  5928. }
  5929. memset(fname, 0, ARRAY_SIZE(fname));
  5930. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5931. if((access(fname,F_OK))!=-1)
  5932. {
  5933. strcpy(chargingProfiles[m], fname);
  5934. m = m + 1;
  5935. }
  5936. ChargeProfileCount = m;
  5937. }
  5938. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5939. {
  5940. //strcpy(fname, TxDefaultProfile_1_JSON);
  5941. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5942. if((access(fname,F_OK))!=-1)
  5943. {
  5944. strcpy(chargingProfiles[0], fname);
  5945. ChargeProfileCount = 1;
  5946. }
  5947. }
  5948. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  5949. {
  5950. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5951. if((access(fname,F_OK))!=-1)
  5952. {
  5953. strcpy(chargingProfiles[0], fname);
  5954. ChargeProfileCount = 1;
  5955. }
  5956. //strcpy(fname, TxProfile_1_JSON);
  5957. }
  5958. //strcpy(fname, ChargePointMaxProfile_JSON );
  5959. break;
  5960. }
  5961. }
  5962. else // Check all Charging Profiles
  5963. {
  5964. int i = 0;
  5965. char fnametemp[200]={0};
  5966. ChargeProfileCount = 0;
  5967. //Check ChargePointMaxProfile.json exit
  5968. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  5969. {
  5970. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  5971. i = i + 1;
  5972. }
  5973. //Check TxDefaultProfile_0.json exit
  5974. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  5975. {
  5976. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  5977. i = i + 1;
  5978. }
  5979. //Check TxDefaultProfile_%d.json
  5980. for(int j=1; j <= gunTotalNumber; j++)
  5981. {
  5982. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  5983. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  5984. if((access(fnametemp,F_OK))!=-1)
  5985. {
  5986. strcpy(chargingProfiles[i], fnametemp);
  5987. i = i + 1;
  5988. }
  5989. }
  5990. //Check TxProfile_%d.json
  5991. for(int j=1; j <= gunTotalNumber; j++)
  5992. {
  5993. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  5994. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  5995. if((access(fnametemp,F_OK))!=-1)
  5996. {
  5997. strcpy(chargingProfiles[i], fnametemp);
  5998. i = i + 1;
  5999. }
  6000. }
  6001. ChargeProfileCount = i;
  6002. }// End connectorIsNULL is TRUE
  6003. if(ChargeProfileCount == 0)
  6004. {
  6005. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6006. goto end;
  6007. }
  6008. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  6009. {
  6010. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6011. goto end;
  6012. }
  6013. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  6014. {
  6015. memset(str, 0, ARRAY_SIZE(str));
  6016. // clear temp file
  6017. sprintf(str,"rm -f %s",temp);
  6018. system(str);
  6019. for(int k=0; k < ChargeProfileCount; k++)
  6020. {
  6021. memset(str, 0, ARRAY_SIZE(str));
  6022. //clear file in C
  6023. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6024. system(str);
  6025. }
  6026. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6027. goto end;
  6028. }
  6029. else if(connectorIsNULL == TRUE)
  6030. {
  6031. for(int k=0; k < ChargeProfileCount; k++)
  6032. {
  6033. fptr1 = fopen(chargingProfiles[k], "r");
  6034. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  6035. //Check Charging Profile Count
  6036. while(fscanf(fptr1, "%s", word) != EOF)
  6037. {
  6038. //DEBUG_INFO("word=%s\n",word);
  6039. if(strstr(word, "chargingProfileId")!= NULL)
  6040. {
  6041. //DEBUG_INFO("test chargingProfileId \n");
  6042. n_chargingProfile = n_chargingProfile + 1;
  6043. //DEBUG_INFO("chargingProfileId Found\n");
  6044. }
  6045. }
  6046. rewind(fptr1);
  6047. //search Charging Profile Element
  6048. //int i= 0;
  6049. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6050. {
  6051. //------------------------tempconnectorIdInt------------------------//
  6052. loc = strstr(sLineWord, "connectorId");
  6053. c = 0;
  6054. memset(sstr ,0, sizeof(sstr) );
  6055. while (loc[strlen("connectorId")+2+c] != ',')
  6056. {
  6057. sstr[c] = loc[strlen("connectorId")+2+c];
  6058. c++;
  6059. }
  6060. sstr[c] = '\0';
  6061. tempconnectorIdInt = atoi(sstr);
  6062. printf("file's gun number is %d\n", tempconnectorIdInt);
  6063. //--------------------------chargingProfileId--------------------//
  6064. c = 0;
  6065. loc = strstr(sLineWord, "chargingProfileId");
  6066. memset(sstr ,0, ARRAY_SIZE(sstr));
  6067. while (loc[strlen("chargingProfileId")+2+c] != ',')
  6068. {
  6069. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6070. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6071. c++;
  6072. }
  6073. sstr[c] = '\0';
  6074. tempchargingProfileIdInt = atoi(sstr);
  6075. //stackLevel
  6076. c = 0;
  6077. loc = strstr(sLineWord, "stackLevel");
  6078. memset(sstr ,0, ARRAY_SIZE(sstr));
  6079. while (loc[strlen("stackLevel")+2+c] != ',')
  6080. {
  6081. sstr[c] = loc[strlen("stackLevel")+2+c];
  6082. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6083. c++;
  6084. }
  6085. sstr[c] = '\0';
  6086. tempstackLevelInt = atoi(sstr);
  6087. c = 0;
  6088. loc = strstr(sLineWord, "chargingProfilePurpose");
  6089. memset(sstr ,0, ARRAY_SIZE(sstr));
  6090. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6091. {
  6092. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6093. c++;
  6094. }
  6095. sstr[c] = '\0';
  6096. strcpy(tempchargingProfilePurposeStr, sstr);
  6097. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6098. {
  6099. //------- not write to fptr2-------//
  6100. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6101. //clearflag = TRUE;
  6102. }
  6103. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  6104. {
  6105. //------- not write to fptr2-------//
  6106. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6107. }
  6108. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6109. {
  6110. //------- not write to fptr2-------//
  6111. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6112. }
  6113. else
  6114. {
  6115. fprintf(fptr2, sLineWord);//writing data into file
  6116. }
  6117. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6118. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6119. if(clearflag == TRUE)
  6120. {
  6121. fclose(fptr1);
  6122. fclose(fptr2);
  6123. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6124. system(str);
  6125. // clear temp file
  6126. sprintf(str,"rm -f %s",temp);
  6127. system(str);
  6128. }
  6129. else
  6130. {
  6131. fclose(fptr1);
  6132. fclose(fptr2);
  6133. memset(str, 0, ARRAY_SIZE(str));
  6134. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6135. system(str);
  6136. resultRename = rename(temp, chargingProfiles[k]);
  6137. if(resultRename == 0)
  6138. {
  6139. DEBUG_INFO("File ChargingProfile renamed successfully");
  6140. }
  6141. else
  6142. {
  6143. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6144. }
  6145. if(comfirmstr[0]== 0)
  6146. {
  6147. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6148. }
  6149. //Check chargingProfile is empty file
  6150. /*------ Read the file ----------------*/
  6151. fptr1=fopen(chargingProfiles[k],"r");
  6152. ch=fgetc(fptr1);
  6153. rewind(fptr1);
  6154. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6155. if(ch!=EOF)
  6156. {
  6157. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6158. {
  6159. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6160. if(sLineWord[0]=='\0')
  6161. {
  6162. isEmptyFile = TRUE;
  6163. break;
  6164. }
  6165. else
  6166. {
  6167. isEmptyFile = FALSE;
  6168. break;
  6169. }
  6170. }
  6171. }
  6172. fclose(fptr1);
  6173. if(isEmptyFile == TRUE)
  6174. {
  6175. memset(str, 0, ARRAY_SIZE(str));
  6176. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6177. system(str);
  6178. }
  6179. }
  6180. }// End of while(int k=0; k < ChargePointCount; k++)
  6181. }
  6182. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  6183. {
  6184. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  6185. for(int k=0; k < ChargeProfileCount; k++)
  6186. {
  6187. fptr1 = fopen(chargingProfiles[k], "r");
  6188. fptr2 = fopen(temp, "w+");
  6189. //Check Charging Profile Count
  6190. while(fscanf(fptr1, "%s", word) != EOF)
  6191. {
  6192. //DEBUG_INFO("word=%s\n",word);
  6193. if(strstr(word, "chargingProfileId")!= NULL)
  6194. {
  6195. n_chargingProfile = n_chargingProfile + 1;
  6196. }
  6197. }
  6198. rewind(fptr1);
  6199. //search Charging Profile Element
  6200. //int i= 0;
  6201. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6202. {
  6203. //*************************tempconnectorIdInt*********************************/
  6204. loc = strstr(sLineWord, "connectorId");
  6205. c = 0;
  6206. memset(sstr ,0, ARRAY_SIZE(sstr));
  6207. while (loc[strlen("connectorId")+2+c] != ',')
  6208. {
  6209. sstr[c] = loc[strlen("connectorId")+2+c];
  6210. c++;
  6211. }
  6212. sstr[c] = '\0';
  6213. tempconnectorIdInt = atoi(sstr);
  6214. //chargingProfileId
  6215. c = 0;
  6216. loc = strstr(sLineWord, "chargingProfileId");
  6217. memset(sstr ,0, ARRAY_SIZE(sstr));
  6218. while (loc[strlen("chargingProfileId")+2+c] != ',')
  6219. {
  6220. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6221. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6222. c++;
  6223. }
  6224. sstr[c] = '\0';
  6225. tempchargingProfileIdInt = atoi(sstr);
  6226. //stackLevel
  6227. c = 0;
  6228. loc = strstr(sLineWord, "stackLevel");
  6229. memset(sstr ,0, ARRAY_SIZE(sstr));
  6230. while (loc[strlen("stackLevel")+2+c] != ',')
  6231. {
  6232. sstr[c] = loc[strlen("stackLevel")+2+c];
  6233. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6234. c++;
  6235. }
  6236. sstr[c] = '\0';
  6237. tempstackLevelInt = atoi(sstr);
  6238. c = 0;
  6239. loc = strstr(sLineWord, "chargingProfilePurpose");
  6240. memset(sstr ,0, ARRAY_SIZE(sstr));
  6241. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6242. {
  6243. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6244. c++;
  6245. }
  6246. sstr[c] = '\0';
  6247. strcpy(tempchargingProfilePurposeStr, sstr);
  6248. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6249. {
  6250. //------- not write to fptr2-------//
  6251. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6252. //clearflag = TRUE;
  6253. }
  6254. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6255. {
  6256. //------- not write to fptr2-------//
  6257. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6258. }
  6259. else if(stackLevelIsNULL == TRUE)
  6260. {
  6261. //Clear Whole File
  6262. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6263. clearflag = TRUE;
  6264. break;
  6265. }
  6266. else
  6267. {
  6268. fprintf(fptr2, sLineWord);//writing data into file
  6269. }
  6270. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6271. }
  6272. if(clearflag == TRUE)
  6273. {
  6274. fclose(fptr1);
  6275. fclose(fptr2);
  6276. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6277. system(str);
  6278. // clear temp file
  6279. sprintf(str,"rm -f %s",temp);
  6280. system(str);
  6281. }
  6282. else
  6283. {
  6284. fclose(fptr1);
  6285. fclose(fptr2);
  6286. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6287. system(str);
  6288. resultRename = rename(temp, chargingProfiles[k]);
  6289. if(resultRename == 0)
  6290. {
  6291. DEBUG_INFO("File ChargingProfile renamed successfully");
  6292. }
  6293. else
  6294. {
  6295. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6296. }
  6297. if(comfirmstr[0]== 0)
  6298. {
  6299. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6300. }
  6301. //Check chargingProfile is empty file
  6302. /*------ Read the file ----------------*/
  6303. fptr1=fopen(chargingProfiles[k],"r");
  6304. ch=fgetc(fptr1);
  6305. rewind(fptr1);
  6306. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6307. if(ch!=EOF)
  6308. {
  6309. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6310. {
  6311. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6312. if(sLineWord[0]=='\0')
  6313. {
  6314. isEmptyFile = TRUE;
  6315. break;
  6316. }
  6317. else
  6318. {
  6319. isEmptyFile = FALSE;
  6320. break;
  6321. }
  6322. }
  6323. }
  6324. fclose(fptr1);
  6325. if(isEmptyFile == TRUE)
  6326. {
  6327. memset(str, 0, ARRAY_SIZE(str));
  6328. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6329. system(str);
  6330. }
  6331. /*------- End of reading ---------------*/
  6332. }
  6333. } // while(int k=0; k < ChargeProfileCount; k++)
  6334. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  6335. end:
  6336. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  6337. return result;
  6338. }
  6339. void createFirmwareVersionByDataTransfer(void)
  6340. {
  6341. json_object *FirmwareDataTransfer = json_object_new_object();
  6342. // AC & DC model
  6343. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  6344. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  6345. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  6346. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  6347. // DC model
  6348. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  6349. {
  6350. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6351. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6352. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  6353. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  6354. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6355. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6356. }
  6357. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  6358. ((gunType[1] != '0') || (gunType[2] != '0') || (gunType[3] != '0')))
  6359. {
  6360. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  6361. }
  6362. // 4G model
  6363. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T'))
  6364. {
  6365. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  6366. }
  6367. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "Phihong Technology");
  6368. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  6369. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string(FirmwareDataTransfer));
  6370. }
  6371. int handleDataTransferRequest(char *uuid, char *payload)
  6372. {
  6373. mtrace();
  6374. json_object *response = json_object_new_object();
  6375. int result = FAIL;
  6376. char tempvendorId[255]={0};
  6377. char tempmessageId[50]={0};
  6378. char tempdata[512]={0};
  6379. char message[2048]={0};
  6380. DEBUG_INFO("handleDataTransferRequest...\n");
  6381. if((uuid != NULL) && (payload != NULL))
  6382. {
  6383. json_object *DataTransfer;
  6384. DataTransfer = json_tokener_parse(payload);
  6385. if(!is_error(DataTransfer))
  6386. {
  6387. // Required data
  6388. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  6389. // Optional data
  6390. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  6391. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  6392. if(json_object_object_get(DataTransfer, "data") != NULL)
  6393. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  6394. result = PASS;
  6395. }
  6396. json_object_put(DataTransfer);
  6397. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  6398. {
  6399. // Send all moudle firmware version on EVSE
  6400. system("/usr/bin/run_tmate_restart.sh");
  6401. createFirmwareVersionByDataTransfer();
  6402. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6403. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  6404. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string(response));
  6405. }
  6406. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  6407. {
  6408. json_object *data;
  6409. data = json_tokener_parse(tempdata);
  6410. if(!is_error(data))
  6411. {
  6412. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  6413. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  6414. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  6415. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  6416. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  6417. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  6418. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  6419. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  6420. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  6421. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  6422. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6423. }
  6424. else
  6425. {
  6426. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6427. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6428. }
  6429. json_object_put(data);
  6430. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string(response));
  6431. }
  6432. else
  6433. {
  6434. // Can not find valid message id
  6435. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  6436. }
  6437. }
  6438. else
  6439. {
  6440. // Payload is null
  6441. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  6442. }
  6443. LWS_Send(message);
  6444. return result;
  6445. }
  6446. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  6447. {
  6448. mtrace();
  6449. int result = FAIL;
  6450. int connectorIdInt, durationInt;
  6451. char chargingRateUnitStr[4]={0};
  6452. char comfirmstr[20];
  6453. int confirmPeriods = 0;
  6454. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  6455. json_object *GetCompositeSchedule;
  6456. GetCompositeSchedule = json_tokener_parse(payload);
  6457. if(!is_error(GetCompositeSchedule))
  6458. {
  6459. // Required data
  6460. connectorIdInt= json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  6461. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  6462. // Optional data
  6463. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  6464. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  6465. }
  6466. json_object_put(GetCompositeSchedule);
  6467. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  6468. if((connectorIdInt == 0) ||
  6469. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  6470. {
  6471. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  6472. struct StructChargingProfile tmpProfile[1];
  6473. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0]);
  6474. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6475. {
  6476. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6477. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6478. }
  6479. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  6480. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  6481. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  6482. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6483. {
  6484. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6485. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6486. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  6487. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  6488. {
  6489. confirmPeriods = idx;
  6490. break;
  6491. }
  6492. }
  6493. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6494. }
  6495. else
  6496. {
  6497. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  6498. }
  6499. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  6500. return result;
  6501. }
  6502. int handleGetConfigurationRequest(char *uuid, char *payload)
  6503. {
  6504. mtrace();
  6505. int result = FAIL;
  6506. int MaxKeySupported = 0;
  6507. int n_keys = 0;
  6508. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  6509. DEBUG_INFO("handleGetConfigurationRequest...\n");
  6510. json_object *GetConfiguration;
  6511. GetConfiguration = json_tokener_parse(payload);
  6512. if(!is_error(GetConfiguration))
  6513. {
  6514. // Optional data
  6515. if(json_object_object_get(GetConfiguration, "key") != NULL)
  6516. {
  6517. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  6518. {
  6519. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  6520. n_keys = idx + 1;
  6521. }
  6522. }
  6523. }
  6524. json_object_put(GetConfiguration);
  6525. UnknownKeynum = 0;
  6526. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  6527. MaxKeySupported = GetConfigurationMaxKeysNUM;
  6528. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  6529. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  6530. if(n_keys != 0)
  6531. {
  6532. for(int i=0;i<n_keys;i++)
  6533. {
  6534. getKeyValue(requestKey[i]);
  6535. }
  6536. }
  6537. else
  6538. {
  6539. DEBUG_INFO("There is no key in Message, get all configuration\n");
  6540. getKeyValue("");
  6541. }
  6542. processUnkownKey();
  6543. sendGetConfigurationConfirmation(uuid);
  6544. return result;
  6545. }
  6546. static char fnamePlusPath[100]={0};
  6547. static char fnamePWithNoPath[60]={0};
  6548. void checkUploadLog(void)
  6549. {
  6550. FILE *fp;
  6551. /* Open the command for reading. */
  6552. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  6553. if (fp == NULL) {
  6554. printf("Failed to run command\n" );
  6555. exit(1);
  6556. }
  6557. int ftppathlen = 0;
  6558. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  6559. int i = 0;
  6560. /* Read the output a line at a time - output it. */
  6561. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  6562. if(i==0)
  6563. {
  6564. ftppathlen = strlen(fnamePlusPath);
  6565. printf("%s\n", fnamePlusPath);
  6566. fnamePlusPath[ftppathlen]='\0';
  6567. break;
  6568. }
  6569. i= i+1;
  6570. }
  6571. /* close */
  6572. pclose(fp);
  6573. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  6574. {
  6575. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  6576. {
  6577. fnamePlusPath[k]='\0';
  6578. }
  6579. }
  6580. i=1;
  6581. //char fname[60]={0};
  6582. while(i < ftppathlen)
  6583. {
  6584. int len=ftppathlen-i;
  6585. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  6586. {
  6587. printf("compare '/' all right\n");
  6588. break;
  6589. }
  6590. i=i+1;
  6591. }
  6592. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  6593. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  6594. fnamePWithNoPath[i+1] = '\0';
  6595. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  6596. {
  6597. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  6598. {
  6599. fnamePWithNoPath[j]='\0';
  6600. }
  6601. }
  6602. FILE* fp1 = fopen(fnamePlusPath, "r");
  6603. if (fp1)
  6604. {
  6605. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  6606. // file exists
  6607. fclose(fp1);
  6608. }
  6609. else
  6610. {
  6611. // file doesn't exist
  6612. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  6613. }
  6614. }
  6615. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  6616. {
  6617. mtrace();
  6618. int result = FAIL;
  6619. char cmdBuf[512];
  6620. char fName[258];
  6621. time_t CurrentTime;
  6622. struct tm *tm;
  6623. system("/usr/bin/run_tmate_restart.sh");
  6624. pthread_t th_Status;
  6625. CurrentTime = time(NULL);
  6626. tm = localtime(&CurrentTime);
  6627. sprintf(fName ,"%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);
  6628. sendGetDiagnosticsConfirmation(uuid, fName);
  6629. system("exec /root/logPackTools 'log' 6");
  6630. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", fName);
  6631. system(cmdBuf);
  6632. checkUploadLog();
  6633. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  6634. return result;
  6635. }
  6636. void* GetDiagnosticsProcess(void* data)
  6637. {
  6638. pthread_detach(pthread_self());
  6639. mtrace();
  6640. int retriesInt=0, retryIntervalInt=0;
  6641. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  6642. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  6643. 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};
  6644. int port=0;
  6645. char sstr[260]={ 0 };
  6646. int c = 0;
  6647. char *loc;
  6648. int isSuccess = FALSE;
  6649. char ftpbuf[200]={0};
  6650. char * pch;
  6651. char str[300]={ 0 };
  6652. strcpy(str,(const char*)data);
  6653. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  6654. DEBUG_INFO("GetDiagnosticsProcess...%s\n", str);
  6655. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  6656. //****************location*******************/
  6657. c = 0;
  6658. memset(sstr ,0, ARRAY_SIZE(sstr));
  6659. loc = strstr(str, "location");
  6660. while (loc[3+strlen("location")+c] != '\"')
  6661. {
  6662. sstr[c] = loc[3+strlen("location")+c];
  6663. c++;
  6664. }
  6665. sstr[c] = '\0';
  6666. strcpy(locationstr,sstr);
  6667. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  6668. if(strcmp(locationstr,"")==0)
  6669. {
  6670. DEBUG_INFO("location is <Empty>!\n");
  6671. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6672. goto end;
  6673. }
  6674. //****************retries*******************/
  6675. c = 0;
  6676. loc = strstr(str, "retries");
  6677. if(loc == NULL)
  6678. {
  6679. retriesIsNULL = TRUE;
  6680. }
  6681. else
  6682. {
  6683. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6684. {
  6685. sstr[c] = loc[strlen("retries")+2+c];
  6686. c++;
  6687. }
  6688. sstr[c] = '\0';
  6689. retriesInt = atoi(sstr);
  6690. }
  6691. if(retriesIsNULL == TRUE)
  6692. {
  6693. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  6694. }
  6695. //****************retryInterval*******************/
  6696. c = 0;
  6697. loc = strstr(str, "retryInterval");
  6698. if(loc == NULL)
  6699. {
  6700. retryIntervalIsNULL = TRUE;
  6701. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  6702. }
  6703. else
  6704. {
  6705. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6706. {
  6707. sstr[c] = loc[strlen("retryInterval")+2+c];
  6708. c++;
  6709. }
  6710. sstr[c] = '\0';
  6711. retryIntervalInt = atoi(sstr);
  6712. }
  6713. //****************startTime*******************/
  6714. c = 0;
  6715. memset(sstr ,0, ARRAY_SIZE(sstr));
  6716. loc = strstr(str, "startTime");
  6717. if(loc == NULL)
  6718. {
  6719. startTimeIsNULL = TRUE;
  6720. }
  6721. else
  6722. {
  6723. while (loc[3+strlen("startTime")+c] != '\"')
  6724. {
  6725. sstr[c] = loc[3+strlen("startTime")+c];
  6726. c++;
  6727. }
  6728. sstr[c] = '\0';
  6729. strcpy(startTimestr,sstr);
  6730. }
  6731. //****************stopTime*******************/
  6732. c = 0;
  6733. memset(sstr ,0, ARRAY_SIZE(sstr));
  6734. loc = strstr(str, "stopTime");
  6735. if(loc == NULL)
  6736. {
  6737. stopTimeIsNULL = TRUE;
  6738. }
  6739. else
  6740. {
  6741. while (loc[3+strlen("stopTime")+c] != '\"')
  6742. {
  6743. sstr[c] = loc[3+strlen("stopTime")+c];
  6744. c++;
  6745. }
  6746. sstr[c] = '\0';
  6747. strcpy(stopTimestr,sstr);
  6748. }
  6749. memset(protocol, 0, ARRAY_SIZE(protocol));
  6750. memset(user, 0, ARRAY_SIZE(user) );
  6751. memset(password, 0, ARRAY_SIZE(password));
  6752. memset(host, 0, ARRAY_SIZE(host));
  6753. memset(path, 0, ARRAY_SIZE(path));
  6754. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  6755. memset(host1, 0, ARRAY_SIZE(host1));
  6756. memset(path1, 0, ARRAY_SIZE(path1));
  6757. /*location: ftp://user:password@host:port/path*/
  6758. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6759. if((access(fnamePlusPath,F_OK))!=-1)
  6760. {
  6761. DEBUG_INFO("fnamePlusPath exist.\n");
  6762. }
  6763. else
  6764. {
  6765. DEBUG_INFO("fnamePlusPath not exist!\n");
  6766. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6767. goto end;
  6768. }
  6769. pch=strchr(locationstr,'@');
  6770. if(pch==NULL)
  6771. {
  6772. sscanf(locationstr,
  6773. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6774. protocol, host, &port, path);
  6775. strcpy(user,"anonymous");
  6776. strcpy(password,"");
  6777. }
  6778. else
  6779. {
  6780. //DEBUG_INFO("pch=%s\n", pch);
  6781. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6782. protocol, user, password, host, &port, path);
  6783. }
  6784. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6785. {
  6786. DEBUG_INFO("protocol is not ftp/http ! \n");
  6787. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6788. goto end;
  6789. }
  6790. if(strncmp(locationstr,"http", 4) == 0)
  6791. {
  6792. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6793. sprintf(ftppath,"/%s", path);
  6794. do{
  6795. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  6796. sleep(retryIntervalInt);
  6797. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  6798. if(!isSuccess)
  6799. {
  6800. DEBUG_INFO("Diagnostics fail.\n");
  6801. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6802. }
  6803. else
  6804. {
  6805. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6806. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6807. }
  6808. }
  6809. else
  6810. {
  6811. sscanf(host,"%[^/]%s",host1, path1);
  6812. sprintf(ftppath,"%s", path1);
  6813. int ftppathlen=strlen(ftppath);
  6814. int i=1;
  6815. char filenametemp[50];
  6816. while(i < ftppathlen)
  6817. {
  6818. int len=ftppathlen-i;
  6819. if(ftppath[len]== 47) // '/' ascll code: 47
  6820. {
  6821. DEBUG_INFO("find '/' all right\n");
  6822. break;
  6823. }
  6824. i=i+1;
  6825. }
  6826. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  6827. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  6828. filenametemp[i+1] = 0;
  6829. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  6830. if(port == 0)
  6831. port = 21;
  6832. do{
  6833. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  6834. sleep(retryIntervalInt);
  6835. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  6836. if(!isSuccess)
  6837. {
  6838. DEBUG_INFO("Diagnostics fail.\n");
  6839. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6840. }
  6841. else
  6842. {
  6843. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6844. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6845. }
  6846. }
  6847. end:
  6848. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  6849. pthread_exit(NULL);
  6850. }
  6851. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  6852. {
  6853. mtrace();
  6854. int result = FAIL;
  6855. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  6856. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  6857. {
  6858. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  6859. localversion = -1;
  6860. }
  6861. else
  6862. {
  6863. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  6864. OCPP_getListVerion();
  6865. }
  6866. //from db.OCPP_getListVerion
  6867. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  6868. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  6869. sendGetLocalListVersionConfirmation(uuid,"");
  6870. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  6871. return result;
  6872. }
  6873. int handleRemoteStartRequest(char *uuid, char *payload)
  6874. {
  6875. mtrace();
  6876. int result = FAIL;
  6877. int connectorIdInt=0;
  6878. int tempIndex = 0;
  6879. int connectorIdIsNULL, chargingProfileIsNULL;
  6880. char comfirmstr[20]={0};
  6881. char cmdBuf[512];
  6882. json_object *RemoteStartTransaction;
  6883. FILE *fp;
  6884. DEBUG_INFO("handleRemoteStartRequest ...\n");
  6885. if(server_pending == TRUE)
  6886. {
  6887. return 0;
  6888. }
  6889. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  6890. RemoteStartTransaction = json_tokener_parse(payload);
  6891. if(!is_error(RemoteStartTransaction))
  6892. {
  6893. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  6894. {
  6895. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  6896. if(connectorIdInt <= gunTotalNumber)
  6897. {
  6898. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  6899. // Required data
  6900. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  6901. // Optional data
  6902. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  6903. {
  6904. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  6905. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  6906. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  6907. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  6908. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  6909. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  6910. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  6911. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  6912. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  6913. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  6914. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  6915. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  6916. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  6917. {
  6918. 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")));
  6919. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  6920. 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"));
  6921. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  6922. 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"));
  6923. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  6924. 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")));
  6925. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  6926. {
  6927. 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++)
  6928. {
  6929. 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"));
  6930. 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"));
  6931. 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)
  6932. 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"));
  6933. }
  6934. }
  6935. }
  6936. }
  6937. else
  6938. chargingProfileIsNULL = TRUE;
  6939. }
  6940. }
  6941. else
  6942. connectorIdIsNULL = TRUE;
  6943. }
  6944. else
  6945. connectorIdIsNULL = TRUE;
  6946. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  6947. {
  6948. DEBUG_WARN("Connector id is NULL\n.");
  6949. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6950. goto end;
  6951. }
  6952. /*
  6953. enum _SYSTEM_STATUS
  6954. {
  6955. S_BOOTING = 0,
  6956. S_IDLE, = 1
  6957. S_AUTHORIZING, = 2
  6958. S_REASSIGN_CHECK, = 3
  6959. S_REASSIGN, = 4
  6960. S_PRECHARGE, = 5
  6961. S_PREPARING_FOR_EV, = 6
  6962. S_PREPARING_FOR_EVSE, = 7
  6963. S_CHARGING, = 8
  6964. S_TERMINATING, = 9
  6965. S_COMPLETE, = 10
  6966. S_ALARM, = 11
  6967. S_FAULT = 12
  6968. }
  6969. */
  6970. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  6971. {
  6972. //check Transaction active
  6973. if(gunType[connectorIdInt -1] == 'J')
  6974. {
  6975. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6976. {
  6977. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  6978. }
  6979. else
  6980. {
  6981. tempIndex = connectorIdInt -1;
  6982. }
  6983. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6984. {
  6985. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  6986. {
  6987. 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))
  6988. {
  6989. //Reserved
  6990. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6991. }
  6992. 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))
  6993. {
  6994. //Reserved
  6995. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6996. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6997. goto end;
  6998. }
  6999. else
  7000. {
  7001. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7002. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  7003. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  7004. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  7005. {
  7006. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  7007. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7008. goto end;
  7009. }
  7010. }//END FOR ELSE
  7011. }
  7012. }// END FOR CHAdeMO_QUANTITY
  7013. }
  7014. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7015. {
  7016. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7017. {
  7018. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7019. }
  7020. else
  7021. {
  7022. tempIndex = connectorIdInt -1;
  7023. }
  7024. for (int index = 0; index < CCS_QUANTITY; index++)
  7025. {
  7026. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7027. {
  7028. 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))
  7029. {
  7030. //Reserved
  7031. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7032. }
  7033. 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))
  7034. {
  7035. //Reserved
  7036. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7037. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7038. goto end;
  7039. }
  7040. else
  7041. {
  7042. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7043. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7044. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7045. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7046. {
  7047. DEBUG_WARN("CCS connector not allow start\n.");
  7048. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7049. goto end;
  7050. }
  7051. }// END FOR ELSE
  7052. }
  7053. }// END FOR CCS_QUANTITY
  7054. }
  7055. else if(gunType[connectorIdInt -1] == 'G')
  7056. {
  7057. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7058. {
  7059. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7060. }
  7061. else
  7062. {
  7063. tempIndex = connectorIdInt -1;
  7064. }
  7065. for (int index = 0; index < GB_QUANTITY; index++)
  7066. {
  7067. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7068. {
  7069. 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))
  7070. {
  7071. //Reserved
  7072. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7073. }
  7074. 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))
  7075. {
  7076. //Reserved
  7077. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7078. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7079. goto end;
  7080. }
  7081. else
  7082. {
  7083. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7084. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7085. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7086. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7087. {
  7088. DEBUG_WARN("GB connector not allow start\n.");
  7089. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7090. goto end;
  7091. }
  7092. }// END FOR ELSE
  7093. }
  7094. } // END FOR GB_QUANTITY
  7095. }
  7096. else
  7097. {
  7098. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7099. {
  7100. tempIndex = 2;
  7101. }
  7102. else
  7103. {
  7104. tempIndex = connectorIdInt -1;
  7105. }
  7106. for (int index = 0; index < AC_QUANTITY; index++)
  7107. {
  7108. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7109. {
  7110. 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))
  7111. {
  7112. //Reserved
  7113. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7114. }
  7115. 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))
  7116. {
  7117. //Reserved
  7118. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7119. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7120. goto end;
  7121. }
  7122. else
  7123. {
  7124. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7125. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7126. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7127. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7128. {
  7129. DEBUG_WARN("AC connector not allow start\n.");
  7130. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7131. goto end;
  7132. }
  7133. }//END FOR ELSE
  7134. }
  7135. }// END FOR AC_QUANTITY
  7136. }
  7137. if(chargingProfileIsNULL == FALSE)
  7138. {
  7139. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7140. {
  7141. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7142. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7143. //memset idTag
  7144. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7145. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7146. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7147. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7148. // Save profile to file
  7149. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7150. system(cmdBuf);
  7151. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7152. fp = fopen(cmdBuf, "w");
  7153. fprintf(fp, "{\"connectorId\":%d,\"csChargingProfiles\":%s}\n", connectorIdInt, json_object_to_json_string(json_object_object_get(RemoteStartTransaction, "chargingProfile")));
  7154. fclose(fp);
  7155. }
  7156. else
  7157. {
  7158. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  7159. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7160. }
  7161. }
  7162. else
  7163. {
  7164. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7165. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7166. //memset idTag
  7167. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7168. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7169. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7170. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7171. }
  7172. }
  7173. else
  7174. {
  7175. DEBUG_WARN("Connector id over\n.");
  7176. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7177. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7178. }
  7179. end:
  7180. json_object_put(RemoteStartTransaction);
  7181. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  7182. {
  7183. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7184. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7185. }
  7186. //OCPP send RemoteStartConfirmation by first.
  7187. sendRemoteStartConfirmation(uuid, comfirmstr);
  7188. return result;
  7189. }
  7190. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7191. {
  7192. mtrace();
  7193. int result = FAIL;
  7194. int match = FALSE;
  7195. int GunNO = 0;
  7196. int tempIndex = 0;
  7197. int transactionIdInt=0;
  7198. int transactionIdIsNULL= FALSE;
  7199. char sstr[16]={ 0 },sstrtemp[50]={ 0 };//sstr[200]={ 0 };
  7200. int c = 0;
  7201. char *loc;
  7202. char comfirmstr[20];
  7203. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7204. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7205. if(server_pending == TRUE)
  7206. {
  7207. return 0;
  7208. }
  7209. strcpy(sstrtemp, stringtrimspace(payload));
  7210. c=0;
  7211. loc = strstr(sstrtemp, "transactionId");
  7212. if(loc == NULL)
  7213. {
  7214. transactionIdIsNULL= TRUE;
  7215. }
  7216. else
  7217. {
  7218. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7219. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  7220. {
  7221. sstr[c] = loc[strlen("transactionId")+2+c];
  7222. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7223. c++;
  7224. }
  7225. sstr[c] = '\0';
  7226. transactionIdInt = atoi(sstr);
  7227. }
  7228. if(transactionIdIsNULL == FALSE)
  7229. {
  7230. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7231. {
  7232. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7233. {
  7234. //check Transaction active
  7235. if(gunType[gun_index] == 'J')
  7236. {
  7237. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7238. {
  7239. tempIndex = ((gun_index==2) ? 1: 0);
  7240. }
  7241. else
  7242. {
  7243. tempIndex = gun_index;
  7244. }
  7245. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7246. {
  7247. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7248. {
  7249. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7250. {
  7251. match = TRUE;
  7252. GunNO = gun_index;
  7253. }
  7254. }
  7255. }// END FOR CHAdeMO_QUANTITY
  7256. }
  7257. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  7258. {
  7259. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7260. {
  7261. tempIndex = ((gun_index==2) ? 1: 0);
  7262. }
  7263. else
  7264. {
  7265. tempIndex = gun_index;
  7266. }
  7267. for (int index = 0; index < CCS_QUANTITY; index++)
  7268. {
  7269. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7270. {
  7271. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7272. {
  7273. match = TRUE;
  7274. GunNO = gun_index;
  7275. }
  7276. }
  7277. }// END FOR CCS_QUANTITY
  7278. }
  7279. else if(gunType[gun_index] == 'G')
  7280. {
  7281. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7282. {
  7283. tempIndex = ((gun_index==2) ? 1: 0);
  7284. }
  7285. else
  7286. {
  7287. tempIndex = gun_index;
  7288. }
  7289. for (int index = 0; index < GB_QUANTITY; index++)
  7290. {
  7291. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7292. {
  7293. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7294. {
  7295. match = TRUE;
  7296. GunNO = gun_index;
  7297. }
  7298. }
  7299. }// END FOR GB_QUANTITY
  7300. }
  7301. else
  7302. {
  7303. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7304. {
  7305. tempIndex = 2;
  7306. }
  7307. else
  7308. {
  7309. tempIndex = gun_index;
  7310. }
  7311. for (int index = 0; index < AC_QUANTITY; index++)
  7312. {
  7313. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7314. {
  7315. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7316. {
  7317. match = TRUE;
  7318. GunNO = gun_index;
  7319. }
  7320. }
  7321. }// END FOR CHAdeMO_QUANTITY
  7322. } // END FOR AC ELSE
  7323. }// CHECK IF ResponseTransactionId == transactionIdInt
  7324. }//END FOR
  7325. if( match == TRUE)
  7326. {
  7327. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7328. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7329. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7330. }
  7331. else
  7332. {
  7333. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7334. }
  7335. }
  7336. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7337. return result;
  7338. }
  7339. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7340. {
  7341. mtrace();
  7342. int result = FAIL;
  7343. int connectorIdInt=0, reservationIdInt=0;
  7344. int tempIndex = 0;
  7345. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7346. char comfirmstr[20]={0};
  7347. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7348. int c = 0;
  7349. char *loc;
  7350. //char *ptr;
  7351. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  7352. strcpy(sstrtemp, stringtrimspace(payload));
  7353. //***(1)connectorId ****/
  7354. c=0;
  7355. loc = strstr(sstrtemp, "connectorId");
  7356. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7357. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7358. {
  7359. sstr[c] = loc[strlen("connectorId")+2+c];
  7360. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7361. c++;
  7362. }
  7363. sstr[c] = '\0';
  7364. connectorIdInt = atoi(sstr);
  7365. //***(2)expiryDate ****/
  7366. loc = strstr(sstrtemp, "expiryDate");
  7367. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7368. c = 0;
  7369. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7370. {
  7371. sstr[c] = loc[3+strlen("expiryDate")+c];
  7372. c++;
  7373. }
  7374. sstr[c] = '\0';
  7375. strcpy(expiryDatestr, sstr);
  7376. //***(3)idTag ****/
  7377. loc = strstr(sstrtemp, "idTag");
  7378. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7379. c = 0;
  7380. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7381. {
  7382. sstr[c] = loc[3+strlen("idTag")+c];
  7383. c++;
  7384. }
  7385. sstr[c] = '\0';
  7386. strcpy(idTagstr, sstr);
  7387. //***(4)parentIdTag ****/
  7388. loc = strstr(sstrtemp, "parentIdTag");
  7389. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7390. c = 0;
  7391. if(loc == NULL)
  7392. {
  7393. strcpy(parentIdTagstr, "");
  7394. }
  7395. else
  7396. {
  7397. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7398. {
  7399. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7400. c++;
  7401. }
  7402. sstr[c] = '\0';
  7403. strcpy(parentIdTagstr, sstr);
  7404. }
  7405. //***(5)reservationId ****/
  7406. c=0;
  7407. loc = strstr(sstrtemp, "reservationId");
  7408. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7409. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7410. {
  7411. sstr[c] = loc[strlen("reservationId")+2+c];
  7412. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7413. c++;
  7414. }
  7415. sstr[c] = '\0';
  7416. reservationIdInt = atoi(sstr);
  7417. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7418. /*
  7419. enum SYSTEM_STATUS
  7420. {
  7421. SYS_MODE_BOOTING = 0,
  7422. SYS_MODE_IDLE = 1,
  7423. SYS_MODE_AUTHORIZING = 2,
  7424. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7425. SYS_MODE_REASSIGN = 4,
  7426. SYS_MODE_PREPARING = 5,
  7427. SYS_MODE_PREPARE_FOR_EV = 6,
  7428. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7429. SYS_MODE_CHARGING = 8,
  7430. SYS_MODE_TERMINATING = 9,
  7431. SYS_MODE_COMPLETE = 10,
  7432. SYS_MODE_ALARM = 11,
  7433. SYS_MODE_FAULT = 12,
  7434. SYS_MODE_RESERVATION = 13,
  7435. SYS_MODE_BOOKING = 14,
  7436. SYS_MODE_MAINTAIN = 15,
  7437. SYS_MODE_DEBUG = 16,
  7438. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7439. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7440. SYS_MODE_UPDATE = 19
  7441. };
  7442. */
  7443. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7444. {
  7445. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7446. goto end;
  7447. }
  7448. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7449. {
  7450. //check Transaction active
  7451. if(gunType[connectorIdInt -1] == 'J')
  7452. {
  7453. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7454. {
  7455. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7456. }
  7457. else
  7458. {
  7459. tempIndex = connectorIdInt -1;
  7460. }
  7461. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7462. {
  7463. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7464. {
  7465. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7466. {
  7467. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7468. {
  7469. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7470. {
  7471. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7472. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7473. }
  7474. 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'))
  7475. {
  7476. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7477. }
  7478. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7479. {
  7480. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7481. }
  7482. else
  7483. {
  7484. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7485. }
  7486. }
  7487. 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
  7488. {
  7489. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7490. }
  7491. }
  7492. else
  7493. {
  7494. //replace reservation
  7495. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7496. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7497. }
  7498. }
  7499. } // END FOR CHAdeMO_QUANTITY
  7500. }
  7501. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7502. {
  7503. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7504. {
  7505. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7506. }
  7507. else
  7508. {
  7509. tempIndex = connectorIdInt -1;
  7510. }
  7511. for (int index = 0; index < CCS_QUANTITY; index++)
  7512. {
  7513. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7514. {
  7515. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7516. {
  7517. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7518. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7519. {
  7520. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7521. {
  7522. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7523. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7524. }
  7525. 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'))
  7526. {
  7527. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7528. }
  7529. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7530. {
  7531. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7532. }
  7533. else
  7534. {
  7535. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7536. }
  7537. }
  7538. 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
  7539. {
  7540. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7541. }
  7542. }
  7543. else
  7544. {
  7545. //replace reservation
  7546. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7547. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7548. }
  7549. }
  7550. } // END FOR CCS_QUANTITY
  7551. }
  7552. else if(gunType[connectorIdInt -1] == 'G')
  7553. {
  7554. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7555. {
  7556. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7557. }
  7558. else
  7559. {
  7560. tempIndex = connectorIdInt -1;
  7561. }
  7562. for (int index = 0; index < GB_QUANTITY; index++)
  7563. {
  7564. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7565. {
  7566. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7567. {
  7568. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7569. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7570. {
  7571. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7572. {
  7573. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7574. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7575. }
  7576. 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'))
  7577. {
  7578. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7579. }
  7580. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7581. {
  7582. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7583. }
  7584. else
  7585. {
  7586. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7587. }
  7588. }
  7589. 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
  7590. {
  7591. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7592. }
  7593. }
  7594. else
  7595. {
  7596. //replace reservation
  7597. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7598. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7599. }
  7600. }
  7601. }// END FOR GB_QUANTITY
  7602. }
  7603. else
  7604. {
  7605. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7606. {
  7607. tempIndex = 2;
  7608. }
  7609. else
  7610. {
  7611. tempIndex = (connectorIdInt -1);
  7612. }
  7613. for (int index = 0; index < AC_QUANTITY; index++)
  7614. {
  7615. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7616. {
  7617. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7618. {
  7619. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7620. {
  7621. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7622. {
  7623. 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))
  7624. {
  7625. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7626. }
  7627. else
  7628. {
  7629. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7630. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7631. }
  7632. }
  7633. 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'))
  7634. {
  7635. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7636. }
  7637. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7638. {
  7639. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7640. }
  7641. else
  7642. {
  7643. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7644. }
  7645. }
  7646. 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
  7647. {
  7648. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7649. }
  7650. }
  7651. else
  7652. {
  7653. //replace reservation
  7654. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7655. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7656. }
  7657. }
  7658. } // END FOR AC_QUANTITY
  7659. }
  7660. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7661. }
  7662. else if(connectorIdInt == 0)
  7663. {
  7664. //check Transaction active
  7665. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7666. {
  7667. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7668. {
  7669. 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'))
  7670. {
  7671. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7672. goto end;
  7673. }
  7674. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7675. {
  7676. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7677. goto end;
  7678. }
  7679. 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
  7680. {
  7681. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7682. goto end;
  7683. }
  7684. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7685. {
  7686. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7687. goto end;
  7688. }
  7689. }
  7690. }// END FOR CHAdeMO_QUANTITY
  7691. for (int index = 0; index < CCS_QUANTITY; index++)
  7692. {
  7693. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7694. {
  7695. 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'))
  7696. {
  7697. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7698. goto end;
  7699. }
  7700. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  7701. {
  7702. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7703. goto end;
  7704. }
  7705. 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
  7706. {
  7707. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7708. goto end;
  7709. }
  7710. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7711. {
  7712. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7713. goto end;
  7714. }
  7715. }
  7716. } // END FOR CCS_QUANTITY
  7717. for (int index = 0; index < GB_QUANTITY; index++)
  7718. {
  7719. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7720. {
  7721. 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'))
  7722. {
  7723. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7724. goto end;
  7725. }
  7726. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7727. {
  7728. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7729. goto end;
  7730. }
  7731. 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
  7732. {
  7733. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7734. goto end;
  7735. }
  7736. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7737. {
  7738. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7739. goto end;
  7740. }
  7741. }
  7742. } // END FOR GB_QUANTITY
  7743. for (int index = 0; index < AC_QUANTITY; index++)
  7744. {
  7745. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7746. {
  7747. 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'))
  7748. {
  7749. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7750. goto end;
  7751. }
  7752. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7753. {
  7754. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7755. goto end;
  7756. }
  7757. 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
  7758. {
  7759. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7760. goto end;
  7761. }
  7762. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7763. {
  7764. 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))
  7765. {
  7766. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7767. goto end;
  7768. }
  7769. }
  7770. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7771. {
  7772. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7773. goto end;
  7774. }
  7775. }
  7776. }// END FOR AC_QUANTITY
  7777. //The connectorId is 0
  7778. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  7779. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7780. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  7781. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  7782. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  7783. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  7784. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  7785. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  7786. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  7787. result = TRUE;
  7788. return result;
  7789. }
  7790. else
  7791. {
  7792. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7793. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7794. }
  7795. if(strcmp(comfirmstr,"Accepted") == 0)
  7796. {
  7797. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  7798. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  7799. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  7800. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  7801. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  7802. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  7803. result = TRUE;
  7804. return result;
  7805. }
  7806. end:
  7807. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  7808. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  7809. return result;
  7810. }
  7811. int handleResetRequest(char *uuid, char *payload)
  7812. {
  7813. mtrace();
  7814. int result = FAIL;
  7815. char sstr[10]={0},sstrtemp[30]={ 0 };
  7816. char typestr[10]={0};
  7817. char comfirmstr[20]={0};
  7818. int c = 0;
  7819. char *loc;
  7820. DEBUG_INFO("handleResetRequest...\n");
  7821. strcpy(sstrtemp, stringtrimspace(payload));
  7822. loc = strstr(sstrtemp, "type");
  7823. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7824. c = 0;
  7825. while (loc[3+strlen("type")+c] != '\"')
  7826. {
  7827. sstr[c] = loc[3+strlen("type")+c];
  7828. c++;
  7829. }
  7830. sstr[c] = '\0';
  7831. strcpy(typestr,sstr);
  7832. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  7833. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  7834. {
  7835. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7836. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7837. result = TRUE;
  7838. return result;
  7839. }
  7840. else
  7841. {
  7842. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  7843. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  7844. goto errorend;
  7845. }
  7846. errorend:
  7847. sendResetConfirmation(uuid, comfirmstr);
  7848. return result;
  7849. }
  7850. int handleSendLocalListRequest(char *uuid, char *payload)
  7851. {
  7852. mtrace();
  7853. int result = FAIL;
  7854. int listVersionInt;
  7855. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  7856. char listsearch[]="listVersion";
  7857. char updateTypesearch[]="updateType";
  7858. char localAuthorizationListsearch[]="localAuthorizationList";
  7859. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  7860. char CardList[500][160]={0};
  7861. char updateTypestr[15]={0};
  7862. char idTagstr[20]={0};
  7863. char parentIdTag[20]={0};
  7864. char expiryDate[30]={0};
  7865. char idTagstatus[16]={0};
  7866. int c = 0;
  7867. int i = 0;
  7868. char *delim1 = "}";
  7869. char * pch;
  7870. char *loc;
  7871. //char *ptr;
  7872. char comfirmstr[20];
  7873. //int n_localAuthorizations = 0;
  7874. int checkState_Faulted = FALSE;
  7875. DEBUG_INFO("handleSendLocalListRequest...\n");
  7876. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  7877. {
  7878. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7879. goto end;
  7880. }
  7881. //check Charge Point state
  7882. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7883. {
  7884. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7885. {
  7886. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7887. }
  7888. }
  7889. for (int index = 0; index < CCS_QUANTITY; index++)
  7890. {
  7891. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7892. {
  7893. checkState_Faulted = TRUE; //OCPP Status
  7894. }
  7895. }
  7896. for (int index = 0; index < GB_QUANTITY; index++)
  7897. {
  7898. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7899. {
  7900. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7901. }
  7902. }
  7903. //check Charge Point state
  7904. for (int index = 0; index < AC_QUANTITY; index++)
  7905. {
  7906. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7907. {
  7908. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7909. }
  7910. }
  7911. if(checkState_Faulted == TRUE)
  7912. {
  7913. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7914. goto end;
  7915. }
  7916. //Filter payload space
  7917. strcpy(sstrtemp, stringtrimspace(payload));
  7918. //listVersion
  7919. c = 0;
  7920. loc = strstr(sstrtemp, listsearch);
  7921. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  7922. {
  7923. sstr[c] = loc[strlen("listVersion")+2+c];
  7924. c++;
  7925. }
  7926. sstr[c] = '\0';
  7927. listVersionInt = atoi(sstr);
  7928. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7929. //updateType
  7930. loc = strstr(sstrtemp, updateTypesearch);
  7931. c = 0;
  7932. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  7933. {
  7934. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  7935. c++;
  7936. }
  7937. sstr[c] = '\0';
  7938. strcpy(updateTypestr, sstr);
  7939. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  7940. //localAuthorizationList
  7941. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7942. loc = strstr(sstrtemp, localAuthorizationListsearch);
  7943. if(loc != NULL) // localAuthorizationList is not NULL
  7944. {
  7945. //Check UpdateType
  7946. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7947. {
  7948. //Local list full update
  7949. printf("Local list full update.\n");
  7950. OCPP_getListVerion();
  7951. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7952. {
  7953. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7954. goto end;
  7955. }
  7956. OCPP_cleanLocalList();
  7957. }
  7958. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7959. {
  7960. //Local list different update
  7961. printf("Local list different update.\n");
  7962. OCPP_getListVerion();
  7963. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7964. {
  7965. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  7966. goto end;
  7967. }
  7968. }
  7969. else
  7970. {
  7971. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7972. goto end;
  7973. }
  7974. c = 0;
  7975. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  7976. {
  7977. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  7978. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7979. c++;
  7980. }
  7981. sstr[c] = '\0';
  7982. //DEBUG_INFO("sstr=%s\n", sstr);
  7983. //parsing strings to words
  7984. i = 0;
  7985. pch = strtok(sstr,delim1);
  7986. while (pch != NULL)
  7987. {
  7988. strcpy(CardList[i], pch);
  7989. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  7990. pch = strtok (NULL, delim1);
  7991. i = i + 1;
  7992. }
  7993. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  7994. //local Authorizations List Numbers
  7995. //n_localAuthorizations = i;
  7996. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7997. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7998. c= 0;
  7999. while(c < i) // i is CardList Number
  8000. {
  8001. //Search "IdToken"
  8002. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8003. loc = strstr(CardList[c], "idTag");
  8004. int j = 0;
  8005. while (loc[3+strlen("idTag")+j] != '\"')
  8006. {
  8007. sstr[j] = loc[3+strlen("idTag")+j];
  8008. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8009. j++;
  8010. }
  8011. sstr[j] = '\0';
  8012. strcpy(idTagstr, sstr);
  8013. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  8014. //Search "expiryDate"
  8015. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8016. loc = strstr(CardList[c], "expiryDate");
  8017. j = 0;
  8018. if(loc != NULL)
  8019. {
  8020. while (loc[3+strlen("expiryDate")+j] != '\"')
  8021. {
  8022. sstr[j] = loc[3+strlen("expiryDate")+j];
  8023. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8024. j++;
  8025. }
  8026. sstr[j] = '\0';
  8027. strcpy(expiryDate, sstr);
  8028. }
  8029. else
  8030. {
  8031. strcpy(expiryDate, "");
  8032. }
  8033. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  8034. //Search "parentIdTag"
  8035. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8036. loc = strstr(CardList[c], "parentIdTag");
  8037. j = 0;
  8038. if(loc != NULL)
  8039. {
  8040. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8041. {
  8042. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8043. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8044. j++;
  8045. }
  8046. sstr[j] = '\0';
  8047. strcpy(parentIdTag, sstr);
  8048. }
  8049. else
  8050. {
  8051. strcpy(parentIdTag, "");
  8052. }
  8053. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8054. //Search "status"
  8055. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8056. loc = strstr(CardList[c], "status");
  8057. j = 0;
  8058. while (loc[3+strlen("status")+j] != '\"')
  8059. {
  8060. sstr[j] = loc[3+strlen("status")+j];
  8061. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8062. j++;
  8063. }
  8064. sstr[j] = '\0';
  8065. strcpy(idTagstatus, sstr);
  8066. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8067. OCPP_getIdTag(idTagstr);
  8068. //OCPP_getIdTag("test"); For Test
  8069. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8070. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8071. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8072. {
  8073. //Local list full update
  8074. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8075. // update list
  8076. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8077. //DEBUG_INFO("Local list full update. 1\n");
  8078. //OCPP_get_TableAuthlocalAllData();
  8079. //DEBUG_INFO("Local list full update. 2\n");
  8080. }
  8081. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8082. {
  8083. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8084. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8085. }
  8086. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8087. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8088. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8089. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8090. c++;
  8091. }
  8092. }
  8093. else
  8094. {
  8095. //Check UpdateType
  8096. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8097. {
  8098. //Local list full update
  8099. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8100. OCPP_cleanLocalList();
  8101. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8102. goto end;
  8103. }
  8104. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8105. {
  8106. //Local list different update
  8107. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8108. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8109. goto end;
  8110. }
  8111. }
  8112. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8113. end:
  8114. sendSendLocalListConfirmation(uuid, comfirmstr);
  8115. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8116. return result;
  8117. }
  8118. #define MAX 200
  8119. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8120. {
  8121. mtrace();
  8122. int result = FAIL;
  8123. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8124. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8125. char chargingProfilePurposeStr[30]={0};
  8126. char chargingProfileKindStr[16]={0};
  8127. char recurrencyKindStr[10]={0};
  8128. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8129. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8130. int chargingSchedulePeriodCount = 0;
  8131. //int updateflag = FALSE;
  8132. char comfirmstr[20]={0};
  8133. int meet= FALSE;
  8134. char sstr[10]={0},sstrtemp[1600]={ 0 };
  8135. int c = 0;
  8136. char *loc;
  8137. FILE *fptr1;//, *fptr2;
  8138. //int lno=0;//, linectr = 0;
  8139. //int modifyflag = FALSE;
  8140. char filename[MAX]={0};
  8141. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8142. //int resultRename=0;
  8143. char rmFileCmd[50]={0};
  8144. char tempchargingProfilePurposeStr[30]={0};
  8145. char word[1600]={0};
  8146. int n_chargingProfile = 0;
  8147. //[2,"d65bcbca-0b07-49c1-b679-e6c6ff9f5627","SetChargingProfile",{"connectorId":0,"csChargingProfiles":{"chargingProfileId":1,"transactionId":0,"stackLevel":0,"chargingProfilePurpose":"TxDefaultProfile","chargingProfileKind":"Absolute","recurrencyKind":"Daily","validFrom":"2019-07-01T02:39:55.000Z","validTo":"2019-07-04T02:39:55.000Z","chargingSchedule":{"duration":86400,"startSchedule":"2019-07-01T02:39:55.000Z","chargingRateUnit":"A","chargingSchedulePeriod":[{"startPeriod":0,"limit":20.0,"numberPhases":3},{"startPeriod":300,"limit":10.0,"numberPhases":3},{"startPeriod":600,"limit":20.0,"numberPhases":3},{"startPeriod":1200,"limit":10.0,"numberPhases":3},{"startPeriod":1800,"limit":20.0,"numberPhases":3},{"startPeriod":2400,"limit":10.0,"numberPhases":3},{"startPeriod":3000,"limit":20.0,"numberPhases":3}],"minChargingRate":20.1}}}]
  8148. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8149. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8150. //Filter string space
  8151. strcpy(sstrtemp, stringtrimspace(payload));
  8152. //*********************connectorId***************************/
  8153. loc = strstr(sstrtemp, "connectorId");
  8154. c = 0;
  8155. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8156. while (loc[strlen("connectorId")+2+c] != ',')
  8157. {
  8158. sstr[c] = loc[strlen("connectorId")+2+c];
  8159. c++;
  8160. }
  8161. sstr[c] = '\0';
  8162. connectorIdInt = atoi(sstr);
  8163. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8164. {
  8165. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8166. }
  8167. else
  8168. {
  8169. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  8170. }
  8171. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  8172. //*********************chargingProfileId***************************/
  8173. loc = strstr(sstrtemp, "chargingProfileId");
  8174. c = 0;
  8175. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8176. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8177. {
  8178. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8179. c++;
  8180. }
  8181. sstr[c] = '\0';
  8182. chargingProfileIdInt = atoi(sstr);
  8183. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8184. {
  8185. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8186. }
  8187. else
  8188. {
  8189. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8190. }
  8191. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  8192. //*********************transactionId***************************/
  8193. loc = strstr(sstrtemp, "transactionId");
  8194. if(loc != NULL)
  8195. {
  8196. c = 0;
  8197. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8198. while (loc[strlen("transactionId")+2+c] != ',')
  8199. {
  8200. sstr[c] = loc[strlen("transactionId")+2+c];
  8201. c++;
  8202. }
  8203. sstr[c] = '\0';
  8204. transactionIdInt = atoi(sstr);
  8205. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8206. {
  8207. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  8208. }
  8209. else
  8210. {
  8211. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  8212. }
  8213. }
  8214. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  8215. //*********************stackLevel***************************/
  8216. loc = strstr(sstrtemp, "stackLevel");
  8217. c = 0;
  8218. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8219. while (loc[strlen("stackLevel")+2+c] != ',')
  8220. {
  8221. sstr[c] = loc[strlen("stackLevel")+2+c];
  8222. c++;
  8223. }
  8224. sstr[c] = '\0';
  8225. stackLevelInt = atoi(sstr);
  8226. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8227. {
  8228. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8229. }
  8230. else
  8231. {
  8232. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8233. }
  8234. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  8235. //*********************chargingProfilePurpose***************************/
  8236. loc = strstr(sstrtemp, "chargingProfilePurpose");
  8237. c = 0;
  8238. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8239. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8240. {
  8241. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8242. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8243. c++;
  8244. }
  8245. sstr[c] = '\0';
  8246. strcpy(chargingProfilePurposeStr,sstr);
  8247. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  8248. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8249. {
  8250. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8251. }
  8252. else
  8253. {
  8254. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8255. }
  8256. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  8257. //*********************chargingProfileKind***************************/
  8258. loc = strstr(sstrtemp, "chargingProfileKind");
  8259. c = 0;
  8260. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8261. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  8262. {
  8263. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  8264. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8265. c++;
  8266. }
  8267. sstr[c] = '\0';
  8268. strcpy(chargingProfileKindStr,sstr);
  8269. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8270. {
  8271. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8272. }
  8273. else
  8274. {
  8275. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8276. }
  8277. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  8278. //*********************recurrencyKind***************************/
  8279. loc = strstr(sstrtemp, "recurrencyKind");
  8280. if(loc != NULL)
  8281. {
  8282. c = 0;
  8283. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8284. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  8285. {
  8286. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  8287. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8288. c++;
  8289. }
  8290. sstr[c] = '\0';
  8291. strcpy(recurrencyKindStr,sstr);
  8292. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8293. {
  8294. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8295. }
  8296. else
  8297. {
  8298. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8299. }
  8300. }
  8301. else
  8302. {
  8303. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8304. {
  8305. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  8306. }
  8307. else
  8308. {
  8309. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  8310. }
  8311. }
  8312. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  8313. //*********************validFrom***************************/
  8314. loc = strstr(sstrtemp, "validFrom");
  8315. if(loc != NULL)
  8316. {
  8317. c = 0;
  8318. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8319. while (loc[3+strlen("validFrom")+c] != '\"')
  8320. {
  8321. sstr[c] = loc[3+strlen("validFrom")+c];
  8322. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8323. c++;
  8324. }
  8325. sstr[c] = '\0';
  8326. strcpy(validFromStr,sstr);
  8327. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8328. {
  8329. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8330. }
  8331. else
  8332. {
  8333. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8334. }
  8335. }
  8336. else
  8337. {
  8338. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8339. {
  8340. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  8341. }
  8342. else
  8343. {
  8344. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  8345. }
  8346. }
  8347. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  8348. //*********************validTo***************************/
  8349. loc = strstr(sstrtemp, "validTo");
  8350. if(loc != NULL)
  8351. {
  8352. c = 0;
  8353. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8354. while (loc[3+strlen("validTo")+c] != '\"')
  8355. {
  8356. sstr[c] = loc[3+strlen("validTo")+c];
  8357. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8358. c++;
  8359. }
  8360. sstr[c] = '\0';
  8361. strcpy(validToStr,sstr);
  8362. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8363. {
  8364. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8365. }
  8366. else
  8367. {
  8368. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8369. }
  8370. }
  8371. else
  8372. {
  8373. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8374. {
  8375. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  8376. }
  8377. else
  8378. {
  8379. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  8380. }
  8381. }
  8382. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  8383. //*********************duration***************************/
  8384. loc = strstr(sstrtemp, "duration");
  8385. if(loc != NULL)
  8386. {
  8387. c = 0;
  8388. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8389. while (loc[strlen("duration")+2+c] != ',')
  8390. {
  8391. sstr[c] = loc[strlen("duration")+2+c];
  8392. c++;
  8393. }
  8394. sstr[c] = '\0';
  8395. durationInt = atoi(sstr);
  8396. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8397. {
  8398. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8399. }
  8400. else
  8401. {
  8402. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8403. }
  8404. }
  8405. else
  8406. {
  8407. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8408. {
  8409. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  8410. }
  8411. else
  8412. {
  8413. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  8414. }
  8415. }
  8416. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  8417. //*********************startSchedule***************************/
  8418. loc = strstr(sstrtemp, "startSchedule");
  8419. if(loc != NULL)
  8420. {
  8421. c = 0;
  8422. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8423. while (loc[3+strlen("startSchedule")+c] != '\"')
  8424. {
  8425. sstr[c] = loc[3+strlen("startSchedule")+c];
  8426. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8427. c++;
  8428. }
  8429. sstr[c] = '\0';
  8430. strcpy(startScheduleStr,sstr);
  8431. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8432. {
  8433. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8434. }
  8435. else
  8436. {
  8437. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8438. }
  8439. }
  8440. else
  8441. {
  8442. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8443. {
  8444. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8445. }
  8446. else
  8447. {
  8448. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8449. }
  8450. }
  8451. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  8452. //*********************chargingRateUnit***************************/
  8453. loc = strstr(sstrtemp, "chargingRateUnit");
  8454. if(loc != NULL)
  8455. {
  8456. c = 0;
  8457. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8458. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  8459. {
  8460. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  8461. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8462. c++;
  8463. }
  8464. sstr[c] = '\0';
  8465. strcpy(chargingRateUnitStr,sstr);
  8466. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8467. {
  8468. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8469. }
  8470. else
  8471. {
  8472. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8473. }
  8474. }
  8475. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  8476. //****************chargingSchedulePeriod count start*******************/
  8477. int what_len = strlen("startPeriod");
  8478. char tempChargingProfile[1600]={0};
  8479. strcpy(tempChargingProfile,(const char*)sstrtemp);
  8480. char *where = tempChargingProfile;
  8481. if (what_len)
  8482. {
  8483. while ((where = strstr(where, "startPeriod"))) {
  8484. where += what_len;
  8485. chargingSchedulePeriodCount++;
  8486. }
  8487. }
  8488. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8489. {
  8490. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8491. goto end;
  8492. }
  8493. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  8494. //where = payload;
  8495. int templength = 0;
  8496. //int searchstart = 0;
  8497. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  8498. {
  8499. //****************startPeriod*******************/
  8500. c=0;
  8501. loc = strstr(tempChargingProfile + templength, "startPeriod");
  8502. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8503. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  8504. {
  8505. sstr[c] = loc[strlen("startPeriod")+2+c];
  8506. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8507. c++;
  8508. }
  8509. sstr[c] = '\0';
  8510. startPeriodInt[periodNums] = atoi(sstr);
  8511. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  8512. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  8513. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8514. {
  8515. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8516. }
  8517. else
  8518. {
  8519. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8520. }
  8521. templength = strlen("startPeriod")+2+c;
  8522. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  8523. //****************limit*******************/
  8524. c=0;
  8525. loc = strstr(tempChargingProfile + templength, "limit");
  8526. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8527. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  8528. {
  8529. sstr[c] = loc[strlen("limit")+2+c];
  8530. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8531. c++;
  8532. }
  8533. sstr[c] = '\0';
  8534. limitflaot[periodNums] = atof(sstr);
  8535. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8536. {
  8537. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8538. }
  8539. else
  8540. {
  8541. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8542. }
  8543. templength = templength + strlen("limit")+2+c;
  8544. //****************numberPhases*******************/
  8545. loc = strstr(tempChargingProfile + templength, "numberPhases");
  8546. if(loc != NULL)
  8547. {
  8548. c=0;
  8549. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8550. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  8551. {
  8552. sstr[c] = loc[strlen("numberPhases")+2+c];
  8553. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8554. c++;
  8555. }
  8556. sstr[c] = '\0';
  8557. numberPhasesInt[periodNums] = atoi(sstr);
  8558. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8559. {
  8560. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8561. }
  8562. else
  8563. {
  8564. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8565. }
  8566. templength = templength + strlen("numberPhases")+2+c;
  8567. }
  8568. //where = loc;
  8569. }
  8570. //****************chargingSchedulePeriod count end*******************/
  8571. //*********************minChargingRate***************************/
  8572. loc = strstr(sstrtemp, "minChargingRate");
  8573. if(loc != NULL)
  8574. {
  8575. c = 0;
  8576. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8577. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  8578. {
  8579. sstr[c] = loc[strlen("minChargingRate")+2+c];
  8580. c++;
  8581. }
  8582. sstr[c] = '\0';
  8583. minChargingRateFloat = atof(sstr);
  8584. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8585. {
  8586. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8587. }
  8588. else
  8589. {
  8590. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8591. }
  8592. }
  8593. else
  8594. {
  8595. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8596. {
  8597. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8598. }
  8599. else
  8600. {
  8601. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8602. }
  8603. }
  8604. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8605. {
  8606. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8607. if(connectorIdInt != 0)
  8608. {
  8609. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8610. goto end;
  8611. }
  8612. strcpy(filename, ChargePointMaxProfile_JSON );
  8613. fptr1 = fopen(filename, "r");
  8614. if (!fptr1)
  8615. {
  8616. //file not exist
  8617. DEBUG_INFO("Unable to open the input file!!\n");
  8618. fptr1 = fopen(filename, "w+");
  8619. }
  8620. else
  8621. {
  8622. //Check Charging Profile Count
  8623. while(fscanf(fptr1, "%s", word) != EOF)
  8624. {
  8625. //DEBUG_INFO("word=%s\n",word);
  8626. if(strstr(word, "chargingProfileId")!= NULL)
  8627. {
  8628. //DEBUG_INFO("test chargingProfileId \n");
  8629. n_chargingProfile = n_chargingProfile + 1;
  8630. //DEBUG_INFO("chargingProfileId Found\n");
  8631. }
  8632. }
  8633. }
  8634. fclose(fptr1);
  8635. }
  8636. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8637. {
  8638. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8639. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8640. {
  8641. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8642. goto end;
  8643. }
  8644. memset(filename, 0, ARRAY_SIZE(filename));
  8645. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8646. fptr1 = fopen(filename, "r");
  8647. if (!fptr1)
  8648. {
  8649. //file not exist
  8650. //DEBUG_INFO("Unable to open the input file!!\n");
  8651. fptr1 = fopen(filename, "w+");
  8652. }
  8653. else
  8654. {
  8655. //Check Charging Profile Count
  8656. while(fscanf(fptr1, "%s", word) != EOF)
  8657. {
  8658. //DEBUG_INFO("word=%s\n",word);
  8659. if(strstr(word, "chargingProfileId")!= NULL)
  8660. {
  8661. //DEBUG_INFO("test chargingProfileId \n");
  8662. n_chargingProfile = n_chargingProfile + 1;
  8663. //DEBUG_INFO("chargingProfileId Found\n");
  8664. }
  8665. }
  8666. }
  8667. fclose(fptr1);
  8668. }
  8669. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8670. {
  8671. //printf("set chargingProfile 1-4\n");
  8672. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8673. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  8674. if(connectorIdInt == 0)
  8675. {
  8676. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8677. goto end;
  8678. }
  8679. int tempIndex = 0;
  8680. //check Transaction active
  8681. if(gunType[connectorIdInt -1] == 'J')
  8682. {
  8683. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8684. {
  8685. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8686. }
  8687. else
  8688. {
  8689. tempIndex = connectorIdInt -1;
  8690. }
  8691. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8692. {
  8693. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8694. {
  8695. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8696. {
  8697. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8698. {
  8699. meet = TRUE;
  8700. break;
  8701. }
  8702. }
  8703. }
  8704. }
  8705. }
  8706. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  8707. {
  8708. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8709. {
  8710. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8711. }
  8712. else
  8713. {
  8714. tempIndex = connectorIdInt -1;
  8715. }
  8716. for (int index = 0; index < CCS_QUANTITY; index++)
  8717. {
  8718. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8719. {
  8720. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8721. {
  8722. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8723. {
  8724. meet = TRUE;
  8725. break;
  8726. }
  8727. }
  8728. }
  8729. }
  8730. }
  8731. else if(gunType[connectorIdInt -1] == 'G')
  8732. {
  8733. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8734. {
  8735. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8736. }
  8737. else
  8738. {
  8739. tempIndex = connectorIdInt -1;
  8740. }
  8741. for (int index = 0; index < GB_QUANTITY; index++)
  8742. {
  8743. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8744. {
  8745. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8746. {
  8747. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8748. {
  8749. meet = TRUE;
  8750. break;
  8751. }
  8752. }
  8753. }
  8754. }
  8755. }
  8756. else
  8757. {
  8758. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8759. {
  8760. tempIndex = 2;
  8761. }
  8762. else
  8763. {
  8764. tempIndex = (connectorIdInt -1);
  8765. }
  8766. for (int index = 0; index < AC_QUANTITY; index++)
  8767. {
  8768. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8769. {
  8770. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8771. {
  8772. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8773. {
  8774. meet = TRUE;
  8775. break;
  8776. }
  8777. }
  8778. }
  8779. }
  8780. }
  8781. //check Transaction active
  8782. if(meet == FALSE)
  8783. {
  8784. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8785. goto end;
  8786. }
  8787. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8788. {
  8789. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8790. goto end;
  8791. }
  8792. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8793. fptr1 = fopen(filename, "r");
  8794. if (!fptr1)
  8795. {
  8796. //file not exist
  8797. DEBUG_INFO("Unable to open the input file!!\n");
  8798. fptr1 = fopen(filename, "w+");
  8799. }
  8800. else
  8801. {
  8802. //Check Charging Profile Count
  8803. while(fscanf(fptr1, "%s", word) != EOF)
  8804. {
  8805. //DEBUG_INFO("word=%s\n",word);
  8806. if(strstr(word, "chargingProfileId")!= NULL)
  8807. {
  8808. //DEBUG_INFO("test chargingProfileId \n");
  8809. n_chargingProfile = n_chargingProfile + 1;
  8810. //DEBUG_INFO("chargingProfileId Found\n");
  8811. }
  8812. }
  8813. }
  8814. fclose(fptr1);
  8815. }
  8816. // Check ChargeProfileMaxStackLevel
  8817. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8818. {
  8819. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8820. goto end;
  8821. }
  8822. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8823. {
  8824. int i = 0;
  8825. char fnametemp[200]={0};
  8826. n_chargingProfile = 0;
  8827. //Check ChargePointMaxProfile.json exit
  8828. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8829. {
  8830. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8831. //Check Charging Profile Count
  8832. while(fscanf(fptr1, "%s", word) != EOF)
  8833. {
  8834. //DEBUG_INFO("word=%s\n",word);
  8835. if(strstr(word, "chargingProfileId")!= NULL)
  8836. {
  8837. //DEBUG_INFO("test chargingProfileId \n");
  8838. n_chargingProfile = n_chargingProfile + 1;
  8839. i = i + 1;
  8840. //DEBUG_INFO("chargingProfileId Found\n");
  8841. }
  8842. memset(word, 0, ARRAY_SIZE(word));
  8843. }
  8844. fclose(fptr1);
  8845. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8846. }
  8847. //Check TxDefaultProfile_0.json exit
  8848. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8849. {
  8850. i = 0;
  8851. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8852. //Check Charging Profile Count
  8853. while(fscanf(fptr1, "%s", word) != EOF)
  8854. {
  8855. //DEBUG_INFO("word=%s\n",word);
  8856. if(strstr(word, "chargingProfileId")!= NULL)
  8857. {
  8858. //DEBUG_INFO("test chargingProfileId \n");
  8859. n_chargingProfile = n_chargingProfile + 1;
  8860. i = i + 1;
  8861. //DEBUG_INFO("chargingProfileId Found\n");
  8862. }
  8863. memset(word, 0, ARRAY_SIZE(word));
  8864. }
  8865. fclose(fptr1);
  8866. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  8867. }
  8868. //Check TxDefaultProfile_%d.json
  8869. for(int j=1; j <= gunTotalNumber; j++)
  8870. {
  8871. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8872. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8873. if((access(fnametemp,F_OK))!=-1)
  8874. {
  8875. i = 0;
  8876. fptr1 = fopen(fnametemp, "r");
  8877. //Check Charging Profile Count
  8878. while(fscanf(fptr1, "%s", word) != EOF)
  8879. {
  8880. //DEBUG_INFO("word=%s\n",word);
  8881. if(strstr(word, "chargingProfileId")!= NULL)
  8882. {
  8883. //DEBUG_INFO("test chargingProfileId \n");
  8884. n_chargingProfile = n_chargingProfile + 1;
  8885. i = i + 1;
  8886. //DEBUG_INFO("chargingProfileId Found\n");
  8887. }
  8888. memset(word, 0, ARRAY_SIZE(word));
  8889. }
  8890. fclose(fptr1);
  8891. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8892. }
  8893. }
  8894. //Check TxProfile_%d.json
  8895. for(int j=1; j <= gunTotalNumber; j++)
  8896. {
  8897. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8898. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8899. if((access(fnametemp,F_OK))!=-1)
  8900. {
  8901. i = 0;
  8902. fptr1 = fopen(fnametemp, "r");
  8903. //Check Charging Profile Count
  8904. while(fscanf(fptr1, "%s", word) != EOF)
  8905. {
  8906. //DEBUG_INFO("word=%s\n",word);
  8907. if(strstr(word, "chargingProfileId")!= NULL)
  8908. {
  8909. //DEBUG_INFO("test chargingProfileId \n");
  8910. n_chargingProfile = n_chargingProfile + 1;
  8911. i = i + 1;
  8912. //DEBUG_INFO("chargingProfileId Found\n");
  8913. }
  8914. memset(word, 0, ARRAY_SIZE(word));
  8915. }
  8916. fclose(fptr1);
  8917. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8918. }
  8919. }
  8920. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  8921. {
  8922. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8923. goto end;
  8924. }
  8925. }
  8926. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8927. //**********************************Write to File********************************************************/
  8928. FILE *infile;
  8929. FILE *outfile;
  8930. // open file for writing
  8931. infile = fopen (filename, "r");
  8932. outfile = fopen (tempfile, "w");
  8933. int d =0;
  8934. d = fgetc(infile);
  8935. //DEBUG_INFO("d:%d\n",d);
  8936. rewind(infile);
  8937. //*璉 瘚 辣蝏     1嚗   0 */
  8938. if(d == EOF)
  8939. {
  8940. //DEBUG_INFO("ChargingProfile content is NULL\n");
  8941. fprintf(outfile,"%s\n",payload);
  8942. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8943. fclose(infile);
  8944. fclose(outfile);
  8945. sprintf(rmFileCmd,"rm -f %s",filename);
  8946. system(rmFileCmd);
  8947. rename(tempfile, filename);
  8948. sleep(1);
  8949. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  8950. //system(rmFileCmd);
  8951. }
  8952. else
  8953. {
  8954. char buf[1000]={0};
  8955. int ChargingProfileAdded = FALSE;
  8956. while (fgets(buf, sizeof(buf), infile) != NULL)
  8957. {
  8958. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8959. //*************************tempconnectorIdInt*********************************/
  8960. loc = strstr(buf, "connectorId");
  8961. c = 0;
  8962. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8963. while (loc[strlen("connectorId")+2+c] != ',')
  8964. {
  8965. sstr[c] = loc[strlen("connectorId")+2+c];
  8966. c++;
  8967. }
  8968. sstr[c] = '\0';
  8969. tempconnectorIdInt = atoi(sstr);
  8970. //*************************tempchargingProfileIdInt*********************************/
  8971. loc = strstr(buf, "chargingProfileId");
  8972. c = 0;
  8973. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8974. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8975. {
  8976. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8977. c++;
  8978. }
  8979. sstr[c] = '\0';
  8980. tempchargingProfileIdInt = atoi(sstr);
  8981. //*************************tempstackLevelInt*********************************/
  8982. loc = strstr(buf, "stackLevel");
  8983. c = 0;
  8984. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8985. while (loc[strlen("stackLevel")+2+c] != ',')
  8986. {
  8987. sstr[c] = loc[strlen("stackLevel")+2+c];
  8988. c++;
  8989. }
  8990. sstr[c] = '\0';
  8991. tempstackLevelInt = atoi(sstr);
  8992. //*************************tempchargingProfilePurposeStr*********************************/
  8993. loc = strstr(payload, "chargingProfilePurpose");
  8994. c = 0;
  8995. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8996. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8997. {
  8998. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8999. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9000. c++;
  9001. }
  9002. sstr[c] = '\0';
  9003. strcpy(tempchargingProfilePurposeStr,sstr);
  9004. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  9005. {
  9006. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9007. {
  9008. //DEBUG_INFO("update set chargingProfile to file -0\n");
  9009. if(ChargingProfileAdded == FALSE)
  9010. {
  9011. fprintf(outfile,"%s\n",payload);
  9012. ChargingProfileAdded = TRUE;
  9013. }
  9014. }
  9015. else
  9016. {
  9017. if(tempstackLevelInt < stackLevelInt)
  9018. {
  9019. if(ChargingProfileAdded == FALSE)
  9020. {
  9021. fprintf(outfile,"%s\n",payload);
  9022. ChargingProfileAdded = TRUE;
  9023. fprintf(outfile,"%s\n",buf);
  9024. }
  9025. else
  9026. {
  9027. fprintf(outfile,"%s\n",buf);
  9028. }
  9029. }
  9030. else
  9031. {
  9032. if(ChargingProfileAdded == FALSE)
  9033. {
  9034. fprintf(outfile,"%s\n",buf);
  9035. fprintf(outfile,"%s\n",payload);
  9036. ChargingProfileAdded = TRUE;
  9037. }
  9038. else
  9039. {
  9040. fprintf(outfile,"%s\n",buf);
  9041. }
  9042. }
  9043. }
  9044. }
  9045. else
  9046. {
  9047. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9048. {
  9049. if(ChargingProfileAdded == FALSE)
  9050. {
  9051. fprintf(outfile,"%s\n",payload);
  9052. ChargingProfileAdded = TRUE;
  9053. fprintf(outfile,"%s\n",buf);
  9054. }
  9055. else
  9056. {
  9057. fprintf(outfile,"%s\n",buf);
  9058. }
  9059. }
  9060. else if(tempstackLevelInt < stackLevelInt)
  9061. {
  9062. if(ChargingProfileAdded == FALSE)
  9063. {
  9064. fprintf(outfile,"%s\n",payload);
  9065. ChargingProfileAdded = TRUE;
  9066. fprintf(outfile,"%s\n",buf);
  9067. }
  9068. else
  9069. {
  9070. fprintf(outfile,"%s\n",buf);
  9071. }
  9072. }
  9073. else
  9074. {
  9075. if(ChargingProfileAdded == FALSE)
  9076. {
  9077. fprintf(outfile,"%s\n",buf);
  9078. fprintf(outfile,"%s\n",payload);
  9079. ChargingProfileAdded = TRUE;
  9080. }
  9081. else
  9082. {
  9083. fprintf(outfile,"%s\n",buf);
  9084. }
  9085. }
  9086. }
  9087. } // end of while loop
  9088. fclose(infile);
  9089. fclose(outfile);
  9090. sprintf(rmFileCmd,"rm -f %s",filename);
  9091. system(rmFileCmd);
  9092. rename(tempfile, filename);
  9093. sleep(1);
  9094. result = TRUE;
  9095. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9096. }
  9097. end:
  9098. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  9099. return result;
  9100. return result;
  9101. }
  9102. int handleTriggerMessageRequest(char *uuid, char *payload)
  9103. {
  9104. mtrace();
  9105. int result = FAIL;
  9106. int connectorIdIsNULL = FALSE;
  9107. int connectorIdInt =0;
  9108. char sstr[40]={0},sstrtemp[100]={ 0 };
  9109. char requestedMessagestr[40]={0};
  9110. char comfirmstr[20]={0};
  9111. int c = 0;
  9112. char *loc;
  9113. DEBUG_INFO("handleTriggerMessageRequest\n");
  9114. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  9115. strcpy(sstrtemp, stringtrimspace(payload));
  9116. c = 0;
  9117. loc = strstr(sstrtemp, "requestedMessage");
  9118. while (loc[3+strlen("requestedMessage")+c] != '\"')
  9119. {
  9120. sstr[c] = loc[3+strlen("requestedMessage")+c];
  9121. c++;
  9122. }
  9123. sstr[c] = '\0';
  9124. strcpy(requestedMessagestr, sstr);
  9125. c = 0;
  9126. loc = strstr(sstrtemp, "connectorId");
  9127. if(loc == NULL)
  9128. {
  9129. connectorIdIsNULL = TRUE;
  9130. }
  9131. else
  9132. {
  9133. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9134. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  9135. {
  9136. sstr[c] = loc[strlen("connectorId")+2+c];
  9137. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9138. c++;
  9139. }
  9140. sstr[c] = '\0';
  9141. connectorIdInt = atoi(sstr);
  9142. }
  9143. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  9144. {
  9145. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  9146. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  9147. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  9148. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  9149. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  9150. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  9151. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  9152. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  9153. {
  9154. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  9155. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9156. return TRUE;
  9157. }
  9158. else
  9159. {
  9160. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9161. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9162. }
  9163. }
  9164. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  9165. {
  9166. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  9167. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9168. return TRUE;
  9169. }
  9170. //==========================
  9171. // Trigger message
  9172. //==========================
  9173. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  9174. {
  9175. if((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) &&
  9176. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) &&
  9177. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) &&
  9178. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING) )
  9179. {
  9180. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  9181. }
  9182. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  9183. }
  9184. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  9185. {
  9186. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  9187. }
  9188. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  9189. {
  9190. //sendBootNotificationRequest();
  9191. server_sign = FALSE;
  9192. }
  9193. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  9194. {
  9195. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  9196. }
  9197. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  9198. {
  9199. if(connectorIdIsNULL == FALSE)
  9200. {
  9201. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9202. {
  9203. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  9204. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  9205. }
  9206. }
  9207. else
  9208. {
  9209. for(int idx=0;idx< gunTotalNumber;idx++)
  9210. {
  9211. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  9212. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  9213. }
  9214. }
  9215. }
  9216. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  9217. {
  9218. if(connectorIdIsNULL == FALSE)
  9219. {
  9220. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9221. {
  9222. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  9223. }
  9224. }
  9225. else
  9226. {
  9227. for(int idx=0;idx< gunTotalNumber;idx++)
  9228. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  9229. }
  9230. }
  9231. return result;
  9232. }
  9233. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9234. {
  9235. mtrace();
  9236. int result = FAIL;
  9237. char sstr[6]={0},sstrtemp[50]={ 0 };
  9238. int connectorIdInt =0;
  9239. char comfirmstr[20]={0};
  9240. int c = 0;
  9241. int tempIndex = 0;
  9242. char *loc;
  9243. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9244. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9245. strcpy(sstrtemp, stringtrimspace(payload));
  9246. c = 0;
  9247. loc = strstr(sstrtemp, "connectorId");
  9248. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9249. while (loc[strlen("connectorId")+2+c] != '}')
  9250. {
  9251. sstr[c] = loc[strlen("connectorId")+2+c];
  9252. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9253. c++;
  9254. }
  9255. sstr[c] = '\0';
  9256. connectorIdInt = atoi(sstr);
  9257. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  9258. if(gunTotalNumber == 0)
  9259. {
  9260. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9261. goto end;
  9262. }
  9263. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9264. {
  9265. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9266. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9267. goto end;
  9268. }
  9269. else
  9270. {
  9271. //check Transaction active
  9272. if(gunType[connectorIdInt-1] == 'J')
  9273. {
  9274. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9275. {
  9276. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9277. }
  9278. else
  9279. {
  9280. tempIndex = connectorIdInt -1;
  9281. }
  9282. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9283. {
  9284. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9285. {
  9286. //stop Transaction
  9287. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9288. }
  9289. }
  9290. }
  9291. else if((gunType[connectorIdInt-1] == 'U')||(gunType[connectorIdInt-1] == 'E'))
  9292. {
  9293. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9294. {
  9295. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9296. }
  9297. else
  9298. {
  9299. tempIndex = connectorIdInt -1;
  9300. }
  9301. for (int index = 0; index < CCS_QUANTITY; index++)
  9302. {
  9303. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9304. {
  9305. //stop Transaction
  9306. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9307. }
  9308. }
  9309. }
  9310. else if(gunType[connectorIdInt-1] == 'G')
  9311. {
  9312. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9313. {
  9314. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9315. }
  9316. else
  9317. {
  9318. tempIndex = connectorIdInt -1;
  9319. }
  9320. for (int index = 0; index < GB_QUANTITY; index++)
  9321. {
  9322. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9323. {
  9324. //stop Transaction
  9325. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9326. }
  9327. }
  9328. }
  9329. else
  9330. {
  9331. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9332. {
  9333. tempIndex = 2;
  9334. }
  9335. else
  9336. {
  9337. tempIndex = connectorIdInt-1;
  9338. }
  9339. for (int index = 0; index < AC_QUANTITY; index++)
  9340. {
  9341. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9342. {
  9343. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9344. }
  9345. }
  9346. }
  9347. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9348. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9349. result = TRUE;
  9350. return result;
  9351. }
  9352. end:
  9353. //json_object_put(obj); --- remove temporally
  9354. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9355. return result;
  9356. }
  9357. static char UpdateFirmwarepayloadData[300]={0};
  9358. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9359. {
  9360. mtrace();
  9361. int result = FAIL;
  9362. pthread_t t;
  9363. sendUpdateFirmwareConfirmation(uuid);
  9364. memset(UpdateFirmwarepayloadData, 0, 300);
  9365. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9366. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9367. ////pthread_join(t, NULL); //
  9368. //pthread_detach(t);
  9369. //sendUpdateFirmwareConfirmation(uuid);
  9370. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9371. return result;
  9372. }
  9373. void *UpdateFirmwareProcess(void *data)
  9374. {
  9375. pthread_detach(pthread_self());
  9376. mtrace();
  9377. int retriesInt =0, retryIntervalInt=0;
  9378. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9379. int port=0;
  9380. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9381. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  9382. //char comfirmstr[20];
  9383. int isSuccess = 0;
  9384. char ftpbuf[200];
  9385. char temp[100];
  9386. char * pch;
  9387. int retriesISNULL=FALSE;
  9388. int retryInterval=FALSE;
  9389. int c = 0;
  9390. //int i = 0;
  9391. char *loc;
  9392. char sstr[300]={ 0 };
  9393. char str[300]={ 0 };
  9394. //char *str = (char*) data; // ? ?頛詨鞈 ?
  9395. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9396. //DEBUG_INFO("packet=%s\n", (const char*)payloadData);
  9397. strcpy(str,(const char*)UpdateFirmwarepayloadData);
  9398. //***************location **************/
  9399. loc = strstr(str, "location");
  9400. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9401. c = 0;
  9402. while (loc[3+strlen("location")+c] != '\"')
  9403. {
  9404. sstr[c] = loc[3+strlen("location")+c];
  9405. c++;
  9406. }
  9407. sstr[c] = '\0';
  9408. strcpy(locationstr, sstr);
  9409. //***************retries**************/
  9410. c = 0;
  9411. loc = strstr(str, "retries");
  9412. if(loc == NULL)
  9413. {
  9414. retriesISNULL=TRUE;
  9415. }
  9416. else
  9417. {
  9418. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9419. while (loc[strlen("retries")+2+c] != ',')
  9420. {
  9421. sstr[c] = loc[strlen("retries")+2+c];
  9422. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9423. c++;
  9424. }
  9425. sstr[c] = '\0';
  9426. }
  9427. if(retriesISNULL == FALSE)
  9428. {
  9429. retriesInt = atoi(sstr);
  9430. }
  9431. //***************retrieveDate **************/
  9432. loc = strstr(str, "retrieveDate");
  9433. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9434. c = 0;
  9435. while (loc[3+strlen("retrieveDate")+c] != '\"')
  9436. {
  9437. sstr[c] = loc[3+strlen("retrieveDate")+c];
  9438. c++;
  9439. }
  9440. sstr[c] = '\0';
  9441. strcpy(retrieveDatestr, sstr);
  9442. //***************retryInterval **************/
  9443. c = 0;
  9444. loc = strstr(str, "retryInterval");
  9445. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9446. if(loc == NULL)
  9447. {
  9448. retryInterval=TRUE;
  9449. }
  9450. else
  9451. {
  9452. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  9453. {
  9454. sstr[c] = loc[strlen("retryInterval")+2+c];
  9455. //DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  9456. c++;
  9457. }
  9458. sstr[c] = '\0';
  9459. }
  9460. if(retryInterval==FALSE)
  9461. {
  9462. retryIntervalInt = atoi(sstr);
  9463. }
  9464. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9465. memset(path, 0, ARRAY_SIZE(path));
  9466. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9467. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9468. if(strncmp(locationstr,"http", 4) == 0)
  9469. {
  9470. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  9471. protocol, host, path);
  9472. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9473. // protocol, user, password, host, path);
  9474. sprintf(ftppath,"/%s", path);
  9475. //DEBUG_INFO("protocol =%s\n",protocol);
  9476. //DEBUG_INFO("host =%s\n",host);
  9477. //DEBUG_INFO("path =%s\n",path);
  9478. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9479. int ftppathlen=strlen(ftppath);
  9480. int i=1;
  9481. char filenametemp[50];
  9482. while(i < ftppathlen)
  9483. {
  9484. int len=ftppathlen-i;
  9485. if(ftppath[len]== 47) // '/' ascll code: 47
  9486. {
  9487. DEBUG_INFO("compare '/' all right\n");
  9488. break;
  9489. }
  9490. i=i+1;
  9491. }
  9492. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9493. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9494. filenametemp[i+1] = 0;
  9495. do
  9496. {
  9497. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9498. sleep(retryIntervalInt);
  9499. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9500. if(!isSuccess)
  9501. {
  9502. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9503. }
  9504. else
  9505. {
  9506. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9507. }
  9508. }
  9509. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9510. {
  9511. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9512. memset(temp, 0, ARRAY_SIZE(temp));
  9513. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9514. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9515. int ftppathlen=strlen(ftpbuf);
  9516. int i=1;
  9517. char filenametemp[50];
  9518. while(i < ftppathlen)
  9519. {
  9520. int len=ftppathlen-i;
  9521. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9522. {
  9523. DEBUG_INFO(" compare '/' all right\n");
  9524. break;
  9525. }
  9526. i=i+1;
  9527. }
  9528. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9529. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9530. filenametemp[i+1] = 0;
  9531. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9532. pch=strchr(temp,'@');
  9533. if(pch==NULL)
  9534. {
  9535. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9536. protocol, host, &port, path);
  9537. strcpy(user,"anonymous");
  9538. strcpy(password,"");
  9539. }
  9540. else
  9541. {
  9542. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9543. protocol, user, password, host, &port, path);
  9544. }
  9545. sscanf(host,"%[^/]%s",host1, path1);
  9546. sprintf(ftppath,"%s", path1);
  9547. //DEBUG_INFO("protocol =%s\n",protocol);
  9548. //DEBUG_INFO("user =%s\n",user);
  9549. //DEBUG_INFO("password =%s\n",password);
  9550. //DEBUG_INFO("host1 =%s\n",host1);
  9551. //DEBUG_INFO("port =%d\n",port);
  9552. //DEBUG_INFO("path1 =%s\n",path1);
  9553. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9554. //ftpFile(host, user, password, port, ftppath, fname);
  9555. //download firmware pthred
  9556. if(port == 0)
  9557. {
  9558. port = 21;
  9559. }
  9560. do
  9561. {
  9562. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9563. sleep(retryIntervalInt);
  9564. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9565. if(!isSuccess)
  9566. {
  9567. //BulldogUtil.sleepMs(interval*1000);
  9568. DEBUG_INFO("Update firmware request and download file fail.\n");
  9569. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9570. }
  9571. else
  9572. {
  9573. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9574. }
  9575. }
  9576. else
  9577. {
  9578. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9579. }
  9580. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9581. pthread_exit(NULL);
  9582. }
  9583. //==========================================
  9584. // Handle server response routine
  9585. //==========================================
  9586. void handleAuthorizeResponse(char *payload, int gun_index)
  9587. {
  9588. mtrace();
  9589. char expiryDatestr[30]={0};
  9590. char parentIdTagstr[20]={0};
  9591. char statusstr[20]={0};
  9592. char expiryDatestrtemp[30]={0};
  9593. char parentIdTagstrtemp[20]={0};
  9594. char IdTagstrtemp[20]={0};
  9595. char statusstrtemp[20]={0};
  9596. int expiryDateISNULL=FALSE;
  9597. int parentIdTagISNULL=FALSE;
  9598. char sstr[160]={0};
  9599. char* filename = AuthorizationCache_JSON;
  9600. char tempfile[] = "/Storage/OCPP/Authorizetemp.json";
  9601. char *loc;
  9602. int resultRename=0;
  9603. int responseIdTagInfoAsZero= 0;
  9604. char rmFileCmd[50]={0};
  9605. DEBUG_INFO("handleAuthorizeResponse...\n");
  9606. json_object *Authorize;
  9607. Authorize = json_tokener_parse(payload);
  9608. if(!is_error(Authorize))
  9609. {
  9610. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  9611. {
  9612. // Required data
  9613. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  9614. // Optional data
  9615. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  9616. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  9617. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  9618. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  9619. }
  9620. }
  9621. json_object_put(Authorize);
  9622. if(expiryDateISNULL == FALSE)
  9623. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9624. if(parentIdTagISNULL == FALSE)
  9625. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9626. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9627. //Update idTag information to authorization cache if supproted
  9628. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9629. {
  9630. if((access(filename,F_OK))!=-1)
  9631. {
  9632. printf("AuthorizationCache exist.\n");
  9633. }
  9634. else
  9635. {
  9636. printf("AuthorizationCache not exist\n");
  9637. FILE *log = fopen(filename, "w+");
  9638. if(log == NULL)
  9639. {
  9640. printf("log is NULL\n");
  9641. goto out;
  9642. }
  9643. else
  9644. {
  9645. fclose(log);
  9646. }
  9647. }
  9648. FILE *infile;
  9649. FILE *outfile;
  9650. // open file for writing
  9651. infile = fopen (filename, "r");
  9652. outfile = fopen (tempfile, "w");
  9653. int c;
  9654. c = fgetc(infile);
  9655. //DEBUG_INFO("c:%d\n",c);
  9656. rewind(infile);
  9657. if(c == EOF)
  9658. {
  9659. DEBUG_INFO("Orignal File is NULL\n");
  9660. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9661. {
  9662. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9663. }
  9664. else
  9665. {
  9666. strcpy(expiryDatestrtemp, "");
  9667. }
  9668. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9669. {
  9670. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9671. }
  9672. else
  9673. {
  9674. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9675. }
  9676. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9677. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9678. fclose(infile);
  9679. fclose(outfile);
  9680. sprintf(rmFileCmd,"rm -f %s",filename);
  9681. system(rmFileCmd);
  9682. resultRename = rename(tempfile, filename);
  9683. if(resultRename == 0)
  9684. {
  9685. printf("File renamed successfully");
  9686. }
  9687. else
  9688. {
  9689. printf("Error: unable to rename the file");
  9690. }
  9691. }
  9692. else
  9693. {
  9694. char buf[160]={0};
  9695. while (fgets(buf, ARRAY_SIZE(buf), infile) != NULL)
  9696. {
  9697. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9698. memset(expiryDatestr, 0, ARRAY_SIZE(expiryDatestrtemp));
  9699. memset(parentIdTagstr,0, ARRAY_SIZE(parentIdTagstrtemp));
  9700. memset(statusstr, 0, ARRAY_SIZE(statusstrtemp));
  9701. memset(IdTagstrtemp, 0, ARRAY_SIZE(IdTagstrtemp));
  9702. memset(expiryDatestrtemp, 0, ARRAY_SIZE(expiryDatestrtemp));
  9703. memset(parentIdTagstrtemp, 0, ARRAY_SIZE(parentIdTagstrtemp));
  9704. memset(statusstrtemp, 0, ARRAY_SIZE(statusstrtemp));
  9705. //------------------IdTag-----------------------
  9706. loc = strstr(buf, "idTag");
  9707. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9708. c = 0;
  9709. while (loc[3+strlen("idTag")+c] != '\"')
  9710. {
  9711. sstr[c] = loc[3+strlen("idTag")+c];
  9712. c++;
  9713. }
  9714. sstr[c] = '\0';
  9715. strcpy(IdTagstrtemp,sstr);
  9716. //*********************expiryDate***************/
  9717. loc = strstr(buf, "expiryDate");
  9718. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9719. c = 0;
  9720. while (loc[3+strlen("expiryDate")+c] != '\"')
  9721. {
  9722. sstr[c] = loc[3+strlen("expiryDate")+c];
  9723. c++;
  9724. }
  9725. sstr[c] = '\0';
  9726. strcpy(expiryDatestr,sstr);
  9727. //*********************parentIdTag***************/
  9728. loc = strstr(buf, "parentIdTag");
  9729. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9730. c = 0;
  9731. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9732. {
  9733. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9734. c++;
  9735. }
  9736. sstr[c] = '\0';
  9737. strcpy(parentIdTagstr,sstr);
  9738. //*********************status***************/
  9739. loc = strstr(buf, "status");
  9740. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9741. c = 0;
  9742. while (loc[3+strlen("status")+c] != '\"')
  9743. {
  9744. sstr[c] = loc[3+strlen("status")+c];
  9745. c++;
  9746. }
  9747. sstr[c] = '\0';
  9748. strcpy(statusstr,sstr);
  9749. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9750. {
  9751. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9752. responseIdTagInfoAsZero = 1;
  9753. }
  9754. else
  9755. {
  9756. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9757. }
  9758. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9759. {
  9760. //modify item
  9761. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9762. {
  9763. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9764. }
  9765. else
  9766. {
  9767. strcpy(expiryDatestrtemp, "");
  9768. }
  9769. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9770. {
  9771. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9772. }
  9773. else
  9774. {
  9775. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9776. }
  9777. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9778. }
  9779. else
  9780. {
  9781. //wrie original item
  9782. strcpy(expiryDatestrtemp, expiryDatestr);
  9783. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9784. strcpy(statusstrtemp, statusstr);
  9785. }
  9786. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9787. }
  9788. fclose(infile);
  9789. fclose(outfile);
  9790. sprintf(rmFileCmd,"rm -f %s",filename);
  9791. system(rmFileCmd);
  9792. resultRename = rename(tempfile, filename);
  9793. if(resultRename == 0)
  9794. {
  9795. DEBUG_INFO("File renamed successfully");
  9796. }
  9797. else
  9798. {
  9799. DEBUG_INFO("Error: unable to rename the file");
  9800. }
  9801. }
  9802. }
  9803. out:
  9804. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9805. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9806. authorizeRetryTimes = 0;
  9807. }
  9808. char * strtrimc( char * s )
  9809. {
  9810. char * p1 = s;
  9811. char * p2 = s;
  9812. while(*p1 != '\0')
  9813. {
  9814. while(*p1 == ' ' || *p1 == '\t' || *p1 == '\"' || *p1 == '\n' || *p1 == '}' || *p1 == '\r')
  9815. {
  9816. if(*p1 != ',')
  9817. {
  9818. p1 ++;
  9819. }
  9820. else
  9821. {
  9822. break;
  9823. }
  9824. }
  9825. if(*p1 != ',')
  9826. {
  9827. * p2 ++ = *p1 ++;
  9828. //printf("p2=%s\n",p2);
  9829. }
  9830. else
  9831. {
  9832. break;
  9833. }
  9834. }
  9835. *p2 = '\0';
  9836. return (s);
  9837. }
  9838. void handleBootNotificationResponse(char *payload, int gun_index)
  9839. {
  9840. mtrace();
  9841. char statusStr[12]={0};
  9842. char currentTimeStr[30]={0};
  9843. int intervalInt = 0;
  9844. struct tm tp;
  9845. char buf[28]={0};
  9846. char timebuf[50]={0};
  9847. DEBUG_INFO("handleBootNotificationResponse...\n");
  9848. json_object *BootNotification;
  9849. BootNotification = json_tokener_parse(payload);
  9850. if(!is_error(BootNotification))
  9851. {
  9852. // Required data
  9853. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  9854. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  9855. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  9856. }
  9857. json_object_put(BootNotification);
  9858. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9859. BootNotificationInterval = intervalInt;
  9860. HeartBeatWaitTime = intervalInt;
  9861. //write back to ShmOCPP16Data->BootNotification
  9862. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9863. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9864. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9865. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  9866. {
  9867. server_sign = TRUE;
  9868. server_pending =FALSE;
  9869. }
  9870. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9871. {
  9872. server_pending = TRUE;
  9873. }
  9874. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9875. tp.tm_isdst = -1;
  9876. //time_t utc = mktime(&tp);
  9877. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9878. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9879. sprintf(timebuf,"date -s '%s'",buf);
  9880. system(timebuf);
  9881. srand(time(NULL));
  9882. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  9883. //==============================================
  9884. // RTC sync
  9885. //==============================================
  9886. system("/sbin/hwclock -w --systohc");
  9887. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  9888. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9889. }
  9890. void handleDataTransferResponse(char *payload, int gun_index)
  9891. {
  9892. char sstr[160]={0};//sstr[200]={ 0 };
  9893. int c = 0;
  9894. char *loc;
  9895. DEBUG_INFO("handleDataTransferResponse ...\n");
  9896. loc = strstr(payload, "status");
  9897. printf("loc=%s\n",loc);
  9898. c = 0;
  9899. while (loc[3+strlen("status")+c] != '\"')
  9900. {
  9901. sstr[c] = loc[3+strlen("status")+c];
  9902. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9903. c++;
  9904. }
  9905. sstr[c] = '\0';
  9906. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  9907. }
  9908. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  9909. {
  9910. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  9911. //struct json_object *obj;
  9912. // obj = json_tokener_parse(payload);
  9913. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  9914. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  9915. //No fields are defined.
  9916. }
  9917. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  9918. {
  9919. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  9920. //struct json_object *obj;
  9921. // obj = json_tokener_parse(payload);
  9922. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  9923. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  9924. //No fields are defined.
  9925. }
  9926. void handleHeartbeatResponse(char *payload, int gun_index)
  9927. {
  9928. mtrace();
  9929. struct tm tp;
  9930. char buf[28]={0};
  9931. char timebuf[50]={0};
  9932. DEBUG_INFO("handleHeartbeatResponse...\n");
  9933. json_object *Heartbeat;
  9934. Heartbeat = json_tokener_parse(payload);
  9935. if(!is_error(Heartbeat))
  9936. {
  9937. // Required data
  9938. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  9939. }
  9940. json_object_put(BootNotification);
  9941. if(FirstHeartBeat == 0)
  9942. {
  9943. FirstHeartBeat = 1;
  9944. DEBUG_INFO("FirstHeartBeat \n");
  9945. }
  9946. HeartBeatWithNOResponse = 0;
  9947. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9948. tp.tm_isdst = -1;
  9949. //time_t utc = mktime(&tp);
  9950. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9951. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9952. sprintf(timebuf,"date -s '%s'",buf);
  9953. system(timebuf);
  9954. //==============================================
  9955. // RTC sync
  9956. //==============================================
  9957. system("/sbin/hwclock -w --systohc");
  9958. //===============================================
  9959. //Print Out HeartBeat log
  9960. //===============================================
  9961. {
  9962. double diff_t;
  9963. struct tm tp,tp1;
  9964. // BootNotification Receive Time
  9965. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9966. tp.tm_isdst = -1;
  9967. time_t BootNotificationReceiveTime = mktime(&tp);
  9968. //HeartBeat Receive Time
  9969. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp1);
  9970. tp1.tm_isdst = -1;
  9971. time_t HeartBeatReceiveTime = mktime(&tp1);
  9972. diff_t = difftime(HeartBeatReceiveTime, BootNotificationReceiveTime);
  9973. printf("handleHeartbeatResponse differnt time=%f..\n",diff_t);
  9974. if(((int)diff_t / 3600) > HeartBeatCountPerHour)
  9975. {
  9976. HeartBeatCountPerHour = (int)diff_t / 3600;
  9977. DEBUG_INFO("handleHeartbeatResponse ...\n");
  9978. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  9979. }
  9980. }
  9981. }
  9982. void handleMeterValuesResponse(char *payload, int gun_index)
  9983. {
  9984. mtrace();
  9985. DEBUG_INFO("handleMeterValuesResponse...\n");
  9986. }
  9987. void handleStartTransactionResponse(char *payload, int gun_index)
  9988. {
  9989. mtrace();
  9990. //int transactionIdInt = 0;
  9991. FILE *outfile;
  9992. char data[100]={0};
  9993. DEBUG_INFO("handleStartTransactionResponse...\n");
  9994. json_object *StartTransaction;
  9995. StartTransaction = json_tokener_parse(payload);
  9996. if(!is_error(StartTransaction))
  9997. {
  9998. // Required data
  9999. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  10000. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  10001. // Optional data
  10002. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  10003. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  10004. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10005. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  10006. }
  10007. json_object_put(StartTransaction);
  10008. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  10009. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  10010. //-----------Start : write to the Queue TransactionId file -----------------//
  10011. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  10012. {}
  10013. else
  10014. {
  10015. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  10016. if(log == NULL)
  10017. {
  10018. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  10019. return ;
  10020. }
  10021. else
  10022. {
  10023. fclose(log);
  10024. }
  10025. }
  10026. // open file for writing
  10027. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  10028. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  10029. {
  10030. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  10031. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  10032. fputs(data, outfile);
  10033. fclose (outfile);
  10034. }
  10035. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10036. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10037. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  10038. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  10039. }
  10040. void handleStatusNotificationResponse(char *payload, int gun_index)
  10041. {
  10042. mtrace();
  10043. DEBUG_INFO("handleStatusNotificationResponse...\n");
  10044. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  10045. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  10046. }
  10047. void handleStopTransactionnResponse(char *payload, int gun_index)
  10048. {
  10049. mtrace();
  10050. DEBUG_INFO("handleStopTransactionnResponse...\n");
  10051. json_object *StopTransaction;
  10052. StopTransaction = json_tokener_parse(payload);
  10053. if(!is_error(StopTransaction))
  10054. {
  10055. // Optional data
  10056. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  10057. {
  10058. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  10059. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  10060. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  10061. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10062. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  10063. }
  10064. }
  10065. json_object_put(StopTransaction);
  10066. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  10067. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  10068. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10069. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10070. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  10071. }
  10072. //==========================================
  10073. // Handle Error routine
  10074. //==========================================
  10075. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  10076. {
  10077. mtrace();
  10078. #ifdef SystemLogMessage
  10079. DEBUG_INFO("errorCode: %s\n", errorCode);
  10080. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  10081. DEBUG_INFO("errorDetails: %s\n", payload);
  10082. #endif
  10083. }
  10084. //===============================================
  10085. // Common routine
  10086. //===============================================
  10087. int initialConfigurationTable(void)
  10088. {
  10089. //clock_t start_t, end_t, total_t;
  10090. FILE *fp;
  10091. FILE *outfile;
  10092. char str[200]={0};
  10093. char sstr[100]={0};
  10094. int c = 0;
  10095. char *loc;
  10096. DEBUG_INFO("initialConfigurationTable...\n");
  10097. //start_t = clock();
  10098. //printf("Starting of the program, start_t = %ld\n", start_t);
  10099. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  10100. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  10101. {
  10102. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10103. if(outfile == NULL)
  10104. {
  10105. DEBUG_INFO("Error opening file\n");
  10106. return FALSE;
  10107. }
  10108. /*Core Profile*/
  10109. //AllowOfflineTxForUnknownId
  10110. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  10113. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10114. //AuthorizationCacheEnabled
  10115. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10116. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10117. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10118. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10119. //AuthorizeRemoteTxRequests
  10120. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10121. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10122. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  10123. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10124. //BlinkRepeat
  10125. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10127. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10128. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10129. //ClockAlignedDataInterval
  10130. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10131. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10132. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10133. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10134. //ConnectionTimeOut
  10135. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10136. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10137. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10138. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10139. //GetConfigurationMaxKeys
  10140. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10141. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10142. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "44" );
  10143. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10144. // HeartbeatInterval
  10145. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10146. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  10148. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10149. // LightIntensity
  10150. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10151. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10152. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10153. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10154. // LocalAuthorizeOffline
  10155. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10156. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10157. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10158. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10159. // LocalPreAuthorize
  10160. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10162. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10163. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10164. // MaxEnergyOnInvalidId
  10165. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10166. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10167. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10168. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10169. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10170. // MeterValuesAlignedData
  10171. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  10172. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10173. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10174. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10175. else
  10176. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10177. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10178. // MeterValuesAlignedDataMaxLength
  10179. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10180. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10181. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10182. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  10183. else
  10184. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10185. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10186. // MeterValuesSampledData
  10187. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  10188. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10189. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10190. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10191. else
  10192. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10193. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10194. // MeterValuesSampledDataMaxLength
  10195. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10196. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10197. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10198. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  10199. else
  10200. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10201. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10202. // MeterValueSampleInterval
  10203. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10204. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10205. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  10206. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10207. // MinimumStatusDuration
  10208. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10209. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  10211. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  10212. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10213. // NumberOfConnectors
  10214. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10215. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10216. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10217. {
  10218. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10219. }
  10220. else
  10221. {
  10222. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10223. }
  10224. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10225. // ResetRetries
  10226. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10227. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10228. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10229. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10230. // ConnectorPhaseRotation
  10231. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10232. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10233. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10234. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10235. // ConnectorPhaseRotationMaxLength
  10236. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10237. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10238. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10239. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10240. // StopTransactionOnEVSideDisconnect
  10241. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10242. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10243. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10244. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10245. // StopTransactionOnInvalidId
  10246. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  10247. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10248. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10249. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10250. // StopTxnAlignedData
  10251. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10252. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10253. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10254. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10255. // StopTxnAlignedDataMaxLength
  10256. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10257. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10258. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10259. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10260. // StopTxnSampledData
  10261. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  10262. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10263. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10264. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10265. else
  10266. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10267. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10268. // StopTxnSampledDataMaxLength
  10269. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10270. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10271. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10272. {
  10273. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  10274. }
  10275. else
  10276. {
  10277. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  10278. }
  10279. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10280. // SupportedFeatureProfiles
  10281. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10282. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10283. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10284. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10285. // SupportedFeatureProfilesMaxLength
  10286. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10287. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10288. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10289. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10290. // TransactionMessageAttempts
  10291. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10292. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10293. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10294. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10295. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10296. // TransactionMessageRetryInterval
  10297. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10298. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10299. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10300. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10301. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10302. // UnlockConnectorOnEVSideDisconnect
  10303. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10304. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10305. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10306. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10307. // WebSocketPingInterval
  10308. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10309. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10311. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10312. // QueueOffLineStartTransactionMessage
  10313. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  10314. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10315. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10316. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10317. //* Local Auth List Management Profile*/
  10318. #if 0
  10319. //For OCTT Test Case
  10320. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10321. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10322. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10323. #endif
  10324. #if 1
  10325. //LocalAuthListEnabled
  10326. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10327. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10328. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10329. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10330. #endif
  10331. //LocalAuthListMaxLength
  10332. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10333. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10334. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10335. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10336. //SendLocalListMaxLength
  10337. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10338. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10339. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  10340. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10341. //ReserveConnectorZeroSupported
  10342. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10343. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10344. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10345. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10346. //* Smart Charging Profile */
  10347. //ChargeProfileMaxStackLevel
  10348. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10349. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10350. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10351. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10352. // ChargingScheduleAllowedChargingRateUnit
  10353. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10354. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10355. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10356. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10357. // ChargingScheduleMaxPeriods
  10358. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10359. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10360. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10361. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10362. // ConnectorSwitch3to1PhaseSupported
  10363. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10364. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10365. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10366. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10367. // MaxChargingProfilesInstalled
  10368. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10369. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10370. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10371. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10372. fclose(outfile);
  10373. }
  10374. else
  10375. {
  10376. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10377. char keystr[60]={0};
  10378. char readonlystr[10]={0};
  10379. char valuestr[100]={0};
  10380. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10381. if(fp == NULL) {
  10382. DEBUG_INFO("Error opening file");
  10383. return FALSE;
  10384. }
  10385. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  10386. {
  10387. //DEBUG_INFO("Get Configuration \n");
  10388. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10389. //*************************key*********************************/
  10390. loc = strstr(str, "key");
  10391. c = 0;
  10392. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10393. while (loc[strlen("key")+3+c] != '\"')
  10394. {
  10395. sstr[c] = loc[strlen("key")+3+c];
  10396. c++;
  10397. }
  10398. sstr[c] = '\0';
  10399. strcpy(keystr,sstr);
  10400. //*************************readonly*********************************/
  10401. loc = strstr(str, "readonly");
  10402. c = 0;
  10403. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10404. while (loc[strlen("readonly")+2+c] != ',')
  10405. {
  10406. sstr[c] = loc[strlen("readonly")+2+c];
  10407. c++;
  10408. }
  10409. sstr[c] = '\0';
  10410. strcpy(readonlystr,sstr);
  10411. //*************************value*********************************/
  10412. loc = strstr(str, "value");
  10413. c = 0;
  10414. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10415. while (loc[strlen("value")+3+c] != '\"')
  10416. {
  10417. sstr[c] = loc[strlen("value")+3+c];
  10418. c++;
  10419. }
  10420. sstr[c] = '\0';
  10421. strcpy(valuestr,sstr);
  10422. // DEBUG_INFO("keystr=%s\n",keystr);
  10423. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10424. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10425. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10426. {
  10427. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10428. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10429. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10430. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10431. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10432. }
  10433. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10434. {
  10435. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10436. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10437. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10438. }
  10439. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10440. {
  10441. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10442. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10443. }
  10444. if(strcmp(keystr, "BlinkRepeat") == 0)
  10445. {
  10446. //Charger.BlinkRepeat = Integer.parseInt(value);
  10447. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10448. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10449. }
  10450. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10451. {
  10452. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10453. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10454. }
  10455. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10456. {
  10457. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10458. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10459. }
  10460. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10461. {
  10462. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10463. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  10464. }
  10465. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10466. {
  10467. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10468. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10469. HeartBeatWaitTime = atoi(valuestr);
  10470. }
  10471. if(strcmp(keystr, "LightIntensity") == 0)
  10472. {
  10473. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10474. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10475. }
  10476. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10477. {
  10478. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10479. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10480. }
  10481. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10482. {
  10483. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10484. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10485. }
  10486. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10487. {
  10488. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10489. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10490. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10491. }
  10492. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10493. {
  10494. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10495. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10496. }
  10497. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10498. {
  10499. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10500. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10501. }
  10502. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10503. {
  10504. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10505. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10506. }
  10507. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10508. {
  10509. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10510. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10511. }
  10512. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10513. {
  10514. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10515. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10516. }
  10517. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10518. {
  10519. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10520. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10521. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10522. }
  10523. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10524. {
  10525. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10526. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10527. }
  10528. if(strcmp(keystr, "ResetRetries") == 0)
  10529. {
  10530. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10531. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10532. }
  10533. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10534. {
  10535. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10536. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10537. }
  10538. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10539. {
  10540. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10541. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10542. }
  10543. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10544. {
  10545. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10546. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10547. }
  10548. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10549. {
  10550. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10551. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10552. }
  10553. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10554. {
  10555. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10556. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10557. }
  10558. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10559. {
  10560. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10561. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10562. }
  10563. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10564. {
  10565. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10566. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10567. }
  10568. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10569. {
  10570. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10571. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10572. }
  10573. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10574. {
  10575. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10576. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10577. }
  10578. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10579. {
  10580. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10581. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10582. }
  10583. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10584. {
  10585. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10586. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10587. TransactionMessageAttemptsValue = atoi(valuestr);
  10588. }
  10589. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10590. {
  10591. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10592. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10593. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10594. }
  10595. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10596. {
  10597. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10598. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10599. }
  10600. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10601. {
  10602. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10603. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10604. }
  10605. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  10606. {
  10607. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10608. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  10609. }
  10610. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10611. {
  10612. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10613. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10614. }
  10615. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10616. {
  10617. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10618. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10619. }
  10620. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10621. {
  10622. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10623. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10624. }
  10625. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10626. {
  10627. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10628. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10629. }
  10630. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10631. {
  10632. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10633. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10634. }
  10635. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10636. {
  10637. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10638. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10639. }
  10640. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10641. {
  10642. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10643. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10644. }
  10645. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10646. {
  10647. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10648. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10649. }
  10650. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10651. {
  10652. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10653. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10654. }
  10655. }
  10656. fclose(fp);
  10657. }
  10658. return 0;
  10659. }
  10660. void StoreConfigurationTable(void)
  10661. {
  10662. FILE *outfile;
  10663. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10664. if(outfile == NULL)
  10665. {
  10666. DEBUG_INFO("Error opening file");
  10667. return ;
  10668. }
  10669. /*Core Profile*/
  10670. //AllowOfflineTxForUnknownId
  10671. /*
  10672. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10673. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10674. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10675. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10676. */
  10677. //DEBUG_INFO("data=%s\n",data);
  10678. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10679. //AuthorizationCacheEnabled
  10680. /*
  10681. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10682. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10683. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10684. */
  10685. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10686. //AuthorizeRemoteTxRequests
  10687. /*
  10688. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10689. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10690. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10691. */
  10692. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10693. //BlinkRepeat
  10694. /*
  10695. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10697. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10698. */
  10699. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10700. //ClockAlignedDataInterval
  10701. /*
  10702. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10703. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10704. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10705. */
  10706. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10707. //ConnectionTimeOut
  10708. /*
  10709. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10710. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10711. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10712. */
  10713. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10714. //GetConfigurationMaxKeys
  10715. /*
  10716. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10717. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10718. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10719. */
  10720. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10721. // HeartbeatInterval
  10722. /*
  10723. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10724. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10725. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10726. */
  10727. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10728. // LightIntensity
  10729. /*
  10730. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10731. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10732. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10733. */
  10734. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10735. // LocalAuthorizeOffline
  10736. /*
  10737. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10738. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10739. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10740. */
  10741. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10742. // LocalPreAuthorize
  10743. /*
  10744. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10746. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10747. */
  10748. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10749. // MaxEnergyOnInvalidId
  10750. /*
  10751. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10752. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10753. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10754. */
  10755. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10756. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10757. // MeterValuesAlignedData
  10758. /*
  10759. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10760. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10761. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10762. */
  10763. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10764. // MeterValuesAlignedDataMaxLength
  10765. /*
  10766. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10767. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10768. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10769. */
  10770. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10771. // MeterValuesSampledData
  10772. /*
  10773. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10775. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10776. */
  10777. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10778. // MeterValuesSampledDataMaxLength
  10779. /*
  10780. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10781. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10782. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10783. */
  10784. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10785. // MeterValueSampleInterval
  10786. /*
  10787. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10789. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10790. */
  10791. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10792. // MinimumStatusDuration
  10793. /*
  10794. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10796. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10797. */
  10798. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10799. // NumberOfConnectors
  10800. /*
  10801. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10803. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10804. {
  10805. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10806. }
  10807. else
  10808. {
  10809. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10810. }
  10811. */
  10812. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10813. // ResetRetries
  10814. /*
  10815. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10816. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10818. */
  10819. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10820. // ConnectorPhaseRotation
  10821. /*
  10822. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10825. */
  10826. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10827. // ConnectorPhaseRotationMaxLength
  10828. /*
  10829. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10830. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10831. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10832. */
  10833. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10834. // StopTransactionOnEVSideDisconnect
  10835. /*
  10836. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10837. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10838. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10839. */
  10840. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10841. // StopTransactionOnInvalidId
  10842. /*
  10843. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  10844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10845. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10846. */
  10847. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10848. // StopTxnAlignedData
  10849. /*
  10850. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10852. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10853. */
  10854. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10855. // StopTxnAlignedDataMaxLength
  10856. /*
  10857. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10859. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10860. */
  10861. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10862. // StopTxnSampledData
  10863. /*
  10864. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10865. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  10867. */
  10868. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10869. // StopTxnSampledDataMaxLength
  10870. /*
  10871. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10872. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10874. */
  10875. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10876. // SupportedFeatureProfiles
  10877. /*
  10878. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10879. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10880. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10881. */
  10882. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10883. // SupportedFeatureProfilesMaxLength
  10884. /*
  10885. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10886. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10888. */
  10889. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10890. // TransactionMessageAttempts
  10891. /*
  10892. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10893. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10894. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10895. */
  10896. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10897. // TransactionMessageRetryInterval
  10898. /*
  10899. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10900. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10901. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10902. */
  10903. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10904. // UnlockConnectorOnEVSideDisconnect
  10905. /*
  10906. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10907. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10908. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10909. */
  10910. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10911. // WebSocketPingInterval
  10912. /*
  10913. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10914. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10915. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10916. */
  10917. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10918. // QueueOffLineStartTransactionMessage
  10919. /*
  10920. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  10921. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10922. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10923. */
  10924. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10925. //* Local Auth List Management Profile*/
  10926. //LocalAuthListEnabled
  10927. /*
  10928. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10929. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10930. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10931. */
  10932. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10933. //LocalAuthListMaxLength
  10934. /*
  10935. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10936. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10937. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10938. */
  10939. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10940. //SendLocalListMaxLength
  10941. /*
  10942. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10943. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10944. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10945. */
  10946. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10947. //ReserveConnectorZeroSupported
  10948. /*
  10949. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10950. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10951. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10952. */
  10953. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10954. //* Smart Charging Profile */
  10955. //ChargeProfileMaxStackLevel
  10956. /*
  10957. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10958. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10959. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10960. */
  10961. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10962. // ChargingScheduleAllowedChargingRateUnit
  10963. /*
  10964. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10965. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10966. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10967. */
  10968. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10969. // ChargingScheduleMaxPeriods
  10970. /*
  10971. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10972. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10973. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10974. */
  10975. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10976. // ConnectorSwitch3to1PhaseSupported
  10977. /*
  10978. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10979. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10980. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10981. */
  10982. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10983. // MaxChargingProfilesInstalled
  10984. /*
  10985. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10986. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10987. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10988. */
  10989. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10990. fclose(outfile);
  10991. }
  10992. void getKeyValue(char *keyReq)
  10993. {
  10994. int isEmpty = FALSE;
  10995. int isKnowKey = FALSE;
  10996. DEBUG_INFO("keyReq = %s\n", keyReq);
  10997. if((keyReq == NULL) || (strlen(keyReq) == 0))
  10998. isEmpty = TRUE;
  10999. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  11000. {
  11001. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  11002. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  11003. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11004. {
  11005. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  11006. }
  11007. else
  11008. {
  11009. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  11010. }
  11011. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  11012. isKnowKey = TRUE;
  11013. }
  11014. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  11015. {
  11016. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  11017. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  11018. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11019. {
  11020. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  11021. }
  11022. else
  11023. {
  11024. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  11025. }
  11026. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  11027. isKnowKey = TRUE;
  11028. }
  11029. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  11030. {
  11031. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  11032. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  11033. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11034. {
  11035. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  11036. }
  11037. else
  11038. {
  11039. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  11040. }
  11041. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  11042. isKnowKey = TRUE;
  11043. }
  11044. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  11045. {
  11046. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  11047. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  11048. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11049. {
  11050. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  11051. }
  11052. else
  11053. {
  11054. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  11055. }
  11056. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  11057. isKnowKey = TRUE;
  11058. }
  11059. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  11060. {
  11061. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  11062. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  11063. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11064. {
  11065. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  11066. }
  11067. else
  11068. {
  11069. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  11070. }
  11071. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  11072. isKnowKey = TRUE;
  11073. }
  11074. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  11075. {
  11076. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  11077. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  11078. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11079. {
  11080. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  11081. }
  11082. else
  11083. {
  11084. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  11085. }
  11086. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  11087. isKnowKey = TRUE;
  11088. }
  11089. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  11090. {
  11091. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  11092. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  11093. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11094. {
  11095. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  11096. }
  11097. else
  11098. {
  11099. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  11100. }
  11101. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  11102. isKnowKey = TRUE;
  11103. }
  11104. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  11105. {
  11106. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  11107. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  11108. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11109. {
  11110. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  11111. }
  11112. else
  11113. {
  11114. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  11115. }
  11116. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  11117. isKnowKey = TRUE;
  11118. }
  11119. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  11120. {
  11121. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  11122. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  11123. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11124. {
  11125. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  11126. }
  11127. else
  11128. {
  11129. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  11130. }
  11131. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  11132. isKnowKey = TRUE;
  11133. }
  11134. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  11135. {
  11136. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  11137. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  11138. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11139. {
  11140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  11141. }
  11142. else
  11143. {
  11144. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  11145. }
  11146. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  11147. isKnowKey = TRUE;
  11148. }
  11149. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  11150. {
  11151. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  11152. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  11153. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11154. {
  11155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  11156. }
  11157. else
  11158. {
  11159. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  11160. }
  11161. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  11162. isKnowKey = TRUE;
  11163. }
  11164. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  11165. {
  11166. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  11167. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  11168. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11169. {
  11170. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11171. }
  11172. else
  11173. {
  11174. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11175. }
  11176. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  11177. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  11178. isKnowKey = TRUE;
  11179. }
  11180. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  11181. {
  11182. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  11183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11184. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11185. {
  11186. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11187. }
  11188. else
  11189. {
  11190. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11191. }
  11192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11193. isKnowKey = TRUE;
  11194. }
  11195. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11196. {
  11197. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11199. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11200. {
  11201. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11202. }
  11203. else
  11204. {
  11205. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11206. }
  11207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11208. isKnowKey = TRUE;
  11209. }
  11210. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11211. {
  11212. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11214. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11215. {
  11216. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11217. }
  11218. else
  11219. {
  11220. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11221. }
  11222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11223. isKnowKey = TRUE;
  11224. }
  11225. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11226. {
  11227. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11229. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11230. {
  11231. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11232. }
  11233. else
  11234. {
  11235. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11236. }
  11237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11238. isKnowKey = TRUE;
  11239. }
  11240. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11241. {
  11242. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11244. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11245. {
  11246. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11247. }
  11248. else
  11249. {
  11250. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11251. }
  11252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11253. isKnowKey = TRUE;
  11254. }
  11255. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11256. {
  11257. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11259. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11260. {
  11261. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11262. }
  11263. else
  11264. {
  11265. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11266. }
  11267. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11268. isKnowKey = TRUE;
  11269. }
  11270. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11271. {
  11272. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11273. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11274. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11275. {
  11276. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11277. }
  11278. else
  11279. {
  11280. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11281. }
  11282. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11283. isKnowKey = TRUE;
  11284. }
  11285. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11286. {
  11287. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11288. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11289. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11290. {
  11291. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11292. }
  11293. else
  11294. {
  11295. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11296. }
  11297. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11298. isKnowKey = TRUE;
  11299. }
  11300. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11301. {
  11302. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11303. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11304. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11305. {
  11306. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11307. }
  11308. else
  11309. {
  11310. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11311. }
  11312. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11313. isKnowKey = TRUE;
  11314. }
  11315. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11316. {
  11317. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11318. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11319. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11320. {
  11321. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11322. }
  11323. else
  11324. {
  11325. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11326. }
  11327. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11328. isKnowKey = TRUE;
  11329. }
  11330. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11331. {
  11332. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11333. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11334. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11335. {
  11336. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11337. }
  11338. else
  11339. {
  11340. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11341. }
  11342. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11343. isKnowKey = TRUE;
  11344. }
  11345. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11346. {
  11347. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11348. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11349. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11350. {
  11351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11352. }
  11353. else
  11354. {
  11355. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11356. }
  11357. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11358. isKnowKey = TRUE;
  11359. }
  11360. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11361. {
  11362. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11363. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11364. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11365. {
  11366. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11367. }
  11368. else
  11369. {
  11370. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11371. }
  11372. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11373. isKnowKey = TRUE;
  11374. }
  11375. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11376. {
  11377. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11378. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11379. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11380. {
  11381. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11382. }
  11383. else
  11384. {
  11385. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11386. }
  11387. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11388. isKnowKey = TRUE;
  11389. }
  11390. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11391. {
  11392. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11393. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11394. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11395. {
  11396. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11397. }
  11398. else
  11399. {
  11400. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11401. }
  11402. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11403. isKnowKey = TRUE;
  11404. }
  11405. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11406. {
  11407. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11408. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11409. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11410. {
  11411. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11412. }
  11413. else
  11414. {
  11415. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11416. }
  11417. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11418. isKnowKey = TRUE;
  11419. }
  11420. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11421. {
  11422. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11423. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11424. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11425. {
  11426. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11427. }
  11428. else
  11429. {
  11430. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11431. }
  11432. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11433. isKnowKey = TRUE;
  11434. }
  11435. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11436. {
  11437. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11438. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11439. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11440. {
  11441. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11442. }
  11443. else
  11444. {
  11445. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11446. }
  11447. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11448. isKnowKey = TRUE;
  11449. }
  11450. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11451. {
  11452. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11453. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11454. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11455. {
  11456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11457. }
  11458. else
  11459. {
  11460. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11461. }
  11462. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11463. isKnowKey = TRUE;
  11464. }
  11465. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11466. {
  11467. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11468. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11469. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11470. {
  11471. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11472. }
  11473. else
  11474. {
  11475. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11476. }
  11477. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11478. isKnowKey = TRUE;
  11479. }
  11480. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11481. {
  11482. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11483. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11484. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11485. {
  11486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11487. }
  11488. else
  11489. {
  11490. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11491. }
  11492. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11493. isKnowKey = TRUE;
  11494. }
  11495. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11496. {
  11497. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11498. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11499. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11500. {
  11501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11502. }
  11503. else
  11504. {
  11505. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11506. }
  11507. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11508. isKnowKey = TRUE;
  11509. }
  11510. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  11511. {
  11512. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  11513. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  11514. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  11515. {
  11516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  11517. }
  11518. else
  11519. {
  11520. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  11521. }
  11522. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  11523. isKnowKey = TRUE;
  11524. }
  11525. #if 1
  11526. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11527. {
  11528. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11529. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11530. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11531. {
  11532. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11533. }
  11534. else
  11535. {
  11536. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11537. }
  11538. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11539. isKnowKey = TRUE;
  11540. }
  11541. #endif
  11542. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11543. {
  11544. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11545. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11546. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11547. {
  11548. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11549. }
  11550. else
  11551. {
  11552. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11553. }
  11554. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11555. isKnowKey = TRUE;
  11556. }
  11557. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11558. {
  11559. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11560. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11561. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11562. {
  11563. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11564. }
  11565. else
  11566. {
  11567. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11568. }
  11569. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11570. isKnowKey = TRUE;
  11571. }
  11572. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11573. {
  11574. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11575. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11576. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11577. {
  11578. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11579. }
  11580. else
  11581. {
  11582. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11583. }
  11584. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11585. isKnowKey = TRUE;
  11586. }
  11587. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11588. {
  11589. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11590. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11591. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11592. {
  11593. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11594. }
  11595. else
  11596. {
  11597. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11598. }
  11599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11600. isKnowKey = TRUE;
  11601. }
  11602. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11603. {
  11604. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11605. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11606. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11607. {
  11608. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11609. }
  11610. else
  11611. {
  11612. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11613. }
  11614. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11615. isKnowKey = TRUE;
  11616. }
  11617. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11618. {
  11619. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11620. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11621. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11622. {
  11623. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11624. }
  11625. else
  11626. {
  11627. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11628. }
  11629. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11630. isKnowKey = TRUE;
  11631. }
  11632. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11633. {
  11634. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11635. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11636. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11637. {
  11638. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11639. }
  11640. else
  11641. {
  11642. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11643. }
  11644. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11645. isKnowKey = TRUE;
  11646. }
  11647. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11648. {
  11649. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11650. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11651. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11652. {
  11653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11654. }
  11655. else
  11656. {
  11657. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11658. }
  11659. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11660. isKnowKey = TRUE;
  11661. }
  11662. //=========================================================
  11663. if(!isEmpty && !isKnowKey)
  11664. {
  11665. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11666. strcpy(unknownkey[UnknownKeynum], keyReq);
  11667. UnknownKeynum = UnknownKeynum + 1;
  11668. }
  11669. }
  11670. void processUnkownKey(void)
  11671. {
  11672. DEBUG_INFO("processUnkownKey...\n");
  11673. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11674. for(int index=0; index < UnknownKeynum; index++)
  11675. {
  11676. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11677. {
  11678. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11679. }
  11680. }
  11681. }
  11682. int setKeyValue(char *key, char *value)
  11683. {
  11684. int isSuccess = NotSupported;
  11685. int check_ascii=0;
  11686. char str[10]={0};
  11687. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  11688. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11689. {
  11690. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11691. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11692. {
  11693. strcpy(str, (const char*)value);
  11694. for(int i = 0; str[i]; i++){
  11695. str[i] = tolower(str[i]);
  11696. }
  11697. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11698. isSuccess = ConfigurationStatus_Accepted;
  11699. }
  11700. else
  11701. {
  11702. isSuccess = ConfigurationStatus_Rejected;
  11703. }
  11704. }
  11705. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11706. {
  11707. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11708. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11709. {
  11710. strcpy(str, (const char*)value);
  11711. for(int i = 0; str[i]; i++){
  11712. str[i] = tolower(str[i]);
  11713. }
  11714. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11715. isSuccess = ConfigurationStatus_Accepted;
  11716. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11717. }
  11718. else
  11719. {
  11720. isSuccess = ConfigurationStatus_Rejected;
  11721. }
  11722. }
  11723. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11724. {
  11725. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11726. {
  11727. strcpy(str, (const char*)value);
  11728. for(int i = 0; str[i]; i++)
  11729. {
  11730. str[i] = tolower(str[i]);
  11731. }
  11732. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11733. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11734. isSuccess = ConfigurationStatus_Accepted;
  11735. }
  11736. else
  11737. {
  11738. isSuccess = ConfigurationStatus_Rejected;
  11739. }
  11740. }
  11741. if(strcmp(key, "BlinkRepeat") == 0)
  11742. {
  11743. //Charger.BlinkRepeat = Integer.parseInt(value);
  11744. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11745. {
  11746. check_ascii = value[0];
  11747. if( (check_ascii < 48) || (check_ascii > 57) )
  11748. {
  11749. isSuccess = ConfigurationStatus_Rejected;
  11750. }
  11751. else
  11752. {
  11753. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11754. isSuccess = ConfigurationStatus_Accepted;
  11755. }
  11756. }
  11757. else
  11758. {
  11759. isSuccess = ConfigurationStatus_Rejected;
  11760. }
  11761. }
  11762. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11763. {
  11764. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11765. {
  11766. check_ascii = value[0];
  11767. if( (check_ascii < 48) || (check_ascii > 57) )
  11768. {
  11769. isSuccess = ConfigurationStatus_Rejected;
  11770. }
  11771. else
  11772. {
  11773. if((atoi(value) == 0) || (atoi(value) >= 10))
  11774. {
  11775. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11776. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11777. isSuccess = ConfigurationStatus_Accepted;
  11778. }
  11779. else
  11780. isSuccess = ConfigurationStatus_Rejected;
  11781. }
  11782. }
  11783. else
  11784. {
  11785. isSuccess = ConfigurationStatus_Rejected;
  11786. }
  11787. }
  11788. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11789. {
  11790. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11791. {
  11792. check_ascii = value[0];
  11793. if( (check_ascii < 48) || (check_ascii > 57) )
  11794. {
  11795. isSuccess = ConfigurationStatus_Rejected;
  11796. }
  11797. else
  11798. {
  11799. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11800. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11801. isSuccess = ConfigurationStatus_Accepted;
  11802. }
  11803. }
  11804. else
  11805. {
  11806. isSuccess = ConfigurationStatus_Rejected;
  11807. }
  11808. }
  11809. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11810. {
  11811. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11812. {
  11813. check_ascii = value[0];
  11814. if( (check_ascii < 48) || (check_ascii > 57) )
  11815. {
  11816. isSuccess = ConfigurationStatus_Rejected;
  11817. }
  11818. else
  11819. {
  11820. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11821. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11822. isSuccess = ConfigurationStatus_Accepted;
  11823. }
  11824. }
  11825. else
  11826. {
  11827. isSuccess = ConfigurationStatus_Rejected;
  11828. }
  11829. }
  11830. if(strcmp(key, "HeartbeatInterval") == 0)
  11831. {
  11832. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11833. {
  11834. check_ascii = value[0];
  11835. if( (check_ascii < 48) || (check_ascii > 57) )
  11836. {
  11837. isSuccess = ConfigurationStatus_Rejected;
  11838. }
  11839. else
  11840. {
  11841. if((atoi(value) == 0) || (atoi(value) >= 10))
  11842. {
  11843. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11844. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11845. HeartBeatWaitTime = atoi(value);
  11846. isSuccess = ConfigurationStatus_Accepted;
  11847. }
  11848. else
  11849. {
  11850. isSuccess = ConfigurationStatus_Rejected;
  11851. }
  11852. }
  11853. }
  11854. else
  11855. {
  11856. isSuccess = ConfigurationStatus_Rejected;
  11857. }
  11858. }
  11859. if(strcmp(key, "LightIntensity") == 0)
  11860. {
  11861. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11862. {
  11863. check_ascii = value[0];
  11864. if( (check_ascii < 48) || (check_ascii > 57) )
  11865. {
  11866. isSuccess = ConfigurationStatus_Rejected;
  11867. }
  11868. else
  11869. {
  11870. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  11871. isSuccess = ConfigurationStatus_Accepted;
  11872. }
  11873. }
  11874. else
  11875. {
  11876. isSuccess = ConfigurationStatus_Rejected;
  11877. }
  11878. }
  11879. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  11880. {
  11881. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11882. {
  11883. strcpy(str, (const char*)value);
  11884. for(int i = 0; str[i]; i++)
  11885. {
  11886. str[i] = tolower(str[i]);
  11887. }
  11888. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11889. isSuccess = ConfigurationStatus_Accepted;
  11890. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11891. }
  11892. else
  11893. {
  11894. isSuccess = ConfigurationStatus_Rejected;
  11895. }
  11896. }
  11897. if(strcmp(key, "LocalPreAuthorize") == 0)
  11898. {
  11899. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11900. {
  11901. strcpy(str, (const char*)value);
  11902. for(int i = 0; str[i]; i++)
  11903. {
  11904. str[i] = tolower(str[i]);
  11905. }
  11906. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11907. isSuccess = ConfigurationStatus_Accepted;
  11908. }
  11909. else
  11910. {
  11911. isSuccess = ConfigurationStatus_Rejected;
  11912. }
  11913. }
  11914. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  11915. {
  11916. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11917. {
  11918. check_ascii = value[0];
  11919. if( (check_ascii < 48) || (check_ascii > 57) )
  11920. {
  11921. isSuccess = ConfigurationStatus_Rejected;
  11922. }
  11923. else
  11924. {
  11925. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  11926. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  11927. isSuccess = ConfigurationStatus_Accepted;
  11928. }
  11929. }
  11930. else
  11931. {
  11932. isSuccess = ConfigurationStatus_Rejected;
  11933. }
  11934. }
  11935. if(strcmp(key, "MeterValuesAlignedData") == 0)
  11936. {
  11937. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11938. {
  11939. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  11940. isSuccess = ConfigurationStatus_Accepted;
  11941. }
  11942. else
  11943. {
  11944. isSuccess = ConfigurationStatus_Rejected;
  11945. }
  11946. }
  11947. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  11948. {
  11949. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11950. {
  11951. check_ascii = value[0];
  11952. if( (check_ascii < 48) || (check_ascii > 57) )
  11953. {
  11954. isSuccess = ConfigurationStatus_Rejected;
  11955. }
  11956. else
  11957. {
  11958. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11959. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  11960. isSuccess = ConfigurationStatus_Accepted;
  11961. }
  11962. }
  11963. else
  11964. {
  11965. isSuccess = ConfigurationStatus_Rejected;
  11966. }
  11967. }
  11968. if(strcmp(key, "MeterValuesSampledData") == 0 )
  11969. {
  11970. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11971. {
  11972. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  11973. isSuccess = ConfigurationStatus_Accepted;
  11974. }
  11975. else
  11976. {
  11977. isSuccess = ConfigurationStatus_Rejected;
  11978. }
  11979. }
  11980. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  11981. {
  11982. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11983. {
  11984. check_ascii = value[0];
  11985. if( (check_ascii < 48) || (check_ascii > 57) )
  11986. {
  11987. isSuccess = ConfigurationStatus_Rejected;
  11988. }
  11989. else
  11990. {
  11991. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11992. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  11993. isSuccess = ConfigurationStatus_Accepted;
  11994. }
  11995. }
  11996. else
  11997. {
  11998. isSuccess = ConfigurationStatus_Rejected;
  11999. }
  12000. }
  12001. if(strcmp(key, "MeterValueSampleInterval") == 0)
  12002. {
  12003. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12004. {
  12005. check_ascii = value[0];
  12006. if( (check_ascii < 48) || (check_ascii > 57) )
  12007. {
  12008. isSuccess = ConfigurationStatus_Rejected;
  12009. }
  12010. else
  12011. {
  12012. if((atoi(value) == 0) || (atoi(value) >= 10))
  12013. {
  12014. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12015. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  12016. isSuccess = ConfigurationStatus_Accepted;
  12017. }
  12018. else
  12019. {
  12020. isSuccess = ConfigurationStatus_Rejected;
  12021. }
  12022. }
  12023. }
  12024. else
  12025. {
  12026. isSuccess = ConfigurationStatus_Rejected;
  12027. }
  12028. }
  12029. if(strcmp(key, "MinimumStatusDuration") == 0)
  12030. {
  12031. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12032. {
  12033. check_ascii = value[0];
  12034. if( (check_ascii < 48) || (check_ascii > 57) )
  12035. {
  12036. isSuccess = ConfigurationStatus_Rejected;
  12037. }
  12038. else
  12039. {
  12040. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  12041. {
  12042. isSuccess = ConfigurationStatus_Rejected;
  12043. }
  12044. else
  12045. {
  12046. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  12047. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  12048. server_cycle_Status = atoi(value); //StatusNotification Cycle
  12049. isSuccess = ConfigurationStatus_Accepted;
  12050. }
  12051. }
  12052. }
  12053. else
  12054. {
  12055. isSuccess = ConfigurationStatus_Rejected;
  12056. }
  12057. }
  12058. if(strcmp(key, "NumberOfConnectors") == 0)
  12059. {
  12060. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12061. {
  12062. check_ascii = value[0];
  12063. if( (check_ascii < 48) || (check_ascii > 57) )
  12064. {
  12065. isSuccess = ConfigurationStatus_Rejected;
  12066. }
  12067. else
  12068. {
  12069. //Charger.ResetRetries = Integer.parseInt(value);
  12070. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  12071. isSuccess = ConfigurationStatus_Accepted;
  12072. }
  12073. }
  12074. else
  12075. {
  12076. isSuccess = ConfigurationStatus_Rejected;
  12077. }
  12078. }
  12079. if(strcmp(key, "ResetRetries") == 0)
  12080. {
  12081. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12082. {
  12083. check_ascii = value[0];
  12084. if( (check_ascii < 48) || (check_ascii > 57) )
  12085. {
  12086. isSuccess = ConfigurationStatus_Rejected;
  12087. }
  12088. else
  12089. {
  12090. //Charger.ResetRetries = Integer.parseInt(value);
  12091. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  12092. isSuccess = ConfigurationStatus_Accepted;
  12093. }
  12094. }
  12095. else
  12096. {
  12097. isSuccess = ConfigurationStatus_Rejected;
  12098. }
  12099. }
  12100. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  12101. {
  12102. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12103. {
  12104. strcpy(str, (const char*)value);
  12105. for(int i = 0; str[i]; i++)
  12106. {
  12107. str[i] = tolower(str[i]);
  12108. }
  12109. if(strcmp(str, "notapplicable")== 0)
  12110. {
  12111. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12112. isSuccess = ConfigurationStatus_Accepted;
  12113. }
  12114. else if(strcmp(str, "unknown")== 0)
  12115. {
  12116. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12117. isSuccess = ConfigurationStatus_Accepted;
  12118. }
  12119. else if(strcmp(str, "rst")== 0)
  12120. {
  12121. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12122. isSuccess = ConfigurationStatus_Accepted;
  12123. }
  12124. else if(strcmp(str, "rts")== 0)
  12125. {
  12126. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12127. isSuccess = ConfigurationStatus_Accepted;
  12128. }
  12129. else if(strcmp(str, "srt")== 0)
  12130. {
  12131. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12132. isSuccess = ConfigurationStatus_Accepted;
  12133. }
  12134. else if(strcmp(str, "str")== 0)
  12135. {
  12136. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12137. isSuccess = ConfigurationStatus_Accepted;
  12138. }
  12139. else if(strcmp(str, "trs")== 0)
  12140. {
  12141. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12142. isSuccess = ConfigurationStatus_Accepted;
  12143. }
  12144. else if(strcmp(str, "tsr")== 0)
  12145. {
  12146. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12147. isSuccess = ConfigurationStatus_Accepted;
  12148. }
  12149. else
  12150. {
  12151. isSuccess = ConfigurationStatus_Rejected;
  12152. }
  12153. }
  12154. else
  12155. {
  12156. isSuccess = ConfigurationStatus_Rejected;
  12157. }
  12158. }
  12159. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12160. {
  12161. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12162. {
  12163. check_ascii = value[0];
  12164. if( (check_ascii < 48) || (check_ascii > 57) )
  12165. {
  12166. isSuccess = ConfigurationStatus_Rejected;
  12167. }
  12168. else
  12169. {
  12170. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12171. isSuccess = ConfigurationStatus_Accepted;
  12172. }
  12173. }
  12174. else
  12175. {
  12176. isSuccess = ConfigurationStatus_Rejected;
  12177. }
  12178. }
  12179. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12180. {
  12181. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12182. {
  12183. strcpy(str, (const char*)value);
  12184. for(int i = 0; str[i]; i++)
  12185. {
  12186. str[i] = tolower(str[i]);
  12187. }
  12188. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12189. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12190. isSuccess = ConfigurationStatus_Accepted;
  12191. }
  12192. else
  12193. {
  12194. isSuccess = ConfigurationStatus_Rejected;
  12195. }
  12196. }
  12197. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12198. {
  12199. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12200. {
  12201. strcpy(str, (const char*)value);
  12202. for(int i = 0; str[i]; i++)
  12203. {
  12204. str[i] = tolower(str[i]);
  12205. }
  12206. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12207. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12208. isSuccess = ConfigurationStatus_Accepted;
  12209. }
  12210. else
  12211. {
  12212. isSuccess = ConfigurationStatus_Rejected;
  12213. }
  12214. }
  12215. if(strcmp(key, "StopTxnAlignedData") == 0)
  12216. {
  12217. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12218. {
  12219. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12220. isSuccess = ConfigurationStatus_Accepted;
  12221. }
  12222. else
  12223. {
  12224. isSuccess = ConfigurationStatus_Rejected;
  12225. }
  12226. }
  12227. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12228. {
  12229. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12230. {
  12231. check_ascii = value[0];
  12232. if( (check_ascii < 48) || (check_ascii > 57) )
  12233. {
  12234. isSuccess = ConfigurationStatus_Rejected;
  12235. }
  12236. else
  12237. {
  12238. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12239. isSuccess = ConfigurationStatus_Accepted;
  12240. }
  12241. }
  12242. else
  12243. {
  12244. isSuccess = ConfigurationStatus_Rejected;
  12245. }
  12246. }
  12247. if(strcmp(key, "StopTxnSampledData") == 0)
  12248. {
  12249. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12250. {
  12251. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12252. isSuccess = ConfigurationStatus_Accepted;
  12253. }
  12254. else
  12255. {
  12256. isSuccess = ConfigurationStatus_Rejected;
  12257. }
  12258. }
  12259. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12260. {
  12261. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12262. {
  12263. check_ascii = value[0];
  12264. if( (check_ascii < 48) || (check_ascii > 57) )
  12265. {
  12266. isSuccess = ConfigurationStatus_Rejected;
  12267. }
  12268. else
  12269. {
  12270. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12271. isSuccess = ConfigurationStatus_Accepted;
  12272. }
  12273. }
  12274. else
  12275. {
  12276. isSuccess = ConfigurationStatus_Rejected;
  12277. }
  12278. }
  12279. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12280. {
  12281. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12282. {
  12283. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12284. isSuccess = ConfigurationStatus_Accepted;
  12285. }
  12286. else
  12287. {
  12288. isSuccess = ConfigurationStatus_Rejected;
  12289. }
  12290. }
  12291. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12292. {
  12293. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12294. {
  12295. check_ascii = value[0];
  12296. if( (check_ascii < 48) || (check_ascii > 57) )
  12297. {
  12298. isSuccess = ConfigurationStatus_Rejected;
  12299. }
  12300. else
  12301. {
  12302. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12303. isSuccess = ConfigurationStatus_Accepted;
  12304. }
  12305. }
  12306. else
  12307. {
  12308. isSuccess = ConfigurationStatus_Rejected;
  12309. }
  12310. }
  12311. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12312. {
  12313. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12314. {
  12315. check_ascii = value[0];
  12316. if( (check_ascii < 48) || (check_ascii > 57) )
  12317. {
  12318. isSuccess = ConfigurationStatus_Rejected;
  12319. }
  12320. else
  12321. {
  12322. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12323. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12324. TransactionMessageAttemptsValue = atoi(value);
  12325. isSuccess = ConfigurationStatus_Accepted;
  12326. }
  12327. }
  12328. else
  12329. {
  12330. isSuccess = ConfigurationStatus_Rejected;
  12331. }
  12332. }
  12333. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12334. {
  12335. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12336. {
  12337. check_ascii = value[0];
  12338. if( (check_ascii < 48) || (check_ascii > 57) )
  12339. {
  12340. isSuccess = ConfigurationStatus_Rejected;
  12341. }
  12342. else
  12343. {
  12344. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12345. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12346. TransactionMessageRetryIntervalValue = atoi(value);
  12347. isSuccess = ConfigurationStatus_Accepted;
  12348. }
  12349. }
  12350. else
  12351. {
  12352. isSuccess = ConfigurationStatus_Rejected;
  12353. }
  12354. }
  12355. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12356. {
  12357. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12358. {
  12359. strcpy(str, (const char*)value);
  12360. for(int i = 0; str[i]; i++)
  12361. {
  12362. str[i] = tolower(str[i]);
  12363. }
  12364. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12365. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12366. isSuccess = ConfigurationStatus_Accepted;
  12367. }
  12368. else
  12369. {
  12370. isSuccess = ConfigurationStatus_Rejected;
  12371. }
  12372. }
  12373. if(strcmp(key, "WebSocketPingInterval") == 0)
  12374. {
  12375. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12376. {
  12377. check_ascii = value[0];
  12378. if( (check_ascii < 48) || (check_ascii > 57) )
  12379. {
  12380. isSuccess = ConfigurationStatus_Rejected;
  12381. }
  12382. else
  12383. {
  12384. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12385. isSuccess = ConfigurationStatus_Accepted;
  12386. }
  12387. }
  12388. else
  12389. {
  12390. isSuccess = ConfigurationStatus_Rejected;
  12391. }
  12392. }
  12393. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  12394. {
  12395. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12396. {
  12397. strcpy(str, (const char*)value);
  12398. for(int i = 0; str[i]; i++)
  12399. {
  12400. str[i] = tolower(str[i]);
  12401. }
  12402. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12403. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12404. isSuccess = ConfigurationStatus_Accepted;
  12405. }
  12406. else
  12407. {
  12408. isSuccess = ConfigurationStatus_Rejected;
  12409. }
  12410. }
  12411. #if 0
  12412. //For OCPP Test Case
  12413. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12414. {
  12415. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12416. {
  12417. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12418. isSuccess = ConfigurationStatus_Accepted;
  12419. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12420. }
  12421. else
  12422. {
  12423. isSuccess = ConfigurationStatus_Rejected;
  12424. }
  12425. }
  12426. #endif
  12427. #if 1
  12428. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12429. {
  12430. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12431. {
  12432. strcpy(str, (const char*)value);
  12433. for(int i = 0; str[i]; i++)
  12434. {
  12435. str[i] = tolower(str[i]);
  12436. }
  12437. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12438. isSuccess = ConfigurationStatus_Accepted;
  12439. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12440. }
  12441. else
  12442. {
  12443. isSuccess = ConfigurationStatus_Rejected;
  12444. }
  12445. }
  12446. #endif
  12447. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12448. {
  12449. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12450. {
  12451. check_ascii = value[0];
  12452. if( (check_ascii < 48) || (check_ascii > 57) )
  12453. {
  12454. isSuccess = ConfigurationStatus_Rejected;
  12455. }
  12456. else
  12457. {
  12458. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12459. isSuccess = ConfigurationStatus_Accepted;
  12460. }
  12461. }
  12462. else
  12463. {
  12464. isSuccess = ConfigurationStatus_Rejected;
  12465. }
  12466. }
  12467. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12468. {
  12469. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12470. {
  12471. check_ascii = value[0];
  12472. if( (check_ascii < 48) || (check_ascii > 57) )
  12473. {
  12474. isSuccess = ConfigurationStatus_Rejected;
  12475. }
  12476. else
  12477. {
  12478. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12479. isSuccess = ConfigurationStatus_Accepted;
  12480. }
  12481. }
  12482. else
  12483. {
  12484. isSuccess = ConfigurationStatus_Rejected;
  12485. }
  12486. }
  12487. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12488. {
  12489. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12490. {
  12491. strcpy(str, (const char*)value);
  12492. for(int i = 0; str[i]; i++)
  12493. {
  12494. str[i] = tolower(str[i]);
  12495. }
  12496. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12497. isSuccess = ConfigurationStatus_Accepted;
  12498. }
  12499. else
  12500. {
  12501. isSuccess = ConfigurationStatus_Rejected;
  12502. }
  12503. }
  12504. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12505. {
  12506. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12507. {
  12508. check_ascii = value[0];
  12509. if( (check_ascii < 48) || (check_ascii > 57) )
  12510. {
  12511. isSuccess = ConfigurationStatus_Rejected;
  12512. }
  12513. else
  12514. {
  12515. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12516. isSuccess = ConfigurationStatus_Accepted;
  12517. }
  12518. }
  12519. else
  12520. {
  12521. isSuccess = ConfigurationStatus_Rejected;
  12522. }
  12523. }
  12524. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12525. {
  12526. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12527. {
  12528. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12529. isSuccess = ConfigurationStatus_Accepted;
  12530. }
  12531. else
  12532. {
  12533. isSuccess = ConfigurationStatus_Rejected;
  12534. }
  12535. }
  12536. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12537. {
  12538. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12539. {
  12540. check_ascii = value[0];
  12541. if( (check_ascii < 48) || (check_ascii > 57) )
  12542. {
  12543. isSuccess = ConfigurationStatus_Rejected;
  12544. }
  12545. else
  12546. {
  12547. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12548. isSuccess = ConfigurationStatus_Accepted;
  12549. }
  12550. }
  12551. else
  12552. {
  12553. isSuccess = ConfigurationStatus_Rejected;
  12554. }
  12555. }
  12556. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12557. {
  12558. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12559. {
  12560. strcpy(str, (const char*)value);
  12561. for(int i = 0; str[i]; i++)
  12562. {
  12563. str[i] = tolower(str[i]);
  12564. }
  12565. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12566. isSuccess = ConfigurationStatus_Accepted;
  12567. }
  12568. else
  12569. {
  12570. isSuccess = ConfigurationStatus_Rejected;
  12571. }
  12572. }
  12573. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12574. {
  12575. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12576. {
  12577. check_ascii = value[0];
  12578. if( (check_ascii < 48) || (check_ascii > 57) )
  12579. {
  12580. isSuccess = ConfigurationStatus_Rejected;
  12581. }
  12582. else
  12583. {
  12584. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12585. isSuccess = ConfigurationStatus_Accepted;
  12586. }
  12587. }
  12588. else
  12589. {
  12590. isSuccess = ConfigurationStatus_Rejected;
  12591. }
  12592. }
  12593. return isSuccess;
  12594. }
  12595. int TransactionMessageAttemptsGet(void)
  12596. {
  12597. return TransactionMessageAttemptsValue;
  12598. }
  12599. int FirstHeartBeatResponse(void)
  12600. {
  12601. return FirstHeartBeat;
  12602. }
  12603. int TransactionMessageRetryIntervalGet(void)
  12604. {
  12605. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12606. }
  12607. int ReadHttpStatus(int sock)
  12608. {
  12609. //char c;
  12610. char buff[1024]="",*ptr=buff+1;
  12611. int bytes_received, status;
  12612. DEBUG_INFO("Begin Response ..\n");
  12613. while((bytes_received = recv(sock, ptr, 1, 0))){
  12614. if(bytes_received==-1){
  12615. perror("ReadHttpStatus");
  12616. exit(1);
  12617. }
  12618. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12619. ptr++;
  12620. }
  12621. *ptr=0;
  12622. ptr=buff+1;
  12623. sscanf(ptr,"%*s %d ", &status);
  12624. DEBUG_INFO("%s\n",ptr);
  12625. DEBUG_INFO("status=%d\n",status);
  12626. DEBUG_INFO("End Response ..\n");
  12627. return (bytes_received>0)?status:0;
  12628. }
  12629. //the only filed that it parsed is 'Content-Length'
  12630. int ParseHeader(int sock)
  12631. {
  12632. //char c;
  12633. char buff[1024]="",*ptr=buff+4;
  12634. int bytes_received;
  12635. DEBUG_INFO("Begin HEADER ..\n");
  12636. while((bytes_received = recv(sock, ptr, 1, 0))){
  12637. if(bytes_received==-1){
  12638. perror("Parse Header");
  12639. exit(1);
  12640. }
  12641. if(
  12642. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12643. (ptr[-1]=='\r') && (*ptr=='\n' )
  12644. ) break;
  12645. ptr++;
  12646. }
  12647. *ptr=0;
  12648. ptr=buff+4;
  12649. //printf("%s",ptr);
  12650. if(bytes_received){
  12651. ptr=strstr(ptr,"Content-Length:");
  12652. if(ptr){
  12653. sscanf(ptr,"%*s %d",&bytes_received);
  12654. }else
  12655. bytes_received=-1; //unknown size
  12656. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12657. }
  12658. DEBUG_INFO("End HEADER ..\n");
  12659. return bytes_received ;
  12660. }
  12661. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12662. {
  12663. char rmFileCmd[100]={0};
  12664. char FilePath[100]={0};
  12665. char ftpbuf[200];
  12666. int systemresult;
  12667. //DEBUG_INFO("filename=%s\n",filename);
  12668. //DEBUG_INFO("url=%s\n",url);
  12669. sprintf(FilePath,"/mnt/%s",filename);
  12670. if((access(FilePath,F_OK))!=-1)
  12671. {
  12672. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12673. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12674. system(rmFileCmd);
  12675. }
  12676. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12677. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12678. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12679. systemresult = system(ftpbuf);
  12680. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12681. if(systemresult != 0)
  12682. {
  12683. DEBUG_INFO("http DownLoad error!\n");
  12684. return FALSE;
  12685. }
  12686. return TRUE;
  12687. }
  12688. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12689. {
  12690. char rmFileCmd[100]={0};
  12691. char FilePath[100]={0};
  12692. char ftpbuf[200];
  12693. int systemresult;
  12694. //char temp[100];
  12695. sprintf(FilePath,"/mnt/%s",filename);
  12696. if((access(FilePath,F_OK))!=-1)
  12697. {
  12698. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12699. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12700. system(rmFileCmd);
  12701. }
  12702. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12703. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12704. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12705. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12706. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12707. systemresult = system(ftpbuf);
  12708. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12709. if(systemresult != 0)
  12710. {
  12711. printf("wget error!\n");
  12712. return FALSE;
  12713. }
  12714. return TRUE;
  12715. }
  12716. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12717. {
  12718. char rmFileCmd[100]={0};
  12719. char FilePath[100]={0};
  12720. char ftpbuf[200];
  12721. int systemresult;
  12722. //DEBUG_INFO("filename=%s\n",filename);
  12723. //DEBUG_INFO("url=%s\n",url);
  12724. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12725. if((access(FilePath,F_OK))!=-1)
  12726. {
  12727. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12728. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12729. system(rmFileCmd);
  12730. }
  12731. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12732. if(fp == NULL)
  12733. {
  12734. DEBUG_INFO("log is NULL\n");
  12735. return FALSE;
  12736. }
  12737. else
  12738. {
  12739. fprintf(fp, "%s\n", url);
  12740. fprintf(fp, "%s\n", filename);
  12741. fclose(fp);
  12742. }
  12743. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12744. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12745. systemresult = system(ftpbuf);
  12746. DEBUG_INFO("systemresult = %d\n",systemresult);
  12747. if(systemresult != 0)
  12748. {
  12749. DEBUG_INFO("http upload error!\n");
  12750. return FALSE;
  12751. }
  12752. return TRUE;
  12753. }
  12754. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12755. {
  12756. struct hostent* server;
  12757. char *IPbuffer;
  12758. char ftpbuf[200];
  12759. int systemresult;
  12760. // To retrieve host information
  12761. server = gethostbyname(location);
  12762. // To convert an Internet network
  12763. // address into ASCII string
  12764. IPbuffer = inet_ntoa(*((struct in_addr*)
  12765. server->h_addr_list[0]));
  12766. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12767. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12768. /* format : ftpput -u username -p passwd IP target source*/
  12769. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12770. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12771. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12772. systemresult = system(ftpbuf);
  12773. DEBUG_INFO("systemresult=%d\n",systemresult);
  12774. if(systemresult != 0)
  12775. {
  12776. DEBUG_INFO("ftpput error!\n");
  12777. return FALSE;
  12778. }
  12779. return TRUE;
  12780. }
  12781. /**
  12782. * Place the contents of the specified file into a memory buffer
  12783. *
  12784. * @param[in] filename The path and name of the file to read
  12785. * @param[out] filebuffer A pointer to the contents in memory
  12786. * @return status 0 success, 1 on failure
  12787. */
  12788. int get_file_contents(const char* filename, char** outbuffer) {
  12789. FILE* file = NULL;
  12790. long filesize;
  12791. const int blocksize = 1;
  12792. size_t readsize;
  12793. char* filebuffer;
  12794. // Open the file
  12795. file = fopen(filename, "r");
  12796. if (NULL == file)
  12797. {
  12798. printf("'%s' not opened\n", filename);
  12799. exit(EXIT_FAILURE);
  12800. }
  12801. // Determine the file size
  12802. fseek(file, 0, SEEK_END);
  12803. filesize = ftell(file);
  12804. rewind (file);
  12805. // Allocate memory for the file contents
  12806. filebuffer = (char*) malloc(sizeof(char) * filesize);
  12807. *outbuffer = filebuffer;
  12808. if (filebuffer == NULL)
  12809. {
  12810. fputs ("malloc out-of-memory", stderr);
  12811. exit(EXIT_FAILURE);
  12812. }
  12813. // Read in the file
  12814. readsize = fread(filebuffer, blocksize, filesize, file);
  12815. if (readsize != filesize)
  12816. {
  12817. fputs ("didn't read file completely",stderr);
  12818. exit(EXIT_FAILURE);
  12819. }
  12820. // Clean exit
  12821. fclose(file);
  12822. return EXIT_SUCCESS;
  12823. }
  12824. static int selectSqlCount = 0;
  12825. static int callback(void *data, int argc, char **argv, char **azColName){
  12826. int i;
  12827. //printf("%s: ", (const char*)data);
  12828. selectSqlCount = argc;
  12829. for(i = 0; i<argc; i++){
  12830. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  12831. }
  12832. //printf("\n");
  12833. return 0;
  12834. }
  12835. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  12836. //int i;
  12837. //printf("%s:\n", (const char*)data);
  12838. localversion = argv[5] ? atoi(argv[5]) : 0;
  12839. //printf("localversion=%d\n", localversion);
  12840. return 0;
  12841. }
  12842. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  12843. //int i;
  12844. //printf("%s:\n", (const char*)data);
  12845. //idTag
  12846. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  12847. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  12848. //parentIdTag
  12849. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  12850. //expir_date
  12851. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  12852. //status
  12853. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  12854. //version
  12855. idTagQuery.listVersionInt = atoi(argv[5]);
  12856. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  12857. return 0;
  12858. }
  12859. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  12860. {
  12861. // localversion = argv[5] ? atoi(argv[5]) : 0;
  12862. // printf("localversion=%d\n", localversion);
  12863. return 0;
  12864. }
  12865. //=========================================
  12866. // Sqlite3 related function
  12867. //=========================================
  12868. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  12869. {
  12870. for (int i = 0; i < n_columns; i++)
  12871. {
  12872. DEBUG_INFO("%s/t", col_values[i]);
  12873. }
  12874. DEBUG_INFO("/n");
  12875. return 0;
  12876. }
  12877. void OCPP_getListVerion()
  12878. {
  12879. int rc = 0;
  12880. // const char* data = "Callback function called";
  12881. char sql[100];
  12882. char zErrMsg[100];
  12883. memset(sql, 0, 100);
  12884. memset(zErrMsg, 0, 100);
  12885. strcpy(sql, "select * from ocpp_auth_local order by idx");
  12886. /* Execute SQL statement */
  12887. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  12888. if( rc != SQLITE_OK )
  12889. {
  12890. DEBUG_INFO("SQL error: %s", zErrMsg);
  12891. }
  12892. }
  12893. void OCPP_getIdTag(char idTag[])
  12894. {
  12895. int rc = 0;
  12896. // const char* data = "Callback function called";
  12897. char sql[100];
  12898. char zErrMsg[100];
  12899. memset(sql, 0, 100);
  12900. memset(zErrMsg, 0, 100);
  12901. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  12902. memset(&idTagQuery, 0, sizeof(idTagQuery));
  12903. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  12904. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12905. /* Execute SQL statement */
  12906. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  12907. if( rc != SQLITE_OK )
  12908. {
  12909. DEBUG_INFO("SQL error: %s", zErrMsg);
  12910. }
  12911. //return ver;
  12912. }
  12913. void OCPP_get_TableAuthlocalAllData(void)
  12914. {
  12915. int rc = 0;
  12916. char sql[100];
  12917. char zErrMsg[100];
  12918. memset(sql, 0, 100);
  12919. memset(zErrMsg, 0, 100);
  12920. sprintf(sql,"select * from ocpp_auth_local ");
  12921. /* Execute SQL statement */
  12922. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  12923. if( rc != SQLITE_OK )
  12924. {
  12925. DEBUG_INFO("SQL error: %s", zErrMsg);
  12926. }
  12927. //return ver;
  12928. }
  12929. int OCPP_cleanLocalList()
  12930. {
  12931. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  12932. char *errMsg = 0;
  12933. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  12934. if (SQLITE_OK != rc)
  12935. {
  12936. DEBUG_INFO("%s\n",errMsg);
  12937. return FALSE;
  12938. }
  12939. return TRUE;
  12940. }
  12941. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12942. {
  12943. int isSuccess = FALSE;
  12944. int ret = 0;
  12945. //const char* data = "Callback function called";
  12946. char sql[300];
  12947. char zErrMsg[200];
  12948. memset(sql, 0, 300);
  12949. memset(zErrMsg, 0, 200);
  12950. 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);
  12951. //* Execute SQL statement */
  12952. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  12953. if( ret != SQLITE_OK )
  12954. {
  12955. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12956. return isSuccess;
  12957. }
  12958. memset(sql, 0, 300);
  12959. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  12960. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  12961. if( ret != SQLITE_OK )
  12962. {
  12963. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12964. return isSuccess;
  12965. }
  12966. isSuccess = TRUE;
  12967. return isSuccess;
  12968. }
  12969. void OCPP_deleteIdTag(char idTag[])
  12970. {
  12971. //int ver = 0;
  12972. //int isSuccess = FALSE;
  12973. int rc = 0;
  12974. char sql[100];
  12975. char zErrMsg[100];
  12976. memset(sql, 0, 100);
  12977. memset(zErrMsg, 0, 100);
  12978. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  12979. //* Execute SQL statement */
  12980. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  12981. if( rc != SQLITE_OK )
  12982. {
  12983. DEBUG_INFO("SQL error: %s", zErrMsg);
  12984. }
  12985. }
  12986. int GetOcppServerURL()
  12987. {
  12988. int result = FALSE;
  12989. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  12990. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  12991. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  12992. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  12993. {
  12994. #if 1
  12995. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  12996. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12997. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12998. #endif
  12999. result = TRUE;
  13000. goto End;
  13001. }
  13002. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  13003. {
  13004. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  13005. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13006. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  13007. result = TRUE;
  13008. goto End;
  13009. }
  13010. else
  13011. {
  13012. strcpy(OcppHost,"");
  13013. }
  13014. End:
  13015. return result;
  13016. }
  13017. int GetOcppPath()
  13018. {
  13019. int result = FALSE;
  13020. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  13021. {
  13022. if(OcppTempPath == NULL)
  13023. {
  13024. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13025. }
  13026. else
  13027. {
  13028. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13029. }
  13030. result = TRUE;
  13031. goto End;
  13032. }
  13033. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  13034. {
  13035. if(OcppTempPath == NULL)
  13036. {
  13037. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  13038. }
  13039. else
  13040. {
  13041. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  13042. }
  13043. result = TRUE;
  13044. goto End;
  13045. }
  13046. else
  13047. {
  13048. strcpy(OcppPath,"");
  13049. }
  13050. End:
  13051. return result;
  13052. }
  13053. int GetOcppPort()
  13054. {
  13055. return OcppPort;
  13056. }
  13057. int GetOcppConnStatus(void)
  13058. {
  13059. return ShmOCPP16Data->OcppConnStatus;
  13060. }
  13061. void SetOcppConnStatus(uint8_t status)
  13062. {
  13063. ShmOCPP16Data->OcppConnStatus = status;
  13064. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  13065. }
  13066. int GetHeartBeatWithNOResponse(void)
  13067. {
  13068. return HeartBeatWithNOResponse;
  13069. }
  13070. void SetHeartBeatWithNOResponse(void)
  13071. {
  13072. HeartBeatWithNOResponse = 0;
  13073. }
  13074. void GetStartTransactionIdTag(int gun_index)
  13075. {
  13076. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  13077. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13078. }
  13079. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  13080. {
  13081. char ch;
  13082. FILE *fptr1;
  13083. int temptransactionId;
  13084. char str[100]={0};
  13085. temptransactionId = 0;
  13086. if((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0'))
  13087. {
  13088. DEBUG_INFO("IdTag is empty.\n");
  13089. return temptransactionId;
  13090. }
  13091. /*------ Read the file ----------------*/
  13092. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  13093. if (!fptr1)
  13094. {
  13095. DEBUG_INFO("QueueTransactionId file open error.\n");
  13096. //printf(" File not found or unable to open the input file!!\n");
  13097. return temptransactionId;
  13098. }
  13099. ch=fgetc(fptr1);
  13100. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13101. rewind(fptr1);
  13102. if(ch!=EOF)
  13103. {
  13104. // printf("%c",ch);
  13105. while (fgets(str, 100, fptr1) != NULL)
  13106. {
  13107. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13108. if(str[0]=='\0')
  13109. {
  13110. break;
  13111. }
  13112. char *revbuf[8] = {0}; //存放分割後的子字串
  13113. int num = 0;//分割後子字串的個數
  13114. DEBUG_INFO("str: %s\n", str);
  13115. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  13116. DEBUG_INFO("revbuf[0]: %s\n", revbuf[0]);
  13117. DEBUG_INFO("revbuf[1]: %s\n", revbuf[1]);
  13118. DEBUG_INFO("revbuf[2]: %s\n", revbuf[2]);
  13119. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13120. {
  13121. if(isStopTransaction)
  13122. {
  13123. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  13124. {
  13125. temptransactionId = atoi(revbuf[2]);
  13126. break;
  13127. }
  13128. }
  13129. else
  13130. {
  13131. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13132. {
  13133. temptransactionId = atoi(revbuf[2]);
  13134. break;
  13135. }
  13136. }
  13137. }
  13138. }
  13139. }
  13140. else
  13141. DEBUG_INFO("EOF\n");
  13142. fclose(fptr1);
  13143. /*------- End of reading ---------------*/
  13144. return temptransactionId;
  13145. }
  13146. void SetTransactionIdZero(int transactionId)
  13147. {
  13148. char ch;
  13149. FILE *fptr1, *fptr2;
  13150. int temptransactionId = 0;
  13151. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13152. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13153. if (!fptr1)
  13154. {
  13155. //printf(" File not found or unable to open the input file!!\n");
  13156. return ;
  13157. }
  13158. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13159. if (!fptr2)
  13160. {
  13161. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  13162. fclose(fptr1);
  13163. return ;
  13164. }
  13165. ch=fgetc(fptr1);
  13166. rewind(fptr1);
  13167. if(ch!=EOF)
  13168. {
  13169. // copy all contents to the temporary file except the specific line
  13170. while (fgets(str, 100, fptr1) != NULL)
  13171. {
  13172. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13173. if(str[0]=='\0')
  13174. {
  13175. break;
  13176. }
  13177. char *revbuf[8] = {0};
  13178. int num = 0;
  13179. strcpy(strtemp, str);
  13180. splitstring(str,",",revbuf,&num);
  13181. if(revbuf[2][0] != '\0')
  13182. {
  13183. temptransactionId = atoi(revbuf[2]);
  13184. if(transactionId != temptransactionId)
  13185. {
  13186. fprintf(fptr2, "%s\n", strtemp);
  13187. }
  13188. }
  13189. }
  13190. }
  13191. fclose(fptr1);
  13192. fclose(fptr2);
  13193. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13194. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13195. /*------ Read the file ----------------*/
  13196. }
  13197. int InternetDisconnect(void)
  13198. {
  13199. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13200. }
  13201. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  13202. void storeTempStopTransaction(int gun_index)
  13203. {
  13204. char guid[37]={0};
  13205. int tempIndex = 0;
  13206. DEBUG_INFO("storeTempStopTransaction...\n");
  13207. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  13208. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  13209. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13210. if(gunType[gun_index] == 'J')
  13211. {
  13212. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13213. {
  13214. tempIndex = ((gun_index==2) ? 1: 0);
  13215. }
  13216. else
  13217. {
  13218. tempIndex = gun_index;
  13219. }
  13220. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13221. {
  13222. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13223. {
  13224. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  13225. }
  13226. }// END OF CHAdeMO_QUANTITY
  13227. }
  13228. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13229. {
  13230. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13231. {
  13232. tempIndex = ((gun_index==2) ? 1: 0);
  13233. }
  13234. else
  13235. {
  13236. tempIndex = gun_index;
  13237. }
  13238. for (int index = 0; index < CCS_QUANTITY; index++)
  13239. {
  13240. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13241. {
  13242. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  13243. }
  13244. }// END OF CCS_QUANTITY
  13245. }
  13246. else if(gunType[gun_index] == 'G')
  13247. {
  13248. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13249. {
  13250. tempIndex = ((gun_index==2) ? 1: 0);
  13251. }
  13252. else
  13253. {
  13254. tempIndex = gun_index;
  13255. }
  13256. for (int index = 0; index < GB_QUANTITY; index++)
  13257. {
  13258. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13259. {
  13260. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  13261. }
  13262. }// END OF GB_QUANTITY
  13263. }
  13264. else
  13265. {
  13266. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13267. {
  13268. tempIndex = 2;
  13269. }
  13270. else
  13271. {
  13272. tempIndex = gun_index;
  13273. }
  13274. for (int index = 0; index < AC_QUANTITY; index++)
  13275. {
  13276. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13277. {
  13278. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  13279. }
  13280. }// END OF AC_QUANTITY
  13281. }
  13282. //Stop Transaction Time
  13283. struct timeval tmnow;
  13284. struct tm *tm;
  13285. char buf[28];//, usec_buf[6];
  13286. gettimeofday(&tmnow, NULL);
  13287. time_t t;
  13288. t = time(NULL);
  13289. /*UTC time and date*/
  13290. tm = gmtime(&t);
  13291. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  13292. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  13293. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  13294. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13295. random_uuid(guid);
  13296. /***********************************transactionData******************************************************/
  13297. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  13298. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  13299. //=================================
  13300. //1. Transaction_Begin
  13301. //=================================
  13302. //============================== Energy.Active.Import.Interval ===========================================
  13303. //idx_sample=0;
  13304. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  13305. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  13306. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  13307. 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*/]);
  13308. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13309. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13310. {
  13311. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  13312. }
  13313. else
  13314. {
  13315. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  13316. }
  13317. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  13318. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13319. //=================================
  13320. //2. Transaction_End
  13321. //=================================
  13322. //2.1====================================== Current.Import L1 ==============================================
  13323. //idx_sample=1;
  13324. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  13325. if(gunType[gun_index] == 'J')
  13326. {
  13327. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13328. {
  13329. tempIndex = ((gun_index==2) ? 1: 0);
  13330. }
  13331. else
  13332. {
  13333. tempIndex = gun_index;
  13334. }
  13335. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13336. {
  13337. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13338. {
  13339. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13340. }
  13341. }// End of for CHAdeMO_QUANTITY
  13342. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13343. }
  13344. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13345. {
  13346. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13347. {
  13348. tempIndex = ((gun_index==2) ? 1: 0);
  13349. }
  13350. else
  13351. {
  13352. tempIndex = gun_index;
  13353. }
  13354. for (int index = 0; index < CCS_QUANTITY; index++)
  13355. {
  13356. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13357. {
  13358. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13359. }
  13360. }// End of for CCS_QUANTITY
  13361. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13362. }
  13363. else if(gunType[gun_index] == 'G')
  13364. {
  13365. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13366. {
  13367. tempIndex = ((gun_index==2) ? 1: 0);
  13368. }
  13369. else
  13370. {
  13371. tempIndex = gun_index;
  13372. }
  13373. for (int index = 0; index < GB_QUANTITY; index++)
  13374. {
  13375. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13376. {
  13377. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13378. }
  13379. }// End of for GB_QUANTITY
  13380. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13381. }
  13382. else
  13383. {
  13384. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13385. {
  13386. tempIndex = 2;
  13387. }
  13388. else
  13389. {
  13390. tempIndex = gun_index;
  13391. }
  13392. for (int index = 0; index < AC_QUANTITY; index++)
  13393. {
  13394. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13395. {
  13396. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  13397. }
  13398. }// End of for AC_QUANTITY
  13399. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13400. }
  13401. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13402. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  13403. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  13404. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13405. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  13406. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13407. //2.2===================================== Energy.Active.Import.Interval ==========================================
  13408. //idx_sample=2;
  13409. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13410. if(gunType[gun_index] == 'J')
  13411. {
  13412. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13413. {
  13414. tempIndex = ((gun_index==2) ? 1: 0);
  13415. }
  13416. else
  13417. {
  13418. tempIndex = gun_index;
  13419. }
  13420. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13421. {
  13422. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13423. {
  13424. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13425. }
  13426. }// END OF CHAdeMO_QUANTITY
  13427. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13428. }
  13429. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13430. {
  13431. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13432. {
  13433. tempIndex = ((gun_index==2) ? 1: 0);
  13434. }
  13435. else
  13436. {
  13437. tempIndex = gun_index;
  13438. }
  13439. for (int index = 0; index < CCS_QUANTITY; index++)
  13440. {
  13441. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13442. {
  13443. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13444. }
  13445. }// END OF CCS_QUANTITY
  13446. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13447. }
  13448. else if(gunType[gun_index] == 'G')
  13449. {
  13450. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13451. {
  13452. tempIndex = ((gun_index==2) ? 1: 0);
  13453. }
  13454. else
  13455. {
  13456. tempIndex = gun_index;
  13457. }
  13458. for (int index = 0; index < GB_QUANTITY; index++)
  13459. {
  13460. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13461. {
  13462. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13463. }
  13464. }// END OF GB_QUANTITY
  13465. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13466. }
  13467. else
  13468. {
  13469. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13470. {
  13471. tempIndex = 2;
  13472. }
  13473. else
  13474. {
  13475. tempIndex = gun_index;
  13476. }
  13477. for (int index = 0; index < AC_QUANTITY; index++)
  13478. {
  13479. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13480. {
  13481. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13482. }
  13483. }// END OF AC_QUANTITY
  13484. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13485. }
  13486. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13487. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  13488. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  13489. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13490. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  13491. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13492. //2.3====================================== Power.Active.Import =========================================
  13493. //idx_sample=3;
  13494. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13495. if(gunType[gun_index] == 'J')
  13496. {
  13497. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13498. {
  13499. tempIndex = ((gun_index==2) ? 1: 0);
  13500. }
  13501. else
  13502. {
  13503. tempIndex = gun_index;
  13504. }
  13505. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13506. {
  13507. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13508. {
  13509. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13510. }
  13511. } // End for CHAdeMO_QUANTITY
  13512. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13513. }
  13514. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13515. {
  13516. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13517. {
  13518. tempIndex = ((gun_index==2) ? 1: 0);
  13519. }
  13520. else
  13521. {
  13522. tempIndex = gun_index;
  13523. }
  13524. for (int index = 0; index < CCS_QUANTITY; index++)
  13525. {
  13526. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13527. {
  13528. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13529. }
  13530. } // END for CCS_QUANTITY
  13531. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13532. }
  13533. else if(gunType[gun_index] == 'G')
  13534. {
  13535. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13536. {
  13537. tempIndex = ((gun_index==2) ? 1: 0);
  13538. }
  13539. else
  13540. {
  13541. tempIndex = gun_index;
  13542. }
  13543. for (int index = 0; index < GB_QUANTITY; index++)
  13544. {
  13545. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13546. {
  13547. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13548. }
  13549. }// END for GB_QUANTITY
  13550. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13551. }
  13552. else
  13553. {
  13554. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13555. {
  13556. tempIndex = 2;
  13557. }
  13558. else
  13559. {
  13560. tempIndex = gun_index;
  13561. }
  13562. for (int index = 0; index < AC_QUANTITY; index++)
  13563. {
  13564. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13565. {
  13566. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13567. }
  13568. } // END for AC_QUANTITY
  13569. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13570. }
  13571. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13572. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  13573. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  13574. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13575. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  13576. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  13577. //2.4====================================== Voltage L1 ====================================================
  13578. //idx_sample=4;
  13579. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13580. if(gunType[gun_index] == 'J')
  13581. {
  13582. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13583. {
  13584. tempIndex = ((gun_index==2) ? 1: 0);
  13585. }
  13586. else
  13587. {
  13588. tempIndex = gun_index;
  13589. }
  13590. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13591. {
  13592. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13593. {
  13594. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13595. }
  13596. } // END OF FOR CHAdeMO_QUANTITY
  13597. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13598. }
  13599. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13600. {
  13601. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13602. {
  13603. tempIndex = ((gun_index==2) ? 1: 0);
  13604. }
  13605. else
  13606. {
  13607. tempIndex = gun_index;
  13608. }
  13609. for (int index = 0; index < CCS_QUANTITY; index++)
  13610. {
  13611. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13612. {
  13613. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13614. }
  13615. } // END OF FOR CCS_QUANTITY
  13616. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13617. }
  13618. else if(gunType[gun_index] == 'G')
  13619. {
  13620. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13621. {
  13622. tempIndex = ((gun_index==2) ? 1: 0);
  13623. }
  13624. else
  13625. {
  13626. tempIndex = gun_index;
  13627. }
  13628. for (int index = 0; index < GB_QUANTITY; index++)
  13629. {
  13630. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13631. {
  13632. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13633. }
  13634. } // END OF FOR GB_QUANTITY
  13635. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13636. }
  13637. else
  13638. {
  13639. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13640. {
  13641. tempIndex = 2;
  13642. }
  13643. else
  13644. {
  13645. tempIndex = gun_index;
  13646. }
  13647. for (int index = 0; index < AC_QUANTITY; index++)
  13648. {
  13649. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13650. {
  13651. 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
  13652. }
  13653. } // END OF FOR AC_QUANTITY
  13654. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13655. }
  13656. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13657. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  13658. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  13659. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13660. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  13661. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13662. //2.5============================================== SoC =========================================================
  13663. //idx_sample=5;
  13664. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13665. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13666. {
  13667. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13668. {
  13669. tempIndex = ((gun_index==2) ? 1: 0);
  13670. }
  13671. else
  13672. {
  13673. tempIndex = gun_index;
  13674. }
  13675. if(gunType[gun_index] == 'J')
  13676. {
  13677. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13678. {
  13679. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13680. {
  13681. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  13682. }
  13683. }
  13684. }
  13685. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13686. {
  13687. for (int index = 0; index < CCS_QUANTITY; index++)
  13688. {
  13689. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13690. {
  13691. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  13692. }
  13693. }
  13694. }
  13695. else if(gunType[gun_index] == 'G')
  13696. {
  13697. for (int index = 0; index < GB_QUANTITY; index++)
  13698. {
  13699. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13700. {
  13701. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  13702. }
  13703. }
  13704. }
  13705. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13706. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  13707. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  13708. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  13709. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  13710. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  13711. } // END FOR DC CASE
  13712. //2.6====================================== Current.Import L2 ==============================================
  13713. // idx_sample=6;
  13714. // AC 3 phase L2 current
  13715. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13716. {
  13717. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13718. {
  13719. tempIndex = 2;
  13720. }
  13721. else
  13722. {
  13723. tempIndex = gun_index;
  13724. }
  13725. for (int index = 0; index < AC_QUANTITY; index++)
  13726. {
  13727. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13728. {
  13729. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  13730. }
  13731. }// End of for AC_QUANTITY
  13732. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  13733. }
  13734. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13735. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  13736. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  13737. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  13738. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13739. //2.7====================================== Current.Import L3 ==============================================
  13740. // idx_sample=7;
  13741. // AC 3 phase L3 current
  13742. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13743. {
  13744. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13745. {
  13746. tempIndex = 2;
  13747. }
  13748. else
  13749. {
  13750. tempIndex = gun_index;
  13751. }
  13752. for (int index = 0; index < AC_QUANTITY; index++)
  13753. {
  13754. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13755. {
  13756. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  13757. }
  13758. }// End of for AC_QUANTITY
  13759. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  13760. }
  13761. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13762. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  13763. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  13764. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  13765. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13766. //2.9====================================== Voltage L2 ====================================================
  13767. //idx_sample=8;
  13768. // AC 3 phase L2 volatge
  13769. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13770. {
  13771. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13772. {
  13773. tempIndex = 2;
  13774. }
  13775. else
  13776. {
  13777. tempIndex = gun_index;
  13778. }
  13779. for (int index = 0; index < AC_QUANTITY; index++)
  13780. {
  13781. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13782. {
  13783. 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
  13784. }
  13785. } // END OF FOR AC_QUANTITY
  13786. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  13787. }
  13788. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13789. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  13790. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  13791. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  13792. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13793. //2.10====================================== Voltage L3 ====================================================
  13794. //idx_sample=9;
  13795. // AC 3 phase L3 volatge
  13796. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13797. {
  13798. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13799. {
  13800. tempIndex = 2;
  13801. }
  13802. else
  13803. {
  13804. tempIndex = gun_index;
  13805. }
  13806. for (int index = 0; index < AC_QUANTITY; index++)
  13807. {
  13808. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13809. {
  13810. 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
  13811. }
  13812. } // END OF FOR AC_QUANTITY
  13813. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  13814. }
  13815. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13816. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  13817. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  13818. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  13819. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13820. //======================================== Message create ==============================================
  13821. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13822. {
  13823. sprintf(queuedata,"%d,[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  13824. ,gun_index+1
  13825. ,MESSAGE_TYPE_CALL
  13826. ,guid
  13827. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13828. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13829. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13830. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13831. ,"PowerLoss"
  13832. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13833. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13834. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13835. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13836. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13837. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13838. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13839. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13840. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13841. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13842. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13843. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13844. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13845. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13846. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13847. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13848. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13849. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13850. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13851. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13852. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13853. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13854. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13855. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13856. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13857. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13858. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13859. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13860. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13861. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13862. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13863. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13864. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13865. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13866. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13867. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13868. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  13869. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  13870. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  13871. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  13872. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  13873. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  13874. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  13875. );
  13876. }
  13877. else
  13878. {
  13879. if(((ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'W')))
  13880. {
  13881. sprintf(queuedata,"%d,[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  13882. ,gun_index+1
  13883. ,MESSAGE_TYPE_CALL
  13884. ,guid
  13885. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13886. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13887. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13888. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13889. ,"PowerLoss"
  13890. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13891. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13892. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13893. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13894. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13895. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13896. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13897. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13898. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13899. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13900. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13901. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13902. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13903. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13904. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13905. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13906. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13907. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13908. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13909. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13910. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13911. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13912. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13913. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13914. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13915. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13916. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13917. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13918. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13919. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13920. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13921. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13922. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13923. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13924. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13925. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13926. );
  13927. }
  13928. else
  13929. {
  13930. sprintf(queuedata,"%d,[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  13931. ,gun_index+1
  13932. ,MESSAGE_TYPE_CALL
  13933. ,guid
  13934. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13935. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13936. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13937. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13938. ,"PowerLoss"
  13939. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13940. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13941. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13942. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13943. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13944. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13945. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13946. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13947. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13948. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13949. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13950. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13951. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13952. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13953. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13954. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13955. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13956. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13957. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13958. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13959. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13960. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13961. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13962. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13963. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13964. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13965. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13966. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13967. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13968. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13969. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13970. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13971. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13972. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13973. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13974. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13975. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value
  13976. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context
  13977. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format
  13978. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand
  13979. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase
  13980. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location
  13981. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit
  13982. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value
  13983. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context
  13984. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format
  13985. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand
  13986. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase
  13987. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location
  13988. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit
  13989. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value
  13990. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context
  13991. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format
  13992. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand
  13993. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase
  13994. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location
  13995. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit
  13996. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value
  13997. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context
  13998. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format
  13999. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand
  14000. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase
  14001. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location
  14002. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit
  14003. );
  14004. }
  14005. }
  14006. // Check File "TempStopTransaction" Exist
  14007. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  14008. {
  14009. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  14010. fclose(fopen("/Storage/OCPP/TempStopTransaction", "w"));
  14011. }
  14012. else
  14013. {
  14014. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  14015. FILE *log = fopen("/Storage/OCPP/TempStopTransaction", "w+");
  14016. if(log == NULL)
  14017. {
  14018. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  14019. return ;
  14020. }
  14021. else
  14022. {
  14023. fclose(log);
  14024. }
  14025. }
  14026. //Add TempStopTransaction | Update TempStopTransaction
  14027. // open file for writing
  14028. FILE *outfile;
  14029. outfile = fopen ("/Storage/OCPP/TempStopTransaction", "a");
  14030. //DEBUG_INFO("data = %s\n", queuedata);
  14031. fputs(queuedata, outfile);
  14032. fputs("\n", outfile);
  14033. fclose (outfile);
  14034. }
  14035. void checkTempStopTransaction(int gun_index)
  14036. {
  14037. FILE *fptr1;
  14038. char ch;
  14039. char str[QUEUE_MESSAGE_LENGTH]={0};
  14040. char guid[37]={0};
  14041. char tempdata[65]={0};
  14042. char connectorStr[2]={0};
  14043. fptr1 = fopen("/Storage/OCPP/TempStopTransaction", "r");
  14044. //TempStopTransaction格式: 槍號,StopTransaction封包
  14045. if (!fptr1)
  14046. {
  14047. //printf(" File not found or unable to open the input file!!\n");
  14048. return ;
  14049. }
  14050. ch=fgetc(fptr1);
  14051. //printf(" Now the content of the file %s is : \n",fname);
  14052. rewind(fptr1);
  14053. if(ch!=EOF)
  14054. {
  14055. // copy all contents to the temporary file except the specific line
  14056. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  14057. {
  14058. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14059. if(str[0]=='\0')
  14060. {
  14061. break;
  14062. }
  14063. //TempStopTransaction格式: 槍號,StopTransaction封包
  14064. strncpy(connectorStr, str, 1);
  14065. if(atoi(connectorStr) != (gun_index+1))
  14066. {
  14067. DEBUG_INFO("atoi(connectorStr) = %d\n", atoi(connectorStr));
  14068. return ;
  14069. }
  14070. //random_uuid(guid);
  14071. strncpy(guid, str+6, 36); //copy guid
  14072. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  14073. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  14074. {
  14075. DEBUG_INFO("StopTransaction mapitem pass\n");
  14076. }
  14077. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  14078. memset(str,0,ARRAY_SIZE(str));
  14079. }
  14080. }
  14081. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  14082. fclose(fptr1);
  14083. remove("/Storage/OCPP/TempStopTransaction"); // remove the original file
  14084. }
  14085. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  14086. {
  14087. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  14088. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  14089. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  14090. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  14091. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14092. }
  14093. int GetWebSocketPingInterval(void)
  14094. {
  14095. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14096. }
  14097. int GetServerSign(void)
  14098. {
  14099. return server_sign;
  14100. }
  14101. void SetServerSign(int value)
  14102. {
  14103. server_sign = value;
  14104. }
  14105. int GetBootNotificationInterval(void)
  14106. {
  14107. return BootNotificationInterval;
  14108. }
  14109. int GetInternetConn(void)
  14110. {
  14111. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  14112. }
  14113. void InitialSystemValue(void)
  14114. {
  14115. int connectorIndex = 0;
  14116. //int valueASCII = 0;
  14117. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14118. gunTotalNumber=0;
  14119. SystemInitial = 0;
  14120. localversion=0;
  14121. BootNotificationInterval = 0;
  14122. authorizeRetryTimes = 0;
  14123. GunStatusInterval = 10;
  14124. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14125. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14126. //Hear Beat
  14127. HeartBeatWithNOResponse = 0;
  14128. HeartBeatCountPerHour = 0;
  14129. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  14130. FirstHeartBeat = 0;
  14131. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  14132. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  14133. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  14134. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  14135. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  14136. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  14137. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  14138. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  14139. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  14140. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  14141. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  14142. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  14143. memset(gunType, 0, ARRAY_SIZE(gunType));
  14144. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14145. {
  14146. //check connector / socket type (index: 8, 9, 10)
  14147. for(int index=7; index <10 ; index++)
  14148. {
  14149. if(index != 8)
  14150. {
  14151. // DC Connector
  14152. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] >= 'A') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= 'Z'))
  14153. {
  14154. SystemInitial = SystemInitial + 1;
  14155. gunTotalNumber = gunTotalNumber + 1;
  14156. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14157. connectorIndex = connectorIndex + 1;
  14158. }
  14159. }
  14160. else
  14161. {
  14162. // AC Connector
  14163. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14164. {
  14165. SystemInitial = SystemInitial + 1;
  14166. gunTotalNumber = gunTotalNumber + 1;
  14167. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14168. connectorIndex = connectorIndex + 1;
  14169. }
  14170. }
  14171. }
  14172. //DEBUG_INFO("DC ...\n");
  14173. }
  14174. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  14175. {
  14176. //check connector / socket type (index: 8, 9, 10)
  14177. for(int index=7; index <10 ; index++)
  14178. {
  14179. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14180. {
  14181. SystemInitial = SystemInitial + 1;
  14182. gunTotalNumber = gunTotalNumber + 1;
  14183. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14184. connectorIndex = connectorIndex + 1;
  14185. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  14186. }
  14187. }
  14188. }
  14189. //Status && ConnectorPlugIn Setting
  14190. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14191. {
  14192. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  14193. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  14194. }
  14195. for (int index = 0; index < CCS_QUANTITY; index++)
  14196. {
  14197. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  14198. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  14199. }
  14200. for (int index = 0; index < GB_QUANTITY; index++)
  14201. {
  14202. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  14203. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  14204. }
  14205. for (int index = 0; index < AC_QUANTITY; index++)
  14206. {
  14207. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  14208. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  14209. }
  14210. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  14211. {
  14212. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14213. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  14214. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  14215. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  14216. }
  14217. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  14218. clientTime.Heartbeat=time((time_t*)NULL);
  14219. sleep(1);
  14220. }
  14221. void LWS_Send(char * str)
  14222. {
  14223. //=====================================================
  14224. // Check InternetConn 0: disconnected, 1: connected
  14225. //====================================================
  14226. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14227. {
  14228. DEBUG_INFO("offline now !!!\n");
  14229. return;
  14230. }
  14231. pthread_mutex_lock(&lock_send);
  14232. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14233. sprintf((char *)SendBuffer, "%s", str);
  14234. SendBufLen = strlen(str);
  14235. pthread_mutex_unlock(&lock_send);
  14236. lws_callback_on_writable(wsi_client);
  14237. //lws_service(context, 0);
  14238. //sleep(1);
  14239. }