MessageHandler.c 676 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240
  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 getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  441. {
  442. int result = -1;
  443. struct tm tmStart;
  444. struct timeb tbStart;
  445. struct tm tmStop;
  446. struct timeb tbStop;
  447. 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) &&
  448. (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. tmStart.tm_year -= 1900;
  451. tmStart.tm_mon -= 1;
  452. tbStart.time = mktime(&tmStart);
  453. tbStart.millitm = 0;
  454. tmStop.tm_year -= 1900;
  455. tmStop.tm_mon -= 1;
  456. tbStop.time = mktime(&tmStop);
  457. tbStop.millitm = 0;
  458. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  459. }
  460. return result;
  461. }
  462. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile)
  463. {
  464. FILE *fp;
  465. char profileFileName[128];
  466. char *line = NULL;
  467. size_t len = 0;
  468. time_t CurrentTime;
  469. struct tm *tmComposite;
  470. struct StructChargingProfile maxProfile;
  471. struct StructChargingProfile defaultTxProfile;
  472. struct StructChargingProfile txProfile;
  473. struct StructChargingSchedulePeriod tmpPeriod;
  474. uint8_t limitMax=0;
  475. uint8_t limitDef=0;
  476. uint8_t limitTx=0;
  477. int compositePeriodIdx = 0;
  478. CurrentTime = time(NULL);
  479. tmComposite=localtime(&CurrentTime);
  480. 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);
  481. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  482. compositeProfile->ChargingSchedule.Duration = durationReq;
  483. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  484. {
  485. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  486. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  487. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  488. }
  489. compositeProfile->ChargingProfileId = 0;
  490. compositeProfile->StackLevel = 99 ;
  491. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  492. maxProfile.ChargingProfileId = -1;
  493. defaultTxProfile.ChargingProfileId = -1;
  494. txProfile.ChargingProfileId = -1;
  495. system("yes|rm /tmp/*.json");
  496. system("cp /Storage/OCPP/*.json /tmp");
  497. /*
  498. * Search valid charging profile
  499. */
  500. //DEBUG_INFO("====================================\n");
  501. // Search tx profile
  502. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  503. if((access(profileFileName, F_OK))!=-1)
  504. {
  505. fp = fopen(profileFileName, "r");
  506. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  507. {
  508. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  509. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  510. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  511. }
  512. txProfile.ChargingProfileId = -1;
  513. txProfile.StackLevel = -1;
  514. while(getline(&line, &len, fp) != -1)
  515. {
  516. json_object *obj = NULL;
  517. obj = json_tokener_parse(line);
  518. if(is_error(obj))
  519. {
  520. DEBUG_ERROR("Parse txProfile from file error.\n");
  521. }
  522. else
  523. {
  524. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  525. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  526. )
  527. {
  528. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  529. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  530. )
  531. {
  532. struct tm tmFrom, tmTo;
  533. struct timeb tbFrom, tbTo;
  534. 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) &&
  535. (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))
  536. {
  537. tmFrom.tm_year -= 1900;
  538. tmFrom.tm_mon -= 1;
  539. tbFrom.time = mktime(&tmFrom);
  540. tmTo.tm_year -= 1900;
  541. tmTo.tm_mon -= 1;
  542. tbTo.time = mktime(&tmTo);
  543. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  544. {
  545. if(txProfile.ChargingProfileId == -1)
  546. DEBUG_INFO("TxProfile found.\n");
  547. else
  548. DEBUG_INFO("TxProfile updated.\n");
  549. // Required item
  550. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  551. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  552. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  553. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  554. 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++)
  555. {
  556. 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"));
  557. 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")));
  558. 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?
  559. 3:
  560. 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")));
  561. }
  562. // Optional item
  563. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  564. {
  565. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  566. }
  567. else
  568. {
  569. sprintf((char*)txProfile.ValidFrom, " ");
  570. }
  571. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  572. {
  573. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  574. }
  575. else
  576. {
  577. sprintf((char*)txProfile.ValidTo, " ");
  578. }
  579. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  580. {
  581. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  582. }
  583. else
  584. {
  585. sprintf((char*)txProfile.RecurrencyKind, " ");
  586. }
  587. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  588. {
  589. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  590. }
  591. else
  592. {
  593. txProfile.TransactionId = -1;
  594. }
  595. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  596. {
  597. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  598. }
  599. else
  600. {
  601. txProfile.ChargingSchedule.Duration = 86400;
  602. }
  603. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  604. {
  605. 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")));
  606. }
  607. else
  608. {
  609. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  610. }
  611. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  612. {
  613. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  614. }
  615. else
  616. {
  617. txProfile.ChargingSchedule.MinChargingRate = -1;
  618. }
  619. }
  620. }
  621. }
  622. else
  623. {
  624. if(txProfile.ChargingProfileId == -1)
  625. DEBUG_INFO("TxProfile found.\n");
  626. else
  627. DEBUG_INFO("TxProfile updated.\n");
  628. // Required item
  629. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  630. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  631. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  632. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  633. 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++)
  634. {
  635. 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"));
  636. 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")));
  637. 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?
  638. 3:
  639. 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")));
  640. }
  641. // Optional item
  642. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  643. {
  644. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  645. }
  646. else
  647. {
  648. sprintf((char*)txProfile.ValidFrom, " ");
  649. }
  650. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  651. {
  652. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  653. }
  654. else
  655. {
  656. sprintf((char*)txProfile.ValidTo, " ");
  657. }
  658. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  659. {
  660. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  661. }
  662. else
  663. {
  664. sprintf((char*)txProfile.RecurrencyKind, " ");
  665. }
  666. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  667. {
  668. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  669. }
  670. else
  671. {
  672. txProfile.TransactionId = -1;
  673. }
  674. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  675. {
  676. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  677. }
  678. else
  679. {
  680. txProfile.ChargingSchedule.Duration = 86400;
  681. }
  682. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  683. {
  684. 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")));
  685. }
  686. else
  687. {
  688. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  689. }
  690. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  691. {
  692. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  693. }
  694. else
  695. {
  696. maxProfile.ChargingSchedule.MinChargingRate = -1;
  697. }
  698. }
  699. }
  700. }
  701. json_object_put(obj);
  702. }
  703. fclose(fp);
  704. /*
  705. if(defaultTxProfile.ChargingProfileId != -1)
  706. {
  707. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  708. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  709. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  710. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  711. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  712. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  713. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  714. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  715. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  716. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  717. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  718. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  719. {
  720. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  721. {
  722. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  723. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  724. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  725. }
  726. }
  727. }
  728. else
  729. DEBUG_INFO("TxProfile not found.\n");*/
  730. }
  731. // Search default tx profile
  732. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  733. if((access(profileFileName, F_OK))==-1)
  734. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  735. if((access(profileFileName, F_OK))!=-1)
  736. {
  737. fp = fopen(profileFileName, "r");
  738. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  739. {
  740. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  741. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  742. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  743. }
  744. defaultTxProfile.ChargingProfileId = -1;
  745. defaultTxProfile.StackLevel = -1;
  746. while(getline(&line, &len, fp) != -1)
  747. {
  748. json_object *obj = NULL;
  749. obj = json_tokener_parse(line);
  750. if(is_error(obj))
  751. {
  752. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  753. }
  754. else
  755. {
  756. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  757. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  758. )
  759. {
  760. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  761. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  762. )
  763. {
  764. struct tm tmFrom, tmTo;
  765. struct timeb tbFrom, tbTo;
  766. 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) &&
  767. (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))
  768. {
  769. tmFrom.tm_year -= 1900;
  770. tmFrom.tm_mon -= 1;
  771. tbFrom.time = mktime(&tmFrom);
  772. tmTo.tm_year -= 1900;
  773. tmTo.tm_mon -= 1;
  774. tbTo.time = mktime(&tmTo);
  775. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  776. {
  777. if(defaultTxProfile.ChargingProfileId == -1)
  778. DEBUG_INFO("TxDefaultProfile found.\n");
  779. else
  780. DEBUG_INFO("TxDefaultProfile updated.\n");
  781. // Required item
  782. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  783. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  784. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  785. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  786. 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++)
  787. {
  788. 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"));
  789. 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")));
  790. 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?
  791. 3:
  792. 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")));
  793. }
  794. // Optional item
  795. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  796. {
  797. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  798. }
  799. else
  800. {
  801. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  802. }
  803. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  804. {
  805. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  806. }
  807. else
  808. {
  809. sprintf((char*)defaultTxProfile.ValidTo, " ");
  810. }
  811. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  812. {
  813. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  814. }
  815. else
  816. {
  817. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  818. }
  819. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  820. {
  821. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  822. }
  823. else
  824. {
  825. defaultTxProfile.TransactionId = -1;
  826. }
  827. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  828. {
  829. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  830. }
  831. else
  832. {
  833. defaultTxProfile.ChargingSchedule.Duration = 86400;
  834. }
  835. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  836. {
  837. 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")));
  838. }
  839. else
  840. {
  841. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  842. }
  843. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  844. {
  845. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  846. }
  847. else
  848. {
  849. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  850. }
  851. }
  852. }
  853. }
  854. else
  855. {
  856. if(defaultTxProfile.ChargingProfileId == -1)
  857. DEBUG_INFO("TxDefaultProfile found.\n");
  858. else
  859. DEBUG_INFO("TxDefaultProfile updated.\n");
  860. // Required item
  861. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  862. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  863. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  864. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  865. 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++)
  866. {
  867. 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"));
  868. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/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")));
  869. 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?
  870. 3:
  871. 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")));
  872. }
  873. // Optional item
  874. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  875. {
  876. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  877. }
  878. else
  879. {
  880. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  881. }
  882. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  883. {
  884. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  885. }
  886. else
  887. {
  888. sprintf((char*)defaultTxProfile.ValidTo, " ");
  889. }
  890. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  891. {
  892. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  893. }
  894. else
  895. {
  896. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  897. }
  898. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  899. {
  900. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  901. }
  902. else
  903. {
  904. defaultTxProfile.TransactionId = -1;
  905. }
  906. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  907. {
  908. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  909. }
  910. else
  911. {
  912. defaultTxProfile.ChargingSchedule.Duration = 86400;
  913. }
  914. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  915. {
  916. 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")));
  917. }
  918. else
  919. {
  920. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  921. }
  922. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  923. {
  924. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  925. }
  926. else
  927. {
  928. maxProfile.ChargingSchedule.MinChargingRate = -1;
  929. }
  930. }
  931. }
  932. }
  933. json_object_put(obj);
  934. }
  935. fclose(fp);
  936. /*
  937. if(defaultTxProfile.ChargingProfileId != -1)
  938. {
  939. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  940. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  941. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  942. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  943. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  944. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  945. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  946. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  947. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  948. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  949. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  950. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  951. {
  952. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  953. {
  954. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  955. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  956. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  957. }
  958. }
  959. }
  960. else
  961. DEBUG_INFO("TxDefaultProfile not found.\n");
  962. DEBUG_INFO("------------------------------------\n");*/
  963. }
  964. // Search max profile
  965. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  966. if((access(profileFileName, F_OK))!=-1)
  967. {
  968. fp = fopen(profileFileName, "r");
  969. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  970. {
  971. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  972. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  973. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  974. }
  975. maxProfile.ChargingProfileId = -1;
  976. maxProfile.StackLevel = -1;
  977. while(getline(&line, &len, fp) != -1)
  978. {
  979. json_object *obj = NULL;
  980. obj = json_tokener_parse(line);
  981. if(is_error(obj))
  982. {
  983. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  984. }
  985. else
  986. {
  987. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  988. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  989. )
  990. {
  991. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  992. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  993. )
  994. {
  995. struct tm tmFrom, tmTo;
  996. struct timeb tbFrom, tbTo;
  997. 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) &&
  998. (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))
  999. {
  1000. tmFrom.tm_year -= 1900;
  1001. tmFrom.tm_mon -= 1;
  1002. tbFrom.time = mktime(&tmFrom);
  1003. tmTo.tm_year -= 1900;
  1004. tmTo.tm_mon -= 1;
  1005. tbTo.time = mktime(&tmTo);
  1006. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1007. {
  1008. if(maxProfile.ChargingProfileId == -1)
  1009. DEBUG_INFO("MaxProfile found.\n");
  1010. else
  1011. DEBUG_INFO("MaxProfile updated.\n");
  1012. // Required item
  1013. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1014. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1015. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1016. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1017. 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++)
  1018. {
  1019. 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"));
  1020. 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")));
  1021. 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?
  1022. 3:
  1023. 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")));
  1024. }
  1025. // Optional item
  1026. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1027. {
  1028. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1029. }
  1030. else
  1031. {
  1032. sprintf((char*)maxProfile.ValidFrom, " ");
  1033. }
  1034. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1035. {
  1036. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1037. }
  1038. else
  1039. {
  1040. sprintf((char*)maxProfile.ValidTo, " ");
  1041. }
  1042. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1043. {
  1044. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1045. }
  1046. else
  1047. {
  1048. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1049. }
  1050. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1051. {
  1052. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1053. }
  1054. else
  1055. {
  1056. maxProfile.TransactionId = -1;
  1057. }
  1058. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1059. {
  1060. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1061. }
  1062. else
  1063. {
  1064. maxProfile.ChargingSchedule.Duration = 86400;
  1065. }
  1066. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1067. {
  1068. 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")));
  1069. }
  1070. else
  1071. {
  1072. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1073. }
  1074. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1075. {
  1076. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1077. }
  1078. else
  1079. {
  1080. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1081. }
  1082. }
  1083. }
  1084. }
  1085. else
  1086. {
  1087. if(maxProfile.ChargingProfileId == -1)
  1088. DEBUG_INFO("MaxProfile found.\n");
  1089. else
  1090. DEBUG_INFO("MaxProfile updated.\n");
  1091. // Required item
  1092. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1093. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1094. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1095. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1096. 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++)
  1097. {
  1098. 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"));
  1099. 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")));
  1100. 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?
  1101. 3:
  1102. 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")));
  1103. }
  1104. // Optional item
  1105. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1106. {
  1107. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1108. }
  1109. else
  1110. {
  1111. sprintf((char*)maxProfile.ValidFrom, " ");
  1112. }
  1113. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1114. {
  1115. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1116. }
  1117. else
  1118. {
  1119. sprintf((char*)maxProfile.ValidTo, " ");
  1120. }
  1121. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1122. {
  1123. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1124. }
  1125. else
  1126. {
  1127. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1128. }
  1129. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1130. {
  1131. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1132. }
  1133. else
  1134. {
  1135. maxProfile.TransactionId = -1;
  1136. }
  1137. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1138. {
  1139. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1140. }
  1141. else
  1142. {
  1143. maxProfile.ChargingSchedule.Duration = 86400;
  1144. }
  1145. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1146. {
  1147. 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")));
  1148. }
  1149. else
  1150. {
  1151. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1152. }
  1153. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1154. {
  1155. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1156. }
  1157. else
  1158. {
  1159. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1160. }
  1161. }
  1162. }
  1163. }
  1164. json_object_put(obj);
  1165. }
  1166. fclose(fp);
  1167. /*
  1168. if(maxProfile.ChargingProfileId !=-1)
  1169. {
  1170. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1171. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1172. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1173. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1174. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1175. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1176. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1177. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1178. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1179. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1180. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1181. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1182. {
  1183. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1184. {
  1185. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1186. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1187. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1188. }
  1189. }
  1190. }
  1191. else
  1192. DEBUG_INFO("MaxProfile not found.\n");
  1193. DEBUG_INFO("------------------------------------\n");*/
  1194. }
  1195. /*
  1196. * Align found profile start schedule & periods
  1197. */
  1198. //DEBUG_INFO("====================================\n");
  1199. /*
  1200. // For local test usage, force modify found profile start schedule info
  1201. 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);
  1202. 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);
  1203. 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);
  1204. */
  1205. if(txProfile.ChargingProfileId != -1)
  1206. {
  1207. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1208. {
  1209. if(txProfile.ChargingSchedule.Duration != -1)
  1210. {
  1211. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1212. 0:
  1213. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1214. }
  1215. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1216. {
  1217. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1218. {
  1219. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1220. 0:
  1221. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1222. if(idxPeriod > 0)
  1223. {
  1224. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1225. {
  1226. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit;
  1227. }
  1228. }
  1229. }
  1230. }
  1231. }
  1232. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1233. {
  1234. if(txProfile.ChargingSchedule.Duration != -1)
  1235. {
  1236. 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?
  1237. 0:
  1238. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1239. }
  1240. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1241. {
  1242. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1243. {
  1244. 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?
  1245. 0:
  1246. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1247. if(idxPeriod > 0)
  1248. {
  1249. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1250. {
  1251. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit;
  1252. }
  1253. }
  1254. }
  1255. }
  1256. }
  1257. else
  1258. {
  1259. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1260. {
  1261. if(txProfile.ChargingSchedule.Duration != -1)
  1262. {
  1263. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1264. 0:
  1265. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1266. }
  1267. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1268. {
  1269. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1270. {
  1271. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1272. 0:
  1273. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1274. if(idxPeriod > 0)
  1275. {
  1276. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1277. {
  1278. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit;
  1279. }
  1280. }
  1281. }
  1282. }
  1283. }
  1284. else
  1285. {
  1286. if(txProfile.ChargingSchedule.Duration != -1)
  1287. {
  1288. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1289. 0:
  1290. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1291. }
  1292. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1293. {
  1294. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1295. {
  1296. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1297. 0:
  1298. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1299. if(idxPeriod > 0)
  1300. {
  1301. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1302. {
  1303. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit;
  1304. }
  1305. }
  1306. }
  1307. }
  1308. }
  1309. }
  1310. /*
  1311. DEBUG_INFO("txProfile after align.\n");
  1312. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1313. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1314. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1315. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1316. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1317. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1318. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1319. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1320. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1321. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1322. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1323. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1324. {
  1325. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1326. {
  1327. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1328. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1329. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1330. }
  1331. }*/
  1332. }
  1333. if(defaultTxProfile.ChargingProfileId != -1)
  1334. {
  1335. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1336. {
  1337. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1338. {
  1339. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1340. 0:
  1341. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1342. }
  1343. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1344. {
  1345. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1346. {
  1347. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1348. 0:
  1349. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1350. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1351. {
  1352. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1353. }
  1354. if(idxPeriod > 0)
  1355. {
  1356. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1357. {
  1358. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit;
  1359. }
  1360. }
  1361. }
  1362. }
  1363. }
  1364. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1365. {
  1366. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1367. {
  1368. 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?
  1369. 0:
  1370. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1371. }
  1372. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1373. {
  1374. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1375. {
  1376. 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?
  1377. 0:
  1378. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1379. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1380. {
  1381. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1382. }
  1383. if(idxPeriod > 0)
  1384. {
  1385. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1386. {
  1387. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit;
  1388. }
  1389. }
  1390. }
  1391. }
  1392. }
  1393. else
  1394. {
  1395. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1396. {
  1397. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1398. {
  1399. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1400. 0:
  1401. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1402. }
  1403. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1404. {
  1405. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1406. {
  1407. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1408. 0:
  1409. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1410. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1411. {
  1412. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1413. }
  1414. if(idxPeriod > 0)
  1415. {
  1416. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1417. {
  1418. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit;
  1419. }
  1420. }
  1421. }
  1422. }
  1423. }
  1424. else
  1425. {
  1426. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1427. {
  1428. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1429. 0:
  1430. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1431. }
  1432. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1433. {
  1434. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1435. {
  1436. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1437. 0:
  1438. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1439. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1440. {
  1441. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1442. }
  1443. if(idxPeriod > 0)
  1444. {
  1445. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1446. {
  1447. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit;
  1448. }
  1449. }
  1450. }
  1451. }
  1452. }
  1453. }
  1454. /*
  1455. DEBUG_INFO("defaultTxProfile after align.\n");
  1456. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1457. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1458. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1459. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1460. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1461. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1462. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1463. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1464. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1465. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1466. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1467. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1468. {
  1469. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1470. {
  1471. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1472. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1473. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1474. }
  1475. }
  1476. DEBUG_INFO("------------------------------------\n");*/
  1477. }
  1478. if(maxProfile.ChargingProfileId != -1)
  1479. {
  1480. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1481. {
  1482. if(maxProfile.ChargingSchedule.Duration != -1)
  1483. {
  1484. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1485. 0:
  1486. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1487. }
  1488. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1489. {
  1490. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1491. {
  1492. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1493. 0:
  1494. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1495. if(idxPeriod > 0)
  1496. {
  1497. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1498. {
  1499. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit;
  1500. }
  1501. }
  1502. }
  1503. }
  1504. }
  1505. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1506. {
  1507. if(maxProfile.ChargingSchedule.Duration != -1)
  1508. {
  1509. 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?
  1510. 0:
  1511. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1512. }
  1513. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1514. {
  1515. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1516. {
  1517. 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?
  1518. 0:
  1519. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1520. if(idxPeriod > 0)
  1521. {
  1522. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1523. {
  1524. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit;
  1525. }
  1526. }
  1527. }
  1528. }
  1529. }
  1530. else
  1531. {
  1532. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1533. {
  1534. if(maxProfile.ChargingSchedule.Duration != -1)
  1535. {
  1536. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1537. 0:
  1538. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1539. }
  1540. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1541. {
  1542. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1543. {
  1544. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1545. 0:
  1546. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1547. if(idxPeriod > 0)
  1548. {
  1549. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1550. {
  1551. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit;
  1552. }
  1553. }
  1554. }
  1555. }
  1556. }
  1557. else
  1558. {
  1559. if(maxProfile.ChargingSchedule.Duration != -1)
  1560. {
  1561. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1562. 0:
  1563. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1564. }
  1565. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1566. {
  1567. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1568. {
  1569. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1570. 0:
  1571. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1572. if(idxPeriod > 0)
  1573. {
  1574. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1575. {
  1576. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit;
  1577. }
  1578. }
  1579. }
  1580. }
  1581. }
  1582. }
  1583. /*
  1584. DEBUG_INFO("MaxProfile after align.\n");
  1585. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1586. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1587. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1588. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1589. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1590. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1591. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1592. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1593. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1594. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1595. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1596. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1597. {
  1598. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1599. {
  1600. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1601. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1602. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1603. }
  1604. }
  1605. DEBUG_INFO("------------------------------------\n");*/
  1606. }
  1607. /*
  1608. * Merge to conposite schedule
  1609. */
  1610. //DEBUG_INFO("====================================\n");
  1611. // Find each profile period quantity
  1612. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1613. {
  1614. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1615. limitMax = idx+1;
  1616. }
  1617. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1618. {
  1619. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1620. limitDef = idx+1;
  1621. }
  1622. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1623. {
  1624. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1625. limitTx = idx+1;
  1626. }
  1627. // TxProfile found, composite schedule based on it
  1628. if(txProfile.ChargingProfileId != -1)
  1629. {
  1630. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  1631. {
  1632. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  1633. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  1634. (txProfile.ChargingSchedule.Duration > 0))
  1635. {
  1636. if(maxProfile.ChargingProfileId != -1)
  1637. {
  1638. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1639. {
  1640. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  1641. {
  1642. if((maxProfile.ChargingSchedule.Duration > 0))
  1643. {
  1644. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1645. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1646. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1647. }
  1648. else
  1649. {
  1650. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1651. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1652. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  1653. }
  1654. }
  1655. if(idxMaxPeriod == (limitMax-1))
  1656. {
  1657. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1658. {
  1659. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1660. {
  1661. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1662. compositePeriodIdx++;
  1663. }
  1664. else
  1665. {
  1666. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1667. }
  1668. }
  1669. }
  1670. }
  1671. }
  1672. else
  1673. {
  1674. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1675. {
  1676. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1677. compositePeriodIdx++;
  1678. }
  1679. else
  1680. {
  1681. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1682. }
  1683. }
  1684. }
  1685. if(idxTxPeriod == (limitTx-1))
  1686. {
  1687. if(defaultTxProfile.ChargingProfileId != -1)
  1688. {
  1689. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1690. {
  1691. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  1692. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  1693. (defaultTxProfile.ChargingSchedule.Duration>0))
  1694. {
  1695. if(maxProfile.ChargingProfileId != -1)
  1696. {
  1697. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1698. {
  1699. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1700. {
  1701. if((maxProfile.ChargingSchedule.Duration > 0))
  1702. {
  1703. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1704. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1705. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1706. }
  1707. else
  1708. {
  1709. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1710. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1711. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  1712. }
  1713. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1714. {
  1715. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1716. {
  1717. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1718. compositePeriodIdx++;
  1719. }
  1720. else
  1721. {
  1722. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1723. }
  1724. }
  1725. break;
  1726. }
  1727. }
  1728. }
  1729. else
  1730. {
  1731. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1732. {
  1733. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1734. compositePeriodIdx++;
  1735. }
  1736. else
  1737. {
  1738. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1739. }
  1740. }
  1741. }
  1742. }
  1743. }
  1744. }
  1745. }
  1746. }
  1747. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  1748. else if(defaultTxProfile.ChargingProfileId != -1)
  1749. {
  1750. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1751. {
  1752. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  1753. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  1754. (defaultTxProfile.ChargingSchedule.Duration > 0))
  1755. {
  1756. if(maxProfile.ChargingProfileId != -1)
  1757. {
  1758. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1759. {
  1760. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1761. {
  1762. if((maxProfile.ChargingSchedule.Duration > 0))
  1763. {
  1764. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1765. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1766. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  1767. }
  1768. else
  1769. {
  1770. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1771. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1772. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  1773. }
  1774. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1775. {
  1776. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1777. {
  1778. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1779. compositePeriodIdx++;
  1780. }
  1781. else
  1782. {
  1783. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1784. }
  1785. }
  1786. break;
  1787. }
  1788. }
  1789. }
  1790. else
  1791. {
  1792. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1793. {
  1794. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1795. compositePeriodIdx++;
  1796. }
  1797. else
  1798. {
  1799. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1800. }
  1801. }
  1802. }
  1803. }
  1804. }
  1805. // Fill other period by MaxProfile
  1806. if(maxProfile.ChargingProfileId != -1)
  1807. {
  1808. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1809. {
  1810. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1811. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1812. (maxProfile.ChargingSchedule.Duration > 0))
  1813. {
  1814. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  1815. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  1816. {
  1817. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  1818. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  1819. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1820. }
  1821. if((maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  1822. {
  1823. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.Duration;
  1824. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  1825. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1826. }
  1827. if(tmpPeriod.Limit != -1)
  1828. {
  1829. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1830. {
  1831. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1832. {
  1833. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1834. compositePeriodIdx++;
  1835. }
  1836. else
  1837. {
  1838. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1839. }
  1840. }
  1841. }
  1842. }
  1843. }
  1844. }
  1845. DEBUG_INFO("Composite schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1846. DEBUG_INFO("Composite schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1847. DEBUG_INFO("Composite rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1848. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1849. {
  1850. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1851. {
  1852. compositeProfile->ChargingProfileId = 1;
  1853. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1854. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1855. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1856. }
  1857. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1858. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1859. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1860. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1861. }
  1862. if(line)
  1863. free(line);
  1864. }
  1865. //==========================================
  1866. // Init all share memory
  1867. //==========================================
  1868. int InitShareMemory()
  1869. {
  1870. int result = PASS;
  1871. int MeterSMId;
  1872. //creat ShmSysConfigAndInfo
  1873. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  1874. {
  1875. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  1876. result = FAIL;
  1877. }
  1878. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1879. {
  1880. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  1881. result = FAIL;
  1882. }
  1883. else
  1884. {}
  1885. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  1886. {
  1887. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  1888. result = FAIL;
  1889. }
  1890. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1891. {
  1892. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  1893. result = FAIL;
  1894. }
  1895. else
  1896. {}
  1897. //creat ShmPsuData
  1898. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  1899. {
  1900. DEBUG_ERROR("shmget ShmPsuData NG\n");
  1901. result = FAIL;
  1902. }
  1903. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1904. {
  1905. DEBUG_ERROR("shmat ShmPsuData NG\n");
  1906. result = FAIL;
  1907. }
  1908. else
  1909. {}
  1910. //creat ShmOCPP16Data
  1911. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  1912. {
  1913. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  1914. result = FAIL;
  1915. }
  1916. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1917. {
  1918. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  1919. result = FAIL;
  1920. }
  1921. else
  1922. {}
  1923. /****************************** For Initial Settings************************************************/
  1924. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  1925. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  1926. // allocate Configuration memory address
  1927. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  1928. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  1929. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  1930. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  1931. //offline MeterValue Interval
  1932. TempMeterValueInterval = 0;
  1933. return result;
  1934. }
  1935. int ProcessShareMemory()
  1936. {
  1937. if(InitShareMemory() == FAIL)
  1938. {
  1939. DEBUG_ERROR("InitShareMemory NG\n");
  1940. if(ShmStatusCodeData!=NULL)
  1941. {
  1942. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  1943. }
  1944. sleep(5);
  1945. return FAIL;
  1946. }
  1947. return PASS;
  1948. }
  1949. //---------------------common routine---------------------------//
  1950. int isOFFline(void)
  1951. {
  1952. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  1953. {
  1954. if(TempMeterValueInterval >= 2 )
  1955. {
  1956. TempMeterValueInterval = 0;
  1957. return TRUE;
  1958. }
  1959. else
  1960. {
  1961. TempMeterValueInterval = TempMeterValueInterval+ 1;
  1962. return FALSE;
  1963. }
  1964. }
  1965. else
  1966. {
  1967. return FALSE;
  1968. }
  1969. }
  1970. //---------------------------------------------
  1971. // new:
  1972. // enum SYSTEM_STATUS
  1973. // {
  1974. // SYS_MODE_BOOTING = 0,
  1975. // SYS_MODE_IDLE = 1,
  1976. // SYS_MODE_AUTHORIZING = 2,
  1977. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  1978. // SYS_MODE_REASSIGN = 4,
  1979. // SYS_MODE_PREPARING = 5,
  1980. // SYS_MODE_PREPARE_FOR_EV = 6,
  1981. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  1982. // SYS_MODE_CHARGING = 8,
  1983. // SYS_MODE_TERMINATING = 9,
  1984. // SYS_MODE_COMPLETE = 10,
  1985. // SYS_MODE_ALARM = 11,
  1986. // SYS_MODE_FAULT = 12,
  1987. // SYS_MODE_RESERVATION = 13,
  1988. // SYS_MODE_BOOKING = 14,
  1989. // SYS_MODE_MAINTAIN = 15,
  1990. // SYS_MODE_DEBUG = 16,
  1991. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  1992. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  1993. // SYS_MODE_UPDATE = 19
  1994. // };
  1995. //
  1996. //
  1997. //-----------------------------------------
  1998. void CheckSystemValue(void)
  1999. {
  2000. uint8_t reqSampleMeter[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  2001. uint8_t reqClockAlignMeter[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  2002. char filenmae[100]={0};
  2003. char str[100]={0};
  2004. int tempIndex = 0;
  2005. //===============================
  2006. // send Heartbeat
  2007. //===============================
  2008. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2009. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2010. {
  2011. clientTime.Heartbeat=time((time_t*)NULL);
  2012. if(server_sign == TRUE)
  2013. {
  2014. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2015. }
  2016. else
  2017. {
  2018. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2019. }
  2020. }
  2021. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  2022. {
  2023. //parameter for test
  2024. sendHeartbeatRequest(0);
  2025. //==============================================
  2026. // Reset Waiting Time
  2027. //==============================================
  2028. clientTime.Heartbeat=time((time_t*)NULL);
  2029. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  2030. }
  2031. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2032. {
  2033. //===============================
  2034. // CSU Trigger Reset Conf
  2035. //===============================
  2036. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  2037. {
  2038. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  2039. }
  2040. //===============================
  2041. // CSU Trigger Authorize Request
  2042. //===============================
  2043. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2044. {
  2045. sendAuthorizeRequest(0);
  2046. authorizeRetryTimes = authorizeRetryTimes + 1;
  2047. if(authorizeRetryTimes < 3)
  2048. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2049. }
  2050. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  2051. {
  2052. authorizeRetryTimes = 0;
  2053. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  2054. server_sign = FALSE;
  2055. }
  2056. 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))
  2057. {
  2058. sendAuthorizeRequest(0);
  2059. }
  2060. //===============================
  2061. // CSU Trigger Smart Charging Profilw
  2062. //===============================
  2063. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2064. {
  2065. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index]);
  2066. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2067. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  2068. }
  2069. //==============================================
  2070. // Charger start transaction
  2071. //==============================================
  2072. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2073. {
  2074. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  2075. sendStartTransactionRequest(gun_index);
  2076. clientTime.StartTransaction = time((time_t*)NULL);
  2077. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2078. }
  2079. //==============================================
  2080. // Charger stop transaction
  2081. //==============================================
  2082. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2083. {
  2084. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  2085. sendStopTransactionRequest(gun_index);
  2086. clientTime.StopTransaction = time((time_t*)NULL);
  2087. }
  2088. //==============================================
  2089. // Charger status report
  2090. //==============================================
  2091. //--- Check Mode Change ---//
  2092. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2093. if(gunType[gun_index] == 'J')
  2094. {
  2095. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2096. {
  2097. tempIndex = ((gun_index==2) ? 1: 0);
  2098. }
  2099. else
  2100. {
  2101. tempIndex = gun_index;
  2102. }
  2103. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2104. {
  2105. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2106. {
  2107. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  2108. {
  2109. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2110. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2111. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2112. statusModeChage[gun_index] = TRUE;
  2113. }
  2114. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2115. {
  2116. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2117. if((access(filenmae,F_OK))!=-1)
  2118. {
  2119. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2120. sprintf(str,"rm -f %s",filenmae);
  2121. system(str);
  2122. }
  2123. }
  2124. #if 1 // for TempStopTransaction
  2125. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2126. {
  2127. checkTempStopTransaction(gun_index);
  2128. }
  2129. #endif
  2130. }
  2131. }
  2132. }
  2133. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2134. {
  2135. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2136. {
  2137. tempIndex = ((gun_index==2) ? 1: 0);
  2138. }
  2139. else
  2140. {
  2141. tempIndex = gun_index;
  2142. }
  2143. for (int index = 0; index < CCS_QUANTITY; index++)
  2144. {
  2145. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2146. {
  2147. 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]*/ )
  2148. {
  2149. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2150. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2151. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2152. statusModeChage[gun_index] = TRUE;
  2153. }
  2154. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2155. {
  2156. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2157. if((access(filenmae,F_OK))!=-1)
  2158. {
  2159. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2160. sprintf(str,"rm -f %s",filenmae);
  2161. system(str);
  2162. }
  2163. }
  2164. #if 1 // for TempStopTransaction
  2165. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2166. {
  2167. checkTempStopTransaction(gun_index);
  2168. }
  2169. #endif
  2170. }
  2171. }
  2172. }
  2173. else if(gunType[gun_index] == 'G')
  2174. {
  2175. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2176. {
  2177. tempIndex = ((gun_index==2) ? 1: 0);
  2178. }
  2179. else
  2180. {
  2181. tempIndex = gun_index;
  2182. }
  2183. for (int index = 0; index < GB_QUANTITY; index++)
  2184. {
  2185. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2186. {
  2187. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2188. {
  2189. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2190. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2191. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2192. statusModeChage[gun_index] = TRUE;
  2193. }
  2194. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2195. {
  2196. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2197. if((access(filenmae,F_OK))!=-1)
  2198. {
  2199. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2200. sprintf(str,"rm -f %s",filenmae);
  2201. system(str);
  2202. }
  2203. }
  2204. #if 1 // for TempStopTransaction
  2205. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2206. {
  2207. checkTempStopTransaction(gun_index);
  2208. }
  2209. #endif
  2210. }
  2211. }
  2212. }
  2213. else
  2214. {
  2215. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2216. {
  2217. tempIndex = 2;
  2218. }
  2219. else
  2220. {
  2221. tempIndex = gun_index;
  2222. }
  2223. for (int index = 0; index < AC_QUANTITY; index++)
  2224. {
  2225. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2226. {
  2227. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2228. {
  2229. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2230. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2231. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2232. statusModeChage[gun_index] = TRUE;
  2233. }
  2234. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2235. {
  2236. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2237. if((access(filenmae,F_OK))!=-1)
  2238. {
  2239. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2240. sprintf(str,"rm -f %s",filenmae);
  2241. system(str);
  2242. }
  2243. }
  2244. #if 1 // for TempStopTransaction
  2245. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2246. {
  2247. checkTempStopTransaction(gun_index);
  2248. }
  2249. #endif
  2250. }
  2251. }// END
  2252. }
  2253. if(isWebsocketSendable &&
  2254. (((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]) > 10)))) )
  2255. {
  2256. if(SystemInitial > 0)
  2257. SystemInitial -= 1;
  2258. sendStatusNotificationRequest(gun_index);
  2259. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2260. statusModeChage[gun_index] = FALSE;
  2261. }
  2262. //==============================================
  2263. // Meter report
  2264. //==============================================
  2265. if(cpinitateMsg.bits[gun_index].TriggerMeterValue)
  2266. {
  2267. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  2268. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  2269. }
  2270. if(/*(server_sign == TRUE) &&(isOFFline() == TRUE) ||*/
  2271. (((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)))
  2272. {
  2273. //check Transaction active
  2274. if(gunType[gun_index] == 'J')
  2275. {
  2276. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2277. {
  2278. tempIndex = ((gun_index==2) ? 1: 0);
  2279. }
  2280. else
  2281. {
  2282. tempIndex = gun_index;
  2283. }
  2284. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2285. {
  2286. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2287. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2288. {
  2289. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2290. {
  2291. reqSampleMeter[gun_index] = 1;
  2292. }
  2293. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2294. {
  2295. reqClockAlignMeter[gun_index] = 1;
  2296. }
  2297. }
  2298. }// End for CHAdeMO
  2299. }
  2300. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2301. {
  2302. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2303. {
  2304. tempIndex = ((gun_index==2) ? 1: 0);
  2305. }
  2306. else
  2307. {
  2308. tempIndex = gun_index;
  2309. }
  2310. for (int index = 0; index < CCS_QUANTITY; index++)
  2311. {
  2312. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2313. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2314. {
  2315. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2316. {
  2317. reqSampleMeter[gun_index] = 1;
  2318. }
  2319. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2320. {
  2321. reqClockAlignMeter[gun_index] = 1;
  2322. }
  2323. }
  2324. } // End for CCS
  2325. }
  2326. else if(gunType[gun_index] == 'G')
  2327. {
  2328. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2329. {
  2330. tempIndex = ((gun_index==2) ? 1: 0);
  2331. }
  2332. else
  2333. {
  2334. tempIndex = gun_index;
  2335. }
  2336. for (int index = 0; index < GB_QUANTITY; index++)
  2337. {
  2338. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2339. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2340. {
  2341. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2342. {
  2343. reqSampleMeter[gun_index] = 1;
  2344. }
  2345. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2346. {
  2347. reqClockAlignMeter[gun_index] = 1;
  2348. }
  2349. }
  2350. }// End for GB
  2351. }
  2352. else
  2353. {
  2354. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2355. {
  2356. tempIndex = 2;
  2357. }
  2358. else
  2359. {
  2360. tempIndex = gun_index;
  2361. }
  2362. for (int index = 0; index < AC_QUANTITY; index++)
  2363. {
  2364. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2365. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2366. {
  2367. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2368. {
  2369. reqSampleMeter[gun_index] = 1;
  2370. }
  2371. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2372. {
  2373. reqClockAlignMeter[gun_index] = 1;
  2374. }
  2375. }
  2376. }//End for AC
  2377. }
  2378. if(reqSampleMeter[gun_index] == 1)
  2379. {
  2380. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  2381. storeTempStopTransaction(gun_index);
  2382. }
  2383. else if(reqClockAlignMeter[gun_index] == 1)
  2384. {
  2385. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2386. }
  2387. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2388. sleep(1);
  2389. }
  2390. //==============================================
  2391. // Check Connector reserved
  2392. //==============================================
  2393. //===============================
  2394. // Check if Reserve is expired
  2395. //===============================
  2396. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  2397. {
  2398. double diff_t;
  2399. struct tm tp;
  2400. // current time
  2401. time_t t = time(NULL);
  2402. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  2403. tp.tm_isdst = -1;
  2404. time_t utc = mktime(&tp);
  2405. diff_t = difftime(utc, t);
  2406. if(diff_t <= 0)
  2407. {
  2408. DEBUG_INFO("reserve expired.\n");
  2409. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  2410. }
  2411. }//END OF Check if Reserve is expired
  2412. //==========================================
  2413. // csu trigger FirmwareStatusNotificationReq
  2414. //==========================================
  2415. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  2416. {
  2417. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  2418. }
  2419. //==========================================
  2420. // csu trigger CancelReservationConf
  2421. //==========================================
  2422. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  2423. {
  2424. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  2425. }
  2426. //==========================================
  2427. // csu trigger ChangeAvailabilityConf
  2428. //==========================================
  2429. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  2430. {
  2431. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  2432. }
  2433. //==========================================
  2434. // csu trigger UnlockConnectorConf
  2435. //==========================================
  2436. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  2437. {
  2438. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  2439. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  2440. }
  2441. //==========================================
  2442. // csu trigger ReserveNowConf
  2443. //==========================================
  2444. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  2445. {
  2446. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  2447. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  2448. }
  2449. //==========================================
  2450. // csu trigger DataTransferReq
  2451. //==========================================
  2452. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2453. {
  2454. sendDataTransferRequest(gun_index);
  2455. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2456. }
  2457. }
  2458. }
  2459. //==========================================
  2460. // send request routine
  2461. //==========================================
  2462. int sendAuthorizeRequest(int gun_index)
  2463. {
  2464. mtrace();
  2465. int result = FAIL;
  2466. char message[100]={0};
  2467. char guid[37];
  2468. char tempdata[65]={0};
  2469. DEBUG_INFO("sendAuthorizeRequest...\n");
  2470. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  2471. //Local Authorize
  2472. if ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  2473. {
  2474. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  2475. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2476. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  2477. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  2478. result = PASS;
  2479. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2480. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2481. authorizeRetryTimes = 0;
  2482. return result;
  2483. }
  2484. 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))||
  2485. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  2486. {
  2487. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2488. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  2489. {
  2490. if(strcmp(idTagQuery.idTagstr,"") == 0)
  2491. {
  2492. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  2493. }
  2494. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  2495. {
  2496. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  2497. }
  2498. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  2499. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2500. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2501. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  2502. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  2503. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2504. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2505. authorizeRetryTimes = 0;
  2506. return result;
  2507. }
  2508. else
  2509. {
  2510. DEBUG_INFO("offline Local Authorization Pass !!!!\n");
  2511. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  2512. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2513. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  2514. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  2515. result = PASS;
  2516. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2517. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2518. authorizeRetryTimes = 0;
  2519. return result;
  2520. }
  2521. }
  2522. //initailize struct Authorize
  2523. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  2524. //get data from shared memory
  2525. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2526. random_uuid(guid);
  2527. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  2528. LWS_Send(message);
  2529. sprintf(tempdata, "Authorize,%d", gun_index);
  2530. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2531. {
  2532. result = PASS;
  2533. DEBUG_INFO("Authorize mapItem pass\n");
  2534. }
  2535. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2536. return result;
  2537. }
  2538. int sendBootNotificationRequest(void)
  2539. {
  2540. mtrace();
  2541. int result = FAIL;
  2542. char message[500]={0}, payload[700]={0};
  2543. char guid[37]={0};
  2544. char tempdata[65]={0};
  2545. /*
  2546. int IsGunCharging = FALSE;
  2547. //check Transaction active
  2548. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2549. {
  2550. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2551. {
  2552. IsGunCharging = TRUE;
  2553. }
  2554. }
  2555. for (int index = 0; index < CCS_QUANTITY; index++)
  2556. {
  2557. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2558. {
  2559. IsGunCharging = TRUE;
  2560. }
  2561. }
  2562. for (int index = 0; index < GB_QUANTITY; index++)
  2563. {
  2564. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2565. {
  2566. IsGunCharging = TRUE;
  2567. }
  2568. }
  2569. for (int index = 0; index < AC_QUANTITY; index++)
  2570. {
  2571. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2572. {
  2573. IsGunCharging = TRUE;
  2574. }
  2575. }
  2576. if(IsGunCharging == TRUE)
  2577. {
  2578. server_sign = TRUE;
  2579. return result;
  2580. }
  2581. */
  2582. // Fill BootNotification fields
  2583. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  2584. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  2585. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  2586. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2587. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  2588. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  2589. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  2590. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  2591. ShmOCPP16Data->ChargeBoxId
  2592. ,ShmSysConfigAndInfo->SysConfig.ModelName
  2593. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  2594. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  2595. ,ShmOCPP16Data->BootNotification.CpFwVersion
  2596. ,ShmOCPP16Data->BootNotification.CpIccid
  2597. ,ShmOCPP16Data->BootNotification.CpImsi);
  2598. random_uuid(guid);
  2599. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  2600. LWS_Send(message);
  2601. sprintf(tempdata, "BootNotification,0");
  2602. 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*/)
  2603. {
  2604. result = PASS;
  2605. }
  2606. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  2607. strcpy(queuedata,message);
  2608. return result;
  2609. }
  2610. int sendDataTransferRequest(int gun_index)
  2611. {
  2612. mtrace();
  2613. char message[1000]={0};
  2614. char guid[37]={0};
  2615. char tempdata[65]={0};
  2616. int result = FAIL;
  2617. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  2618. random_uuid(guid);
  2619. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  2620. MESSAGE_TYPE_CALL,
  2621. guid,
  2622. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  2623. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  2624. ShmOCPP16Data->DataTransfer[gun_index].Data);
  2625. LWS_Send(message);
  2626. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  2627. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2628. {
  2629. result = PASS;
  2630. DEBUG_INFO("DataTransfer mapItem pass\n");
  2631. }
  2632. return result;
  2633. }
  2634. int sendDiagnosticsStatusNotificationRequest(char *status)
  2635. {
  2636. mtrace();
  2637. int result = FAIL;
  2638. char message[110]={0};
  2639. char guid[37]={0};
  2640. char tempdata[65]={0};
  2641. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  2642. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  2643. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  2644. random_uuid(guid);
  2645. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  2646. LWS_Send(message);
  2647. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  2648. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2649. {
  2650. result = PASS;
  2651. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  2652. }
  2653. //#ifdef SystemLogMessage
  2654. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  2655. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2656. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  2657. //#endif
  2658. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  2659. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  2660. //record status
  2661. if(strcmp(status,"Idle")==0)
  2662. {
  2663. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  2664. }
  2665. else if(strcmp(status,"Uploaded")==0)
  2666. {
  2667. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  2668. }
  2669. else if(strcmp(status,"UploadFailed")==0)
  2670. {
  2671. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  2672. }
  2673. else if(strcmp(status,"Uploading")==0)
  2674. {
  2675. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  2676. }
  2677. return result;
  2678. }
  2679. int sendFirmwareStatusNotificationRequest(char *status)
  2680. {
  2681. mtrace();
  2682. int result = FAIL;
  2683. char message[110]={0};
  2684. char guid[37]={0};
  2685. char tempdata[65]={0};
  2686. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  2687. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  2688. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  2689. random_uuid(guid);
  2690. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  2691. LWS_Send(message);
  2692. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  2693. 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*/)
  2694. {
  2695. result = PASS;
  2696. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  2697. }
  2698. //#ifdef SystemLogMessage
  2699. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  2700. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2701. //#endif
  2702. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  2703. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  2704. //record status
  2705. if(strcmp(status,"Downloaded")==0)
  2706. {
  2707. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  2708. }
  2709. else if(strcmp(status,"DownloadFailed")==0)
  2710. {
  2711. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  2712. }
  2713. else if(strcmp(status,"Downloading")==0)
  2714. {
  2715. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  2716. }
  2717. else if(strcmp(status,"Idle")==0)
  2718. {
  2719. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  2720. }
  2721. else if(strcmp(status,"InstallationFailed")==0)
  2722. {
  2723. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  2724. }
  2725. else if(strcmp(status,"Installing")==0)
  2726. {
  2727. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  2728. }
  2729. else if(strcmp(status,"Installed")==0)
  2730. {
  2731. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  2732. }
  2733. return result;
  2734. }
  2735. int sendHeartbeatRequest(int gun_index)
  2736. {
  2737. mtrace();
  2738. int result = FAIL;
  2739. char message[80]={0};
  2740. char guid[37]={0};
  2741. char tempdata[65]={0};
  2742. random_uuid(guid);
  2743. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  2744. , MESSAGE_TYPE_CALL
  2745. , guid );
  2746. LWS_Send(message);
  2747. sprintf(tempdata, "Heartbeat,%d", 0);
  2748. 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*/)
  2749. {
  2750. result = PASS;
  2751. }
  2752. return result;
  2753. }
  2754. int sendStartTransactionRequest(int gun_index)
  2755. {
  2756. mtrace();
  2757. int result = FAIL;
  2758. char message[250]={0};
  2759. char guid[37]={0};
  2760. struct timeval tmnow;
  2761. struct tm *tm;
  2762. char buf[28];//, usec_buf[6];
  2763. char tempdata[65]={0};
  2764. int tempIndex = 0;
  2765. DEBUG_INFO("sendStartTransactionRequest...\n");
  2766. gettimeofday(&tmnow, NULL);
  2767. time_t t;
  2768. t = time(NULL);
  2769. /*UTC time and date*/
  2770. tm = gmtime(&t);
  2771. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2772. #if 0 // remove temporally
  2773. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2774. strcat(buf,".");
  2775. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2776. strcat(buf,usec_buf);
  2777. #endif
  2778. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  2779. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  2780. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2781. // clear StartTransaction Response
  2782. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  2783. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  2784. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  2785. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  2786. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2787. if(gunType[gun_index] == 'J')
  2788. {
  2789. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2790. {
  2791. tempIndex = ((gun_index==2) ? 1: 0);
  2792. }
  2793. else
  2794. {
  2795. tempIndex = gun_index;
  2796. }
  2797. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2798. {
  2799. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2800. {
  2801. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  2802. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  2803. }
  2804. }
  2805. }
  2806. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2807. {
  2808. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2809. {
  2810. tempIndex = ((gun_index==2) ? 1: 0);
  2811. }
  2812. else
  2813. {
  2814. tempIndex = gun_index;
  2815. }
  2816. for (int index = 0; index < CCS_QUANTITY; index++)
  2817. {
  2818. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2819. {
  2820. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  2821. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  2822. }
  2823. }
  2824. }
  2825. else if(gunType[gun_index] == 'G')
  2826. {
  2827. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2828. {
  2829. tempIndex = ((gun_index==2) ? 1: 0);
  2830. }
  2831. else
  2832. {
  2833. tempIndex = gun_index;
  2834. }
  2835. for (int index = 0; index < GB_QUANTITY; index++)
  2836. {
  2837. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2838. {
  2839. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  2840. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  2841. }
  2842. }
  2843. }
  2844. else
  2845. {
  2846. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2847. {
  2848. tempIndex = 2;
  2849. }
  2850. else
  2851. {
  2852. tempIndex = gun_index;
  2853. }
  2854. for (int index = 0; index < AC_QUANTITY; index++)
  2855. {
  2856. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2857. {
  2858. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  2859. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  2860. }
  2861. }
  2862. }
  2863. random_uuid(guid);
  2864. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  2865. {
  2866. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  2867. , gun_index +1
  2868. , MESSAGE_TYPE_CALL
  2869. , guid
  2870. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  2871. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  2872. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  2873. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  2874. }
  2875. else
  2876. {
  2877. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  2878. , gun_index +1
  2879. , MESSAGE_TYPE_CALL
  2880. , guid
  2881. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  2882. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  2883. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  2884. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  2885. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  2886. }
  2887. #if 1
  2888. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  2889. 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*/)
  2890. {
  2891. result = PASS;
  2892. }
  2893. #endif
  2894. strcpy(queuedata, message);
  2895. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2896. /*
  2897. if(GetTransactionQueueNum() == 1)
  2898. {
  2899. LWS_Send(message + 2);
  2900. }*/
  2901. return result;
  2902. }
  2903. int sendStatusNotificationRequest(int gun_index)
  2904. {
  2905. mtrace();
  2906. int result = FAIL;
  2907. char message[600]={0};
  2908. char guid[37];
  2909. int currentStatus = 0;
  2910. struct timeval tmnow;
  2911. struct tm *tm;
  2912. char buf[28];//, usec_buf[6];
  2913. char tempdata[65]={0};
  2914. int tempIndex = 0;
  2915. gettimeofday(&tmnow, NULL);
  2916. time_t t;
  2917. t = time(NULL);
  2918. /*UTC time and date*/
  2919. tm = gmtime(&t);
  2920. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2921. #if 0 // remove temporally
  2922. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2923. strcat(buf,".");
  2924. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2925. strcat(buf,usec_buf);
  2926. #endif
  2927. printf("%s",buf);
  2928. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  2929. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  2930. // it's option
  2931. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  2932. /*
  2933. enum _SYSTEM_STATUS
  2934. {
  2935. S_BOOTING = 0,
  2936. S_IDLE, = 1
  2937. S_AUTHORIZING, =2
  2938. S_REASSIGN_CHECK, =3
  2939. S_REASSIGN, =4
  2940. S_PRECHARGE, =5
  2941. S_PREPARING_FOR_EV, =6
  2942. S_PREPARING_FOR_EVSE, =7
  2943. S_CHARGING, =8
  2944. S_TERMINATING, =9
  2945. S_COMPLETE, =10
  2946. S_ALARM, =11
  2947. S_FAULT =12
  2948. }
  2949. */
  2950. //check Transaction active
  2951. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2952. if(gunType[gun_index] == 'J')
  2953. {
  2954. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2955. {
  2956. tempIndex = ((gun_index==2) ? 1: 0);
  2957. }
  2958. else
  2959. {
  2960. tempIndex = gun_index;
  2961. }
  2962. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2963. {
  2964. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  2965. {
  2966. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  2967. {
  2968. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  2969. {
  2970. currentStatus = 1; //OCPP Status: Preparing
  2971. }
  2972. else
  2973. {
  2974. currentStatus = 0; //OCPP Status: Available
  2975. }
  2976. }
  2977. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  2978. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  2979. ) //S_PRECHARGE
  2980. {
  2981. currentStatus = 1; //OCPP Status: Preparing
  2982. }
  2983. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2984. {
  2985. currentStatus = 2; //OCPP Status: Charging
  2986. }
  2987. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  2988. {
  2989. currentStatus = 5; //OCPP Status: Finishing
  2990. }
  2991. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  2992. {
  2993. currentStatus = 4; //OCPP Status: SuspendedEV
  2994. }
  2995. 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
  2996. {
  2997. currentStatus = 7; //OCPP Status: Unavailable
  2998. }
  2999. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3000. {
  3001. currentStatus = 8; //OCPP Status: Faulted
  3002. }
  3003. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3004. {
  3005. currentStatus = 6; //OCPP Status: Reserved
  3006. }
  3007. } //end of the same index
  3008. }//end of for CHAdeMO_QUANTITY
  3009. }
  3010. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3011. {
  3012. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3013. {
  3014. tempIndex = ((gun_index==2) ? 1: 0);
  3015. }
  3016. else
  3017. {
  3018. tempIndex = gun_index;
  3019. }
  3020. for (int index = 0; index < CCS_QUANTITY; index++)
  3021. {
  3022. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3023. {
  3024. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3025. {
  3026. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3027. {
  3028. currentStatus = 1; //OCPP Status: Preparing
  3029. }
  3030. else
  3031. {
  3032. currentStatus = 0; //OCPP Status: Available
  3033. }
  3034. }
  3035. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3036. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3037. ) //S_PRECHARGE
  3038. {
  3039. currentStatus = 1; //OCPP Status: Preparing
  3040. }
  3041. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3042. {
  3043. currentStatus = 2; //OCPP Status: Charging
  3044. }
  3045. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3046. {
  3047. currentStatus = 5; //OCPP Status: Finishing
  3048. }
  3049. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3050. {
  3051. currentStatus = 4; //OCPP Status: SuspendedEV
  3052. }
  3053. 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
  3054. {
  3055. currentStatus = 7; //OCPP Status : Unavailable
  3056. }
  3057. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3058. {
  3059. currentStatus = 8; //OCPP Status: Faulted
  3060. }
  3061. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3062. {
  3063. currentStatus = 6; //OCPP Status: Reserved
  3064. }
  3065. } //end of the same index
  3066. } // end of for CCS_QUANTITY
  3067. }
  3068. else if(gunType[gun_index] == 'G')
  3069. {
  3070. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3071. {
  3072. tempIndex = ((gun_index==2) ? 1: 0);
  3073. }
  3074. else
  3075. {
  3076. tempIndex = gun_index;
  3077. }
  3078. for (int index = 0; index < GB_QUANTITY; index++)
  3079. {
  3080. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3081. {
  3082. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3083. {
  3084. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3085. {
  3086. currentStatus = 1; //OCPP Status: Preparing
  3087. }
  3088. else
  3089. {
  3090. currentStatus = 0; //OCPP Status: Available
  3091. }
  3092. }
  3093. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3094. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3095. ) //S_PRECHARGE
  3096. {
  3097. currentStatus = 1; //OCPP Status: Preparing
  3098. }
  3099. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3100. {
  3101. currentStatus = 2; //OCPP Status: Charging
  3102. }
  3103. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3104. {
  3105. currentStatus = 5; //OCPP Status: Finishing
  3106. }
  3107. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3108. {
  3109. currentStatus = 4; //OCPP Status: SuspendedEV
  3110. }
  3111. 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
  3112. {
  3113. currentStatus = 7; //OCPP Status: Unavailable
  3114. }
  3115. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3116. {
  3117. currentStatus = 8; //OCPP Status: Faulted
  3118. }
  3119. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3120. {
  3121. currentStatus = 6; //OCPP Status: Reserved
  3122. }
  3123. } //end of the same index
  3124. } // end of for GB_QUANTITY
  3125. }
  3126. else
  3127. {
  3128. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3129. {
  3130. tempIndex = 2;
  3131. }
  3132. else
  3133. {
  3134. tempIndex = gun_index;
  3135. }
  3136. for (int index = 0; index < AC_QUANTITY; index++)
  3137. {
  3138. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3139. {
  3140. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3141. {
  3142. 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))
  3143. {
  3144. currentStatus = 1; //OCPP Status: Preparing
  3145. }
  3146. else
  3147. {
  3148. currentStatus = 0; //OCPP Status: Available
  3149. }
  3150. }
  3151. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3152. {
  3153. currentStatus = 1; //OCPP Status: Preparing
  3154. }
  3155. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3156. {
  3157. currentStatus = 2; //OCPP Status: Charging
  3158. }
  3159. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3160. {
  3161. currentStatus = 5; //OCPP Status: Finishing
  3162. }
  3163. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3164. {
  3165. currentStatus = 4; //OCPP Status: SuspendedEV
  3166. }
  3167. 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
  3168. {
  3169. currentStatus = 7; //OCPP Status: Unavailable
  3170. }
  3171. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3172. {
  3173. currentStatus = 8; //OCPP Status: Faulted
  3174. }
  3175. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3176. {
  3177. currentStatus = 6; //OCPP Status: Reserved
  3178. }
  3179. }//end of the same index
  3180. }//end of for AC_QUANTITY
  3181. }
  3182. //it's option
  3183. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3184. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  3185. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3186. random_uuid(guid);
  3187. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3188. , MESSAGE_TYPE_CALL
  3189. , guid
  3190. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3191. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3192. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3193. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3194. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3195. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3196. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3197. if((server_sign == TRUE))
  3198. {
  3199. LWS_Send(message);
  3200. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3201. 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*/)
  3202. {
  3203. //DEBUG_ERROR("statusNotification mapitem pass");
  3204. result = PASS;
  3205. }
  3206. }
  3207. else
  3208. {
  3209. result = PASS;
  3210. }
  3211. return result;
  3212. }
  3213. int sendStopTransactionRequest(int gun_index)
  3214. {
  3215. mtrace();
  3216. int result = FAIL;
  3217. //char message[1500]={0};
  3218. char guid[37]={0};
  3219. char tempdata[65]={0};
  3220. int tempIndex = 0;
  3221. //int idx_sample=0;
  3222. DEBUG_ERROR("sendStopTransactionRequest \n");
  3223. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3224. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3225. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3226. if(gunType[gun_index] == 'J')
  3227. {
  3228. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3229. {
  3230. tempIndex = ((gun_index==2) ? 1: 0);
  3231. }
  3232. else
  3233. {
  3234. tempIndex = gun_index;
  3235. }
  3236. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3237. {
  3238. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3239. {
  3240. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3241. }
  3242. }// END OF CHAdeMO_QUANTITY
  3243. }
  3244. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3245. {
  3246. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3247. {
  3248. tempIndex = ((gun_index==2) ? 1: 0);
  3249. }
  3250. else
  3251. {
  3252. tempIndex = gun_index;
  3253. }
  3254. for (int index = 0; index < CCS_QUANTITY; index++)
  3255. {
  3256. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3257. {
  3258. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3259. }
  3260. }// END OF CCS_QUANTITY
  3261. }
  3262. else if(gunType[gun_index] == 'G')
  3263. {
  3264. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3265. {
  3266. tempIndex = ((gun_index==2) ? 1: 0);
  3267. }
  3268. else
  3269. {
  3270. tempIndex = gun_index;
  3271. }
  3272. for (int index = 0; index < GB_QUANTITY; index++)
  3273. {
  3274. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3275. {
  3276. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3277. }
  3278. }// END OF GB_QUANTITY
  3279. }
  3280. else
  3281. {
  3282. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3283. {
  3284. tempIndex = 2;
  3285. }
  3286. else
  3287. {
  3288. tempIndex = gun_index;
  3289. }
  3290. for (int index = 0; index < AC_QUANTITY; index++)
  3291. {
  3292. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3293. {
  3294. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3295. }
  3296. }// END OF AC_QUANTITY
  3297. }
  3298. //====================================== Stop Transaction Time =====================================================
  3299. struct timeval tmnow;
  3300. struct tm *tm;
  3301. char buf[28];//, usec_buf[6];
  3302. gettimeofday(&tmnow, NULL);
  3303. time_t t;
  3304. t = time(NULL);
  3305. /*UTC time and date*/
  3306. tm = gmtime(&t);
  3307. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3308. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  3309. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  3310. random_uuid(guid);
  3311. /***********************************transactionData******************************************************/
  3312. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  3313. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  3314. //=================================
  3315. // Transaction_Begin
  3316. //=================================
  3317. //============================================ Energy.Active.Import.Interval ================================
  3318. //idx_sample=0;
  3319. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  3320. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  3321. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  3322. 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*/]);
  3323. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3324. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3325. {
  3326. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  3327. }
  3328. else
  3329. {
  3330. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  3331. }
  3332. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  3333. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3334. //=================================
  3335. // Transaction_End
  3336. //=================================
  3337. // ================================= Current.Import L1 ===============================================
  3338. //idx_sample=1;
  3339. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  3340. if(gunType[gun_index] == 'J')
  3341. {
  3342. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3343. {
  3344. tempIndex = ((gun_index==2) ? 1: 0);
  3345. }
  3346. else
  3347. {
  3348. tempIndex = gun_index;
  3349. }
  3350. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3351. {
  3352. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3353. {
  3354. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3355. }
  3356. }// End of for CHAdeMO_QUANTITY
  3357. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3358. }
  3359. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  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 < CCS_QUANTITY; index++)
  3370. {
  3371. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3372. {
  3373. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3374. }
  3375. }// End of for CCS_QUANTITY
  3376. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3377. }
  3378. else if(gunType[gun_index] == 'G')
  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 < GB_QUANTITY; index++)
  3389. {
  3390. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3391. {
  3392. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3393. }
  3394. }// End of for GB_QUANTITY
  3395. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3396. }
  3397. else
  3398. {
  3399. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3400. {
  3401. tempIndex = 2;
  3402. }
  3403. else
  3404. {
  3405. tempIndex = gun_index;
  3406. }
  3407. for (int index = 0; index < AC_QUANTITY; index++)
  3408. {
  3409. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3410. {
  3411. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  3412. }
  3413. }// End of for AC_QUANTITY
  3414. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  3415. }
  3416. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3417. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  3418. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  3419. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  3420. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3421. // ================================= Energy.Active.Import.Interval ==============================================
  3422. //idx_sample=2;
  3423. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3424. if(gunType[gun_index] == 'J')
  3425. {
  3426. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3427. {
  3428. tempIndex = ((gun_index==2) ? 1: 0);
  3429. }
  3430. else
  3431. {
  3432. tempIndex = gun_index;
  3433. }
  3434. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3435. {
  3436. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3437. {
  3438. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3439. }
  3440. }// END OF CHAdeMO_QUANTITY
  3441. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3442. }
  3443. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  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 < CCS_QUANTITY; index++)
  3454. {
  3455. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3456. {
  3457. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3458. }
  3459. }// END OF CCS_QUANTITY
  3460. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3461. }
  3462. else if(gunType[gun_index] == 'G')
  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 < GB_QUANTITY; index++)
  3473. {
  3474. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3475. {
  3476. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3477. }
  3478. }// END OF GB_QUANTITY
  3479. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3480. }
  3481. else
  3482. {
  3483. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3484. {
  3485. tempIndex = 2;
  3486. }
  3487. else
  3488. {
  3489. tempIndex = gun_index;
  3490. }
  3491. for (int index = 0; index < AC_QUANTITY; index++)
  3492. {
  3493. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3494. {
  3495. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3496. }
  3497. }// END OF AC_QUANTITY
  3498. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  3499. }
  3500. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3501. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  3502. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  3503. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  3504. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3505. //=================================== Power.Active.Import ==================================================
  3506. //idx_sample=3;
  3507. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3508. if(gunType[gun_index] == 'J')
  3509. {
  3510. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3511. {
  3512. tempIndex = ((gun_index==2) ? 1: 0);
  3513. }
  3514. else
  3515. {
  3516. tempIndex = gun_index;
  3517. }
  3518. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3519. {
  3520. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3521. {
  3522. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3523. }
  3524. } // End for CHAdeMO_QUANTITY
  3525. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3526. }
  3527. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  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 < CCS_QUANTITY; index++)
  3538. {
  3539. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3540. {
  3541. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3542. }
  3543. } // END for CCS_QUANTITY
  3544. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3545. }
  3546. else if(gunType[gun_index] == 'G')
  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 < GB_QUANTITY; index++)
  3557. {
  3558. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3559. {
  3560. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3561. }
  3562. }// END for GB_QUANTITY
  3563. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3564. }
  3565. else
  3566. {
  3567. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3568. {
  3569. tempIndex = 2;
  3570. }
  3571. else
  3572. {
  3573. tempIndex = gun_index;
  3574. }
  3575. for (int index = 0; index < AC_QUANTITY; index++)
  3576. {
  3577. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3578. {
  3579. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3580. }
  3581. } // END for AC_QUANTITY
  3582. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  3583. }
  3584. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3585. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  3586. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  3587. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  3588. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  3589. //============================ Voltage L1 ====================================
  3590. //idx_sample=4;
  3591. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3592. if(gunType[gun_index] == 'J')
  3593. {
  3594. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3595. {
  3596. tempIndex = ((gun_index==2) ? 1: 0);
  3597. }
  3598. else
  3599. {
  3600. tempIndex = gun_index;
  3601. }
  3602. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3603. {
  3604. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3605. {
  3606. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3607. }
  3608. } // END OF FOR CHAdeMO_QUANTITY
  3609. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3610. }
  3611. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  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 < CCS_QUANTITY; index++)
  3622. {
  3623. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3624. {
  3625. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3626. }
  3627. } // END OF FOR CCS_QUANTITY
  3628. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3629. }
  3630. else if(gunType[gun_index] == 'G')
  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 < GB_QUANTITY; index++)
  3641. {
  3642. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3643. {
  3644. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3645. }
  3646. } // END OF FOR GB_QUANTITY
  3647. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3648. }
  3649. else
  3650. {
  3651. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3652. {
  3653. tempIndex = 2;
  3654. }
  3655. else
  3656. {
  3657. tempIndex = gun_index;
  3658. }
  3659. for (int index = 0; index < AC_QUANTITY; index++)
  3660. {
  3661. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3662. {
  3663. 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
  3664. }
  3665. } // END OF FOR AC_QUANTITY
  3666. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  3667. }
  3668. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3669. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  3670. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  3671. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  3672. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3673. //====================== SoC ================================
  3674. //idx_sample=5;
  3675. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3676. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3677. {
  3678. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3679. {
  3680. tempIndex = ((gun_index==2) ? 1: 0);
  3681. }
  3682. else
  3683. {
  3684. tempIndex = gun_index;
  3685. }
  3686. if(gunType[gun_index] == 'J')
  3687. {
  3688. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3689. {
  3690. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3691. {
  3692. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  3693. }
  3694. }
  3695. }
  3696. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3697. {
  3698. for (int index = 0; index < CCS_QUANTITY; index++)
  3699. {
  3700. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3701. {
  3702. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  3703. }
  3704. }
  3705. }
  3706. else if(gunType[gun_index] == 'G')
  3707. {
  3708. for (int index = 0; index < GB_QUANTITY; index++)
  3709. {
  3710. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3711. {
  3712. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  3713. }
  3714. }
  3715. }
  3716. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3717. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  3718. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  3719. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  3720. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  3721. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  3722. } // END FOR DC CASE
  3723. // ================================= Current.Import L2 ===============================================
  3724. //idx_sample=6;
  3725. // AC 3 phse L2 current
  3726. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3727. {
  3728. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3729. {
  3730. tempIndex = 2;
  3731. }
  3732. else
  3733. {
  3734. tempIndex = gun_index;
  3735. }
  3736. for (int index = 0; index < AC_QUANTITY; index++)
  3737. {
  3738. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3739. {
  3740. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  3741. }
  3742. }// End of for AC_QUANTITY
  3743. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  3744. }
  3745. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3746. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  3747. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  3748. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  3749. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3750. // ================================= Current.Import L3 ===============================================
  3751. //idx_sample=7;
  3752. // AC 3 phse L3 current
  3753. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3754. {
  3755. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3756. {
  3757. tempIndex = 2;
  3758. }
  3759. else
  3760. {
  3761. tempIndex = gun_index;
  3762. }
  3763. for (int index = 0; index < AC_QUANTITY; index++)
  3764. {
  3765. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3766. {
  3767. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  3768. }
  3769. }// End of for AC_QUANTITY
  3770. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  3771. }
  3772. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3773. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  3774. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  3775. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  3776. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3777. //============================ Voltage L2 ====================================
  3778. //idx_sample=8;
  3779. // AC 3 phse L2 voltage
  3780. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3781. {
  3782. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3783. {
  3784. tempIndex = 2;
  3785. }
  3786. else
  3787. {
  3788. tempIndex = gun_index;
  3789. }
  3790. for (int index = 0; index < AC_QUANTITY; index++)
  3791. {
  3792. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3793. {
  3794. 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
  3795. }
  3796. } // END OF FOR AC_QUANTITY
  3797. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  3798. }
  3799. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3800. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  3801. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  3802. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  3803. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3804. //============================ Voltage L3 ====================================
  3805. //idx_sample=8;
  3806. // AC 3 phse L3 voltage
  3807. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3808. {
  3809. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3810. {
  3811. tempIndex = 2;
  3812. }
  3813. else
  3814. {
  3815. tempIndex = gun_index;
  3816. }
  3817. for (int index = 0; index < AC_QUANTITY; index++)
  3818. {
  3819. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3820. {
  3821. 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
  3822. }
  3823. } // END OF FOR AC_QUANTITY
  3824. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  3825. }
  3826. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3827. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  3828. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  3829. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  3830. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3831. //================================================ Message create ====================================================
  3832. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3833. {
  3834. 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\"}]}]}]"
  3835. ,gun_index+1
  3836. ,MESSAGE_TYPE_CALL
  3837. ,guid
  3838. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3839. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3840. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3841. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3842. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3843. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3844. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3845. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3846. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3847. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3848. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3849. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3850. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3851. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3852. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3853. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3854. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3855. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3856. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3857. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3858. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3859. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3860. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3861. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3862. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3863. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3864. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3865. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3866. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3867. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3868. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3869. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3870. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3871. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3872. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3873. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3874. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3875. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3876. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3877. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3878. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3879. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  3880. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  3881. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  3882. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  3883. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  3884. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  3885. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  3886. );
  3887. }
  3888. else
  3889. {
  3890. if((ShmSysConfigAndInfo->SysConfig.ModelName[2]!='Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2]!='W'))
  3891. {
  3892. 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\"}]}]}]"
  3893. ,gun_index+1
  3894. ,MESSAGE_TYPE_CALL
  3895. ,guid
  3896. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3897. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3898. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3899. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3900. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3901. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3902. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3903. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3904. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3905. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3906. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3907. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3908. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3909. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3910. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3911. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3912. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3913. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3914. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3915. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3916. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3917. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3918. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3919. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3920. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3921. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3922. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3923. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3924. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3925. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3926. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3927. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3928. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3929. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3930. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3931. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3932. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3933. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3934. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3935. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3936. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3937. );
  3938. }
  3939. else
  3940. {
  3941. 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\"}]}]}]"
  3942. ,gun_index+1
  3943. ,MESSAGE_TYPE_CALL
  3944. ,guid
  3945. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3946. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3947. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3948. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3949. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3950. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3951. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3952. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3953. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3954. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3955. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3956. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3957. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3958. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3959. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3960. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3961. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3962. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3963. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3964. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3965. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3966. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3967. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3968. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3969. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3970. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3971. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3972. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3973. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3974. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3975. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3976. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3977. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3978. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3979. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3980. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3981. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3982. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3983. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3984. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3985. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3986. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value
  3987. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context
  3988. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format
  3989. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand
  3990. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase
  3991. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location
  3992. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit
  3993. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value
  3994. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context
  3995. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format
  3996. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand
  3997. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase
  3998. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location
  3999. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit
  4000. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value
  4001. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context
  4002. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format
  4003. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand
  4004. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase
  4005. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location
  4006. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit
  4007. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value
  4008. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context
  4009. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format
  4010. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand
  4011. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase
  4012. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location
  4013. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit
  4014. );
  4015. }
  4016. }
  4017. #if 1 // for TempStopTransaction
  4018. //Delete TempStopTransaction
  4019. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  4020. {
  4021. remove("/Storage/OCPP/TempStopTransaction"); // remove file "TempStopTransaction"
  4022. }
  4023. #endif
  4024. #if 1
  4025. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4026. if(hashmap_operation(0, guid, tempdata) == 1)
  4027. {
  4028. result = PASS;
  4029. DEBUG_INFO("StopTransaction mapitem pass\n");
  4030. }
  4031. #endif
  4032. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4033. /*
  4034. if(GetTransactionQueueNum() == 1)
  4035. {
  4036. LWS_Send(queuedata+2);
  4037. }*/
  4038. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4039. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4040. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  4041. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4042. {
  4043. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4044. }
  4045. //for test
  4046. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4047. return result;
  4048. }
  4049. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4050. {
  4051. mtrace();
  4052. int result = FAIL;
  4053. char guid[37]={0};
  4054. char tempdata[65]={0};
  4055. int tempIndex = 0;
  4056. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4057. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4058. //set value
  4059. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4060. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ((strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging") != NULL) ? ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId : 0);
  4061. random_uuid(guid);
  4062. //UTC Date time
  4063. struct timeval tmnow;
  4064. struct tm *tm;
  4065. char buf[28];//, usec_buf[6];
  4066. gettimeofday(&tmnow, NULL);
  4067. time_t t;
  4068. t = time(NULL);
  4069. /*UTC time and date*/
  4070. tm = gmtime(&t);
  4071. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4072. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4073. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4074. //idx_sample=0;
  4075. //********************************(1)Current.Import L1************************************************/
  4076. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4077. if(gunType[gun_index] == 'J')
  4078. {
  4079. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4080. {
  4081. tempIndex = ((gun_index==2) ? 1: 0);
  4082. }
  4083. else
  4084. {
  4085. tempIndex = gun_index;
  4086. }
  4087. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4088. {
  4089. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4090. {
  4091. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4092. }
  4093. }
  4094. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4095. }
  4096. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  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 < CCS_QUANTITY; index++)
  4107. {
  4108. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4109. {
  4110. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[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] == 'G')
  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 < GB_QUANTITY; index++)
  4126. {
  4127. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4128. {
  4129. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4130. }
  4131. }
  4132. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4133. }
  4134. else
  4135. {
  4136. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4137. {
  4138. tempIndex = 2;
  4139. }
  4140. else
  4141. {
  4142. tempIndex = gun_index;
  4143. }
  4144. for (int index = 0; index < AC_QUANTITY; index++)
  4145. {
  4146. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4147. {
  4148. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4149. }
  4150. }
  4151. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4152. }
  4153. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4154. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4155. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4156. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4157. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4158. //idx_sample=1;
  4159. //********************************(2)Energy.Active.Import.Register ************************************************/
  4160. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4161. if(gunType[gun_index] == 'J')
  4162. {
  4163. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4164. {
  4165. tempIndex = ((gun_index==2) ? 1: 0);
  4166. }
  4167. else
  4168. {
  4169. tempIndex = gun_index;
  4170. }
  4171. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4172. {
  4173. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4174. {
  4175. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4176. }
  4177. }
  4178. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4179. }
  4180. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  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 < CCS_QUANTITY; index++)
  4191. {
  4192. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4193. {
  4194. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[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] == 'G')
  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 < GB_QUANTITY; index++)
  4210. {
  4211. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4212. {
  4213. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4214. }
  4215. }
  4216. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4217. }
  4218. else
  4219. {
  4220. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4221. {
  4222. tempIndex = 2;
  4223. }
  4224. else
  4225. {
  4226. tempIndex = gun_index;
  4227. }
  4228. for (int index = 0; index < AC_QUANTITY; index++)
  4229. {
  4230. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4231. {
  4232. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4233. }
  4234. }
  4235. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4236. }
  4237. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  4238. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4239. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4240. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4241. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4242. //idx_sample=2;
  4243. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  4244. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4245. if(gunType[gun_index] == 'J')
  4246. {
  4247. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4248. {
  4249. tempIndex = ((gun_index==2) ? 1: 0);
  4250. }
  4251. else
  4252. {
  4253. tempIndex = gun_index;
  4254. }
  4255. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4256. {
  4257. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4258. {
  4259. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4260. }
  4261. } // END OF FOR CHAdeMO_QUANTITY
  4262. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4263. }
  4264. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  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 < CCS_QUANTITY; index++)
  4275. {
  4276. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4277. {
  4278. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  4279. }
  4280. } // END OF CCS_QUANTITY
  4281. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4282. }
  4283. else if(gunType[gun_index] == 'G')
  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 < GB_QUANTITY; index++)
  4294. {
  4295. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4296. {
  4297. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  4298. }
  4299. } // END OF GB_QUANTITY
  4300. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4301. }
  4302. else
  4303. {
  4304. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4305. {
  4306. tempIndex = 2;
  4307. }
  4308. else
  4309. {
  4310. tempIndex = gun_index;
  4311. }
  4312. for (int index = 0; index < AC_QUANTITY; index++)
  4313. {
  4314. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4315. {
  4316. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  4317. }
  4318. }
  4319. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  4320. }
  4321. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  4322. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  4323. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  4324. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  4325. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4326. //idx_sample=3;
  4327. //********************************(4)Power.Active.Import************************************************/
  4328. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4329. if(gunType[gun_index] == 'J')
  4330. {
  4331. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4332. {
  4333. tempIndex = ((gun_index==2) ? 1: 0);
  4334. }
  4335. else
  4336. {
  4337. tempIndex = gun_index;
  4338. }
  4339. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4340. {
  4341. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4342. {
  4343. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  4344. }
  4345. } // END OF FOR
  4346. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4347. }
  4348. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  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 < CCS_QUANTITY; index++)
  4359. {
  4360. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4361. {
  4362. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  4363. }
  4364. }
  4365. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4366. }
  4367. else if(gunType[gun_index] == 'G')
  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 < GB_QUANTITY; index++)
  4378. {
  4379. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4380. {
  4381. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4382. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  4383. }
  4384. }
  4385. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4386. }
  4387. else
  4388. {
  4389. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4390. {
  4391. tempIndex = 2;
  4392. }
  4393. else
  4394. {
  4395. tempIndex = gun_index;
  4396. }
  4397. for (int index = 0; index < AC_QUANTITY; index++)
  4398. {
  4399. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4400. {
  4401. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  4402. }
  4403. }
  4404. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  4405. }
  4406. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  4407. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  4408. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  4409. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  4410. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  4411. //idx_sample=4;
  4412. //***********************************************(5)VOLTAGE L1******************************************************/
  4413. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4414. if(gunType[gun_index] == 'J')
  4415. {
  4416. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4417. {
  4418. tempIndex = ((gun_index==2) ? 1: 0);
  4419. }
  4420. else
  4421. {
  4422. tempIndex = gun_index;
  4423. }
  4424. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4425. {
  4426. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4427. {
  4428. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  4429. }
  4430. }
  4431. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4432. }
  4433. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  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 < CCS_QUANTITY; index++)
  4444. {
  4445. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4446. {
  4447. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[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] == 'G')
  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 < GB_QUANTITY; index++)
  4463. {
  4464. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4465. {
  4466. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  4467. }
  4468. }
  4469. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4470. }
  4471. else
  4472. {
  4473. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4474. {
  4475. tempIndex = 2;
  4476. }
  4477. else
  4478. {
  4479. tempIndex = gun_index;
  4480. }
  4481. for (int index = 0; index < AC_QUANTITY; index++)
  4482. {
  4483. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4484. {
  4485. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  4486. }
  4487. }
  4488. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  4489. }
  4490. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  4491. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  4492. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  4493. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  4494. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4495. //***********************************************(6)SOC******************************************************/
  4496. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  4497. {
  4498. //idx_sample=5;
  4499. //sampledValue = NULL;
  4500. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4501. {
  4502. tempIndex = ((gun_index==2) ? 1: 0);
  4503. }
  4504. else
  4505. {
  4506. tempIndex = gun_index;
  4507. }
  4508. if(gunType[gun_index] == 'J')
  4509. {
  4510. //tempIndex = ((gun_index==2) ? 1: 0);
  4511. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4512. {
  4513. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4514. {
  4515. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  4516. }
  4517. }
  4518. }
  4519. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4520. {
  4521. //tempIndex = ((gun_index==2) ? 1: 0);
  4522. for (int index = 0; index < CCS_QUANTITY; index++)
  4523. {
  4524. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4525. {
  4526. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  4527. }
  4528. }
  4529. }
  4530. else if(gunType[gun_index] == 'G')
  4531. {
  4532. //tempIndex = ((gun_index==2) ? 1: 0);
  4533. for (int index = 0; index < GB_QUANTITY; index++)
  4534. {
  4535. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4536. {
  4537. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  4538. }
  4539. }
  4540. }
  4541. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4542. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  4543. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  4544. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  4545. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_Outlet]);
  4546. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  4547. }
  4548. //********************************(7)Current.Import L2************************************************/
  4549. // Only for AC 3 phase
  4550. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4551. {
  4552. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4553. {
  4554. tempIndex = 2;
  4555. }
  4556. else
  4557. {
  4558. tempIndex = gun_index;
  4559. }
  4560. for (int index = 0; index < AC_QUANTITY; index++)
  4561. {
  4562. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4563. {
  4564. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  4565. }
  4566. }
  4567. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  4568. }
  4569. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  4570. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  4571. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  4572. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  4573. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4574. //********************************(8)Current.Import L3************************************************/
  4575. // Only for AC 3 phase
  4576. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4577. {
  4578. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4579. {
  4580. tempIndex = 2;
  4581. }
  4582. else
  4583. {
  4584. tempIndex = gun_index;
  4585. }
  4586. for (int index = 0; index < AC_QUANTITY; index++)
  4587. {
  4588. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4589. {
  4590. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  4591. }
  4592. }
  4593. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  4594. }
  4595. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  4596. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  4597. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  4598. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  4599. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4600. //***********************************************(9)VOLTAGE L2******************************************************/
  4601. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4602. {
  4603. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4604. {
  4605. tempIndex = 2;
  4606. }
  4607. else
  4608. {
  4609. tempIndex = gun_index;
  4610. }
  4611. for (int index = 0; index < AC_QUANTITY; index++)
  4612. {
  4613. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4614. {
  4615. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  4616. }
  4617. }
  4618. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  4619. }
  4620. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  4621. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  4622. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  4623. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  4624. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4625. //***********************************************(10)VOLTAGE L3******************************************************/
  4626. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4627. {
  4628. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4629. {
  4630. tempIndex = 2;
  4631. }
  4632. else
  4633. {
  4634. tempIndex = gun_index;
  4635. }
  4636. for (int index = 0; index < AC_QUANTITY; index++)
  4637. {
  4638. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4639. {
  4640. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  4641. }
  4642. }
  4643. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  4644. }
  4645. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  4646. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  4647. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  4648. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  4649. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4650. // Message create ====================================================================================================
  4651. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  4652. {
  4653. 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\"}]}]}]"
  4654. ,gun_index + 1
  4655. ,MESSAGE_TYPE_CALL
  4656. ,guid
  4657. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4658. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4659. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4660. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4661. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4662. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4663. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4664. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4665. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4666. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4667. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4668. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4669. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4670. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4671. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4672. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4673. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4674. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4675. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4676. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4677. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4678. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4679. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4680. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4681. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4682. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4683. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4684. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4685. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4686. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4687. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4688. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4689. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4690. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4691. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4692. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4693. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4694. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4695. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value
  4696. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context
  4697. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format
  4698. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand
  4699. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase
  4700. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location
  4701. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit
  4702. );
  4703. }
  4704. else
  4705. {
  4706. if((ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'W'))
  4707. {
  4708. 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\"}]}]}]"
  4709. ,gun_index + 1
  4710. ,MESSAGE_TYPE_CALL
  4711. ,guid
  4712. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4713. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4714. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4715. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4716. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4717. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4718. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4719. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4720. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4721. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4722. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4723. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4724. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4725. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4726. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4727. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4728. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4729. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4730. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4731. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4732. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4733. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4734. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4735. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4736. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4737. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4738. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4739. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4740. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4741. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4742. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4743. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4744. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4745. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4746. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4747. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4748. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4749. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4750. );
  4751. }
  4752. else
  4753. {
  4754. 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\"}]}]}]"
  4755. ,gun_index + 1
  4756. ,MESSAGE_TYPE_CALL
  4757. ,guid
  4758. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4759. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4760. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4761. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4762. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4763. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4764. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4765. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4766. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4767. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4768. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4769. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4770. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4771. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4772. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4773. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4774. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4775. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4776. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4777. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4778. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4779. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4780. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4781. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4782. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4783. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4784. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4785. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4786. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4787. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4788. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4789. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4790. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4791. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4792. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4793. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4794. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4795. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4796. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value
  4797. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context
  4798. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format
  4799. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand
  4800. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase
  4801. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location
  4802. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit
  4803. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value
  4804. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context
  4805. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format
  4806. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand
  4807. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase
  4808. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location
  4809. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit
  4810. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value
  4811. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context
  4812. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format
  4813. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand
  4814. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase
  4815. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location
  4816. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit
  4817. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value
  4818. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context
  4819. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format
  4820. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand
  4821. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase
  4822. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location
  4823. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit
  4824. );
  4825. }
  4826. }
  4827. // Put request guid to hash map
  4828. sprintf(tempdata, "MeterValues,%d", (gun_index));
  4829. 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*/)
  4830. {
  4831. result = PASS;
  4832. DEBUG_INFO("MeterValues mapitem pass\n");
  4833. }
  4834. if(dataType != ReadingContext_Trigger)
  4835. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4836. else
  4837. LWS_Send(queuedata +2);
  4838. /*
  4839. if(GetTransactionQueueNum() == 1)
  4840. {
  4841. LWS_Send(queuedata +2);
  4842. }*/
  4843. return result;
  4844. }
  4845. //==========================================
  4846. // send confirm routine
  4847. //==========================================
  4848. int sendCancelReservationConfirmation(char *uuid,char *payload)
  4849. {
  4850. mtrace();
  4851. int result = FAIL;
  4852. char message[100]={0};
  4853. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  4854. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4855. LWS_Send(message);
  4856. result = TRUE;
  4857. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  4858. return result;
  4859. }
  4860. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  4861. {
  4862. mtrace();
  4863. int result = FAIL;
  4864. char message[100]={0};
  4865. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  4866. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4867. LWS_Send(message);
  4868. result = TRUE;
  4869. return result;
  4870. }
  4871. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  4872. {
  4873. mtrace();
  4874. int result = FAIL;
  4875. char message[100]={0};
  4876. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  4877. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4878. LWS_Send(message);
  4879. result = TRUE;
  4880. return result;
  4881. }
  4882. int sendClearCacheConfirmation(char *uuid,char *payload)
  4883. {
  4884. mtrace();
  4885. int result = FAIL;
  4886. char message[500]={0};
  4887. DEBUG_INFO("sendClearCacheConfirmation...\n");
  4888. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4889. LWS_Send(message);
  4890. return result;
  4891. }
  4892. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  4893. {
  4894. mtrace();
  4895. int result = FAIL;
  4896. char message[500]={0};
  4897. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  4898. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4899. LWS_Send(message);
  4900. return result;
  4901. }
  4902. int sendDataTransferConfirmation(char *uuid,char *payload)
  4903. {
  4904. mtrace();
  4905. char statusStr[20]={0};
  4906. char dataStr[10]={0};
  4907. char sstr[20]={0};
  4908. int c = 0;
  4909. char *loc;
  4910. int result = FAIL;
  4911. DEBUG_INFO("sendDataTransferConfirmation...\n");
  4912. /**********************status**************************/
  4913. loc = strstr(payload, "status");
  4914. memset(sstr ,0, ARRAY_SIZE(sstr) );
  4915. c = 0;
  4916. while (loc[3+strlen("status")+c] != '\"')
  4917. {
  4918. sstr[c] = loc[3+strlen("status")+c];
  4919. c++;
  4920. }
  4921. sstr[c] = '\0';
  4922. strcpy(statusStr, sstr);
  4923. /**********************data**************************/
  4924. loc = strstr(payload, "data");
  4925. memset(sstr ,0, ARRAY_SIZE(sstr) );
  4926. c = 0;
  4927. while (loc[3+strlen("data")+c] != '\"')
  4928. {
  4929. sstr[c] = loc[3+strlen("data")+c];
  4930. c++;
  4931. }
  4932. sstr[c] = '\0';
  4933. strcpy(dataStr, sstr);
  4934. return result;
  4935. }
  4936. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  4937. {
  4938. mtrace();
  4939. int result = FAIL;
  4940. char message[1000]={0};
  4941. int CompositeScheduleIndex = 0;
  4942. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  4943. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  4944. if(nPeriod == 0)
  4945. {
  4946. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  4947. {
  4948. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  4949. ,MESSAGE_TYPE_CALLRESULT
  4950. ,uuid
  4951. ,payload
  4952. ,connectorIdInt);
  4953. }
  4954. else
  4955. {
  4956. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  4957. ,MESSAGE_TYPE_CALLRESULT
  4958. ,uuid
  4959. ,payload
  4960. ,connectorIdInt
  4961. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4962. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  4963. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4964. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  4965. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  4966. }
  4967. }
  4968. else
  4969. {
  4970. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  4971. ,MESSAGE_TYPE_CALLRESULT
  4972. ,uuid
  4973. ,payload
  4974. ,connectorIdInt
  4975. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4976. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  4977. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4978. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  4979. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  4980. {
  4981. if (idx_sample == 0)
  4982. {
  4983. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  4984. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  4985. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  4986. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  4987. }
  4988. else
  4989. {
  4990. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  4991. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  4992. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  4993. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  4994. }
  4995. }
  4996. sprintf(message + strlen(message), "]}}]");
  4997. }
  4998. LWS_Send(message);
  4999. result = TRUE;
  5000. return result;
  5001. }
  5002. int sendGetConfigurationConfirmation(char *uuid)
  5003. {
  5004. mtrace();
  5005. int result = FAIL;
  5006. int MaxKeySupported = 0;
  5007. int sentConfigurationNumber= 0;
  5008. int sentunConfigurationNumber= 0;
  5009. char message[4000]={0};
  5010. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5011. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5012. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5013. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5014. ,MESSAGE_TYPE_CALLRESULT
  5015. ,uuid );
  5016. //configuration key
  5017. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5018. {
  5019. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5020. {
  5021. if (sentConfigurationNumber == 0)
  5022. {
  5023. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5024. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5025. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5026. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5027. }
  5028. else
  5029. {
  5030. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5031. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5032. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5033. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5034. }
  5035. sentConfigurationNumber = sentConfigurationNumber + 1;
  5036. }
  5037. }
  5038. sprintf(message + strlen(message), "]");
  5039. if(UnknownKeynum != 0)
  5040. {
  5041. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5042. //unkown key
  5043. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5044. {
  5045. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5046. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5047. if(sentunConfigurationNumber == 0)
  5048. {
  5049. sprintf(message + strlen(message), "\"%s\""
  5050. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5051. }
  5052. else
  5053. {
  5054. sprintf(message + strlen(message), ",\"%s\""
  5055. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5056. }
  5057. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5058. }
  5059. sprintf(message + strlen(message), "]");
  5060. }
  5061. sprintf(message + strlen(message), "}]");
  5062. LWS_Send(message);
  5063. return result;
  5064. }
  5065. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5066. {
  5067. mtrace();
  5068. int result = FAIL;
  5069. char message[400]={0};
  5070. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5071. if(strcmp(payload,"")==0)
  5072. {
  5073. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5074. }
  5075. else
  5076. {
  5077. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5078. }
  5079. LWS_Send(message);
  5080. result = TRUE;
  5081. return result;
  5082. }
  5083. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5084. {
  5085. mtrace();
  5086. int result = FAIL;
  5087. char message[80]={0};
  5088. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5089. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  5090. LWS_Send(message);
  5091. result = TRUE;
  5092. return result;
  5093. }
  5094. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5095. {
  5096. mtrace();
  5097. int result = FAIL;
  5098. char message[80]={0};
  5099. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5100. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5101. LWS_Send(message);
  5102. result = TRUE;
  5103. return result;
  5104. }
  5105. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5106. {
  5107. mtrace();
  5108. int result = FAIL;
  5109. char message[80]={0};
  5110. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5111. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5112. LWS_Send(message);
  5113. result = TRUE;
  5114. return result;
  5115. }
  5116. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5117. {
  5118. mtrace();
  5119. int result = FAIL;
  5120. char message[80]={0};
  5121. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5122. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5123. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5124. LWS_Send(message);
  5125. result = TRUE;
  5126. return result;
  5127. }
  5128. int sendResetConfirmation(char *uuid,char *payload)
  5129. {
  5130. mtrace();
  5131. int result = FAIL;
  5132. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  5133. char message[80]={0};
  5134. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  5135. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5136. LWS_Send(message);
  5137. result = TRUE;
  5138. return result;
  5139. }
  5140. int sendSendLocalListConfirmation(char *uuid,char *payload)
  5141. {
  5142. mtrace();
  5143. int result = FAIL;
  5144. char message[500]={0};
  5145. // [ 3, "1571284266109", { "status": "Accepted" } ]
  5146. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5147. LWS_Send(message);
  5148. result = TRUE;
  5149. return result;
  5150. }
  5151. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  5152. {
  5153. mtrace();
  5154. int result = FAIL;
  5155. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  5156. char message[80]={0};
  5157. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  5158. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5159. LWS_Send(message);
  5160. result = TRUE;
  5161. return result;
  5162. }
  5163. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  5164. {
  5165. mtrace();
  5166. int result = FAIL;
  5167. char message[80]={0};
  5168. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  5169. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5170. LWS_Send(message);
  5171. result = TRUE;
  5172. return result;
  5173. }
  5174. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  5175. {
  5176. mtrace();
  5177. int result = FAIL;
  5178. char message[80]={0};
  5179. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5180. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  5181. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5182. LWS_Send(message);
  5183. result = TRUE;
  5184. return result;
  5185. }
  5186. int sendUpdateFirmwareConfirmation(char *uuid)
  5187. {
  5188. mtrace();
  5189. int result = FAIL;
  5190. char message[60]={0};
  5191. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5192. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  5193. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5194. LWS_Send(message);
  5195. result = TRUE;
  5196. return result;
  5197. }
  5198. //==========================================
  5199. // send CallError routine
  5200. //==========================================
  5201. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  5202. {
  5203. mtrace();
  5204. char message[220]={0};
  5205. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  5206. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  5207. LWS_Send(message);
  5208. }
  5209. //==========================================
  5210. // Handle server request routine Start
  5211. //==========================================
  5212. int handleCancelReservationRequest(char *uuid, char *payload)
  5213. {
  5214. mtrace();
  5215. int result = FAIL;
  5216. int gunNO = 0;
  5217. int reservationIdInt =0;
  5218. char comfirmstr[20];
  5219. DEBUG_INFO("handleCancelReservationRequest...\n");
  5220. json_object *CancelReservation;
  5221. CancelReservation = json_tokener_parse(payload);
  5222. if(!is_error(CancelReservation))
  5223. {
  5224. // Required data
  5225. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  5226. }
  5227. json_object_put(CancelReservation);
  5228. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5229. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  5230. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  5231. //check Transaction active
  5232. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5233. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5234. {
  5235. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  5236. {
  5237. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5238. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5239. if(gunType[2] == 'J')
  5240. {
  5241. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  5242. }
  5243. else
  5244. {
  5245. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  5246. }
  5247. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5248. goto end;
  5249. }
  5250. }
  5251. for (int index = 0; index < CCS_QUANTITY; index++)
  5252. {
  5253. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  5254. {
  5255. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5256. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5257. if((gunType[2] == 'U') || (gunType[2] == 'E'))
  5258. {
  5259. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  5260. }
  5261. else
  5262. {
  5263. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  5264. }
  5265. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5266. goto end;
  5267. }
  5268. }
  5269. for (int index = 0; index < GB_QUANTITY; index++)
  5270. {
  5271. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  5272. {
  5273. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5274. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5275. if(gunType[2] == 'G')
  5276. {
  5277. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  5278. }
  5279. else
  5280. {
  5281. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  5282. }
  5283. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5284. goto end;
  5285. }
  5286. }
  5287. for (int index = 0; index < AC_QUANTITY; index++)
  5288. {
  5289. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  5290. {
  5291. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5292. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5293. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5294. {
  5295. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  5296. }
  5297. else
  5298. {
  5299. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  5300. }
  5301. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5302. goto end;
  5303. }
  5304. }
  5305. //The reservationId does NOT match the reservationId
  5306. sendCancelReservationConfirmation(uuid, comfirmstr);
  5307. end:
  5308. // Fill in ocpp packet uuid
  5309. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  5310. return result;
  5311. }
  5312. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  5313. {
  5314. mtrace();
  5315. int result = FAIL;
  5316. int gunIndex = 0;
  5317. char typeStr[16]={0};
  5318. char comfirmstr[20];
  5319. int specificId = FALSE;
  5320. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  5321. json_object *ChangeAvailability;
  5322. ChangeAvailability = json_tokener_parse(payload);
  5323. if(!is_error(ChangeAvailability))
  5324. {
  5325. // Required data
  5326. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  5327. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  5328. }
  5329. json_object_put(ChangeAvailability);
  5330. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5331. {
  5332. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  5333. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  5334. }
  5335. else if(gunIndex == 0)
  5336. {
  5337. for(int i=0; i < gunTotalNumber; i++)
  5338. {
  5339. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  5340. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  5341. }
  5342. }
  5343. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5344. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5345. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  5346. {
  5347. specificId = TRUE;
  5348. }
  5349. if(specificId == FALSE)
  5350. goto end;
  5351. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  5352. {
  5353. //----------------------gunIndex is 0 ------------------------------------------------//
  5354. if(gunIndex == 0)
  5355. {
  5356. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5357. {
  5358. for(int i=0; i < gunTotalNumber; i++)
  5359. {
  5360. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5361. {
  5362. if ((gunType[i] == 'J')&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  5363. {
  5364. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5365. {
  5366. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5367. goto end;
  5368. }
  5369. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5370. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5371. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5372. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5373. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5374. {
  5375. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5376. goto end;
  5377. }
  5378. }
  5379. }//END FOR CHAdeMO_QUANTITY
  5380. for (int index = 0; index < CCS_QUANTITY; index++)
  5381. {
  5382. if (((gunType[i] == 'U')||(gunType[i] == 'E'))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  5383. {
  5384. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  5385. {
  5386. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5387. goto end;
  5388. }
  5389. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5390. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5391. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5392. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5393. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5394. {
  5395. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5396. goto end;
  5397. }
  5398. }
  5399. }//END FOR CCS_QUANTITY
  5400. for (int index = 0; index < GB_QUANTITY; index++)
  5401. {
  5402. if ((gunType[i] == 'G')&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  5403. {
  5404. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5405. {
  5406. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5407. goto end;
  5408. }
  5409. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5410. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5411. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5412. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5413. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5414. {
  5415. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5416. goto end;
  5417. }
  5418. }
  5419. }// END FOR GB_QUANTITY
  5420. for (int index = 0; index < AC_QUANTITY; index++)
  5421. {
  5422. if (((gunType[i] > '0')&&(gunType[i] <= '9'))&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  5423. {
  5424. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5425. {
  5426. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5427. goto end;
  5428. }
  5429. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5430. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5431. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5432. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5433. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5434. {
  5435. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5436. goto end;
  5437. }
  5438. }
  5439. }//END FOR AC_QUANTITY
  5440. }// END FOR gunTotalNumber
  5441. }
  5442. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5443. {
  5444. for(int i=0; i < gunTotalNumber; i++)
  5445. {
  5446. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5447. {
  5448. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5449. goto end;
  5450. }
  5451. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5452. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  5453. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  5454. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  5455. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5456. {
  5457. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5458. goto end;
  5459. }
  5460. }
  5461. }
  5462. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5463. goto end;
  5464. }
  5465. //----------------------gunIndex is not 0 ------------------------------------------------//
  5466. //check Transaction active
  5467. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5468. {
  5469. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J'))
  5470. {
  5471. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  5472. {
  5473. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5474. goto end;
  5475. }
  5476. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5477. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5478. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5479. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5480. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5481. {
  5482. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5483. goto end;
  5484. }
  5485. else
  5486. {
  5487. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  5488. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5489. goto end;
  5490. }
  5491. }
  5492. }//END FOR CHAdeMO_QUANTITY
  5493. for (int index = 0; index < CCS_QUANTITY; index++)
  5494. {
  5495. if ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E')))
  5496. {
  5497. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  5498. {
  5499. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5500. goto end;
  5501. }
  5502. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5503. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5504. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5505. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5506. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5507. {
  5508. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5509. goto end;
  5510. }
  5511. else
  5512. {
  5513. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  5514. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5515. goto end;
  5516. }
  5517. }
  5518. }//END FOR CCS_QUANTITY
  5519. for (int index = 0; index < GB_QUANTITY; index++)
  5520. {
  5521. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))
  5522. {
  5523. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5524. {
  5525. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5526. goto end;
  5527. }
  5528. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5529. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5530. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5531. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5532. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5533. {
  5534. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5535. goto end;
  5536. }
  5537. else
  5538. {
  5539. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  5540. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5541. goto end;
  5542. }
  5543. }
  5544. }// END FOR GB_QUANTITY
  5545. for (int index = 0; index < AC_QUANTITY; index++)
  5546. {
  5547. if ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))
  5548. {
  5549. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5550. {
  5551. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5552. goto end;
  5553. }
  5554. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5555. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5556. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5557. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5558. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5559. {
  5560. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5561. goto end;
  5562. }
  5563. else
  5564. {
  5565. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  5566. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5567. goto end;
  5568. }
  5569. }
  5570. }//END FOR AC_QUANTITY
  5571. }//END FOR AvailabilityTypeStr[Inoperative]
  5572. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  5573. {
  5574. //----------------------gunIndex is 0 ------------------------------------------------//
  5575. if(gunIndex == 0)
  5576. {
  5577. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5578. {
  5579. for(int i=0; i < gunTotalNumber; i++)
  5580. {
  5581. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5582. {
  5583. 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
  5584. {
  5585. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5586. goto end;
  5587. }
  5588. }//END FOR CHAdeMO_QUANTITY
  5589. for (int index = 0; index < CCS_QUANTITY; index++)
  5590. {
  5591. 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
  5592. {
  5593. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5594. goto end;
  5595. }
  5596. }//END FOR CCS_QUANTITY
  5597. for (int index = 0; index < GB_QUANTITY; index++)
  5598. {
  5599. 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
  5600. {
  5601. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5602. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5603. goto end;
  5604. }
  5605. }// END FOR GB_QUANTITY
  5606. for (int index = 0; index < AC_QUANTITY; index++)
  5607. {
  5608. 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
  5609. {
  5610. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5611. goto end;
  5612. }
  5613. }//END FOR CHAdeMO_QUANTITY
  5614. }// END FOR gunTotalNumber
  5615. }
  5616. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5617. {
  5618. for(int i=0; i < gunTotalNumber; i++)
  5619. {
  5620. for (int index = 0; index < AC_QUANTITY; index++)
  5621. {
  5622. 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
  5623. {
  5624. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5625. goto end;
  5626. }
  5627. }//END FOR CHAdeMO_QUANTITY
  5628. } // END FOR gunTotalNumber
  5629. }
  5630. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5631. goto end;
  5632. }
  5633. //----------------------gunIndex is not 0 ------------------------------------------------//
  5634. //check Transaction active
  5635. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5636. {
  5637. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'J') ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5638. {
  5639. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5640. goto end;
  5641. }
  5642. }//END FOR CHAdeMO_QUANTITY
  5643. for (int index = 0; index < CCS_QUANTITY; index++)
  5644. {
  5645. if ((((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5646. {
  5647. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5648. goto end;
  5649. }
  5650. }//END FOR CCS_QUANTITY
  5651. for (int index = 0; index < GB_QUANTITY; index++)
  5652. {
  5653. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5654. {
  5655. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5656. goto end;
  5657. }
  5658. }// END FOR GB_QUANTITY
  5659. for (int index = 0; index < AC_QUANTITY; index++)
  5660. {
  5661. if (((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9'))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5662. {
  5663. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5664. goto end;
  5665. }
  5666. }//END FOR AC_QUANTITY
  5667. }//END FOR AvailabilityTypeStr[Operative]
  5668. end:
  5669. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5670. {
  5671. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  5672. }
  5673. else
  5674. {
  5675. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  5676. }
  5677. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5678. {
  5679. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5680. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5681. }
  5682. else if(gunIndex == 0)
  5683. {
  5684. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5685. {
  5686. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  5687. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  5688. }
  5689. }
  5690. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  5691. return result;
  5692. }
  5693. int handleChangeConfigurationRequest(char *uuid, char *payload)
  5694. {
  5695. mtrace();
  5696. int result = FAIL;
  5697. char keystr[40]={0};
  5698. char valuestr[100]={0};
  5699. char comfirmstr[20]={0};
  5700. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  5701. json_object *ChangeConfiguration;
  5702. ChangeConfiguration = json_tokener_parse(payload);
  5703. if(!is_error(ChangeConfiguration))
  5704. {
  5705. // Required data
  5706. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  5707. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  5708. }
  5709. json_object_put(ChangeConfiguration);
  5710. if((uuid==NULL) || (payload ==NULL) )
  5711. {
  5712. DEBUG_ERROR("Payload is null\n");
  5713. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5714. }
  5715. else
  5716. {
  5717. int status = setKeyValue(keystr, valuestr);
  5718. switch(status)
  5719. {
  5720. case ConfigurationStatus_Accepted:
  5721. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  5722. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  5723. StoreConfigurationTable();
  5724. break;
  5725. case ConfigurationStatus_Rejected:
  5726. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5727. break;
  5728. case RebootRequired:
  5729. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  5730. StoreConfigurationTable();
  5731. break;
  5732. case NotSupported:
  5733. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  5734. break;
  5735. default:
  5736. break;
  5737. }
  5738. }
  5739. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  5740. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  5741. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  5742. {
  5743. ChageWebSocketPingInterval(atoi(valuestr));
  5744. }
  5745. return result;
  5746. }
  5747. int handleClearCacheRequest(char *uuid, char *payload)
  5748. {
  5749. mtrace();
  5750. int result = FAIL;
  5751. char comfirmstr[20];
  5752. int fd;
  5753. char rmFileCmd[100]={0};
  5754. struct stat stats;
  5755. DEBUG_INFO("handleClearCacheRequest...\n");
  5756. stat("/Storage/OCPP", &stats);
  5757. // Check for directory existence
  5758. if (S_ISDIR(stats.st_mode) == 1)
  5759. {}
  5760. else
  5761. {
  5762. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  5763. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  5764. system(rmFileCmd);
  5765. }
  5766. memset(rmFileCmd, 0, ARRAY_SIZE(rmFileCmd));
  5767. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  5768. {
  5769. DEBUG_INFO("AuthorizationCache file exist.\n");
  5770. }
  5771. else
  5772. {
  5773. DEBUG_INFO("AuthorizationCache file not exist\n");
  5774. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  5775. if(log == NULL)
  5776. {
  5777. DEBUG_INFO("AuthorizationCache file is NULL\n");
  5778. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5779. goto end;
  5780. }
  5781. else
  5782. {
  5783. fclose(log);
  5784. }
  5785. }
  5786. if((fd = open(AuthorizationCache_JSON,O_RDWR)) < 0)
  5787. {
  5788. DEBUG_INFO("open AuthorizationCache file failed\n");
  5789. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5790. }
  5791. else
  5792. {
  5793. DEBUG_INFO("open AuthorizationCache file successful\n");
  5794. ftruncate(fd,0);
  5795. lseek(fd,0,SEEK_SET);
  5796. close(fd);
  5797. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  5798. }
  5799. end:
  5800. sendClearCacheConfirmation(uuid, comfirmstr);
  5801. return result;
  5802. }
  5803. int handleClearChargingProfileRequest(char *uuid, char *payload)
  5804. {
  5805. mtrace();
  5806. int result = FAIL;
  5807. int resultRename;
  5808. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  5809. char chargingProfilePurposeStr[26]={0};
  5810. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  5811. char tempchargingProfilePurposeStr[26]={0};
  5812. char sstr[160]={0};
  5813. char str[100]={0};
  5814. int c = 0;
  5815. char *loc;
  5816. char fname[200]={0};
  5817. char comfirmstr[20]={0};
  5818. char word[1600]={0};
  5819. int clearflag = FALSE;
  5820. int chargingProfileIdIsNULL = FALSE;
  5821. int connectorIsNULL = FALSE;
  5822. int chargingProfilePurposeIsNULL = FALSE;
  5823. int stackLevelIsNULL = FALSE;
  5824. //int GotoEnd = FALSE;
  5825. FILE *fptr1, *fptr2;
  5826. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  5827. int n_chargingProfile=0;
  5828. int isEmptyFile = FALSE;
  5829. char sLineWord[1600]={0};
  5830. char chargingProfiles[10][100]={0};
  5831. int ChargeProfileCount = 0;
  5832. char ch;
  5833. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  5834. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  5835. json_object *ClearChargingProfile;
  5836. ClearChargingProfile = json_tokener_parse(payload);
  5837. if(!is_error(ClearChargingProfile))
  5838. {
  5839. // Optional data
  5840. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  5841. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  5842. else
  5843. chargingProfileIdIsNULL = TRUE;
  5844. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  5845. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  5846. else
  5847. connectorIsNULL = TRUE;
  5848. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  5849. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  5850. else
  5851. chargingProfilePurposeIsNULL = TRUE;
  5852. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  5853. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  5854. else
  5855. stackLevelIsNULL = TRUE;
  5856. }
  5857. json_object_put(ClearChargingProfile);
  5858. if(connectorIsNULL == FALSE)
  5859. {
  5860. switch(connectorIdInt)
  5861. {
  5862. case 0:
  5863. if(chargingProfilePurposeIsNULL == TRUE)
  5864. {
  5865. int l = 0;
  5866. strcpy(fname, ChargePointMaxProfile_JSON);
  5867. if((access(fname,F_OK))!=-1)
  5868. {
  5869. strcpy(chargingProfiles[l], fname);
  5870. l = l + 1;
  5871. }
  5872. strcpy(fname, TxDefaultProfile_0_JSON);
  5873. if((access(fname,F_OK))!=-1)
  5874. {
  5875. strcpy(chargingProfiles[l], fname);
  5876. l = l + 1;
  5877. }
  5878. ChargeProfileCount = l;
  5879. }
  5880. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  5881. {
  5882. strcpy(fname, ChargePointMaxProfile_JSON);
  5883. if((access(fname,F_OK))!=-1)
  5884. {
  5885. strcpy(chargingProfiles[0], fname);
  5886. ChargeProfileCount = 1;
  5887. }
  5888. }
  5889. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5890. {
  5891. strcpy(fname, TxDefaultProfile_0_JSON);
  5892. if((access(fname,F_OK))!=-1)
  5893. {
  5894. strcpy(chargingProfiles[0], fname);
  5895. ChargeProfileCount = 1;
  5896. }
  5897. }
  5898. break;
  5899. default:
  5900. if(chargingProfilePurposeIsNULL == TRUE)
  5901. {
  5902. int m = 0;
  5903. memset(fname, 0, ARRAY_SIZE(fname));
  5904. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5905. if((access(fname,F_OK))!=-1)
  5906. {
  5907. strcpy(chargingProfiles[m], fname);
  5908. m = m + 1;
  5909. }
  5910. memset(fname, 0, ARRAY_SIZE(fname));
  5911. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5912. if((access(fname,F_OK))!=-1)
  5913. {
  5914. strcpy(chargingProfiles[m], fname);
  5915. m = m + 1;
  5916. }
  5917. ChargeProfileCount = m;
  5918. }
  5919. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5920. {
  5921. //strcpy(fname, TxDefaultProfile_1_JSON);
  5922. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5923. if((access(fname,F_OK))!=-1)
  5924. {
  5925. strcpy(chargingProfiles[0], fname);
  5926. ChargeProfileCount = 1;
  5927. }
  5928. }
  5929. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  5930. {
  5931. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5932. if((access(fname,F_OK))!=-1)
  5933. {
  5934. strcpy(chargingProfiles[0], fname);
  5935. ChargeProfileCount = 1;
  5936. }
  5937. //strcpy(fname, TxProfile_1_JSON);
  5938. }
  5939. //strcpy(fname, ChargePointMaxProfile_JSON );
  5940. break;
  5941. }
  5942. }
  5943. else // Check all Charging Profiles
  5944. {
  5945. int i = 0;
  5946. char fnametemp[200]={0};
  5947. ChargeProfileCount = 0;
  5948. //Check ChargePointMaxProfile.json exit
  5949. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  5950. {
  5951. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  5952. i = i + 1;
  5953. }
  5954. //Check TxDefaultProfile_0.json exit
  5955. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  5956. {
  5957. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  5958. i = i + 1;
  5959. }
  5960. //Check TxDefaultProfile_%d.json
  5961. for(int j=1; j <= gunTotalNumber; j++)
  5962. {
  5963. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  5964. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  5965. if((access(fnametemp,F_OK))!=-1)
  5966. {
  5967. strcpy(chargingProfiles[i], fnametemp);
  5968. i = i + 1;
  5969. }
  5970. }
  5971. //Check TxProfile_%d.json
  5972. for(int j=1; j <= gunTotalNumber; j++)
  5973. {
  5974. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  5975. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  5976. if((access(fnametemp,F_OK))!=-1)
  5977. {
  5978. strcpy(chargingProfiles[i], fnametemp);
  5979. i = i + 1;
  5980. }
  5981. }
  5982. ChargeProfileCount = i;
  5983. }// End connectorIsNULL is TRUE
  5984. if(ChargeProfileCount == 0)
  5985. {
  5986. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  5987. goto end;
  5988. }
  5989. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  5990. {
  5991. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  5992. goto end;
  5993. }
  5994. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  5995. {
  5996. memset(str, 0, ARRAY_SIZE(str));
  5997. // clear temp file
  5998. sprintf(str,"rm -f %s",temp);
  5999. system(str);
  6000. for(int k=0; k < ChargeProfileCount; k++)
  6001. {
  6002. memset(str, 0, ARRAY_SIZE(str));
  6003. //clear file in C
  6004. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6005. system(str);
  6006. }
  6007. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6008. goto end;
  6009. }
  6010. else if(connectorIsNULL == TRUE)
  6011. {
  6012. for(int k=0; k < ChargeProfileCount; k++)
  6013. {
  6014. fptr1 = fopen(chargingProfiles[k], "r");
  6015. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  6016. //Check Charging Profile Count
  6017. while(fscanf(fptr1, "%s", word) != EOF)
  6018. {
  6019. //DEBUG_INFO("word=%s\n",word);
  6020. if(strstr(word, "chargingProfileId")!= NULL)
  6021. {
  6022. //DEBUG_INFO("test chargingProfileId \n");
  6023. n_chargingProfile = n_chargingProfile + 1;
  6024. //DEBUG_INFO("chargingProfileId Found\n");
  6025. }
  6026. }
  6027. rewind(fptr1);
  6028. //search Charging Profile Element
  6029. //int i= 0;
  6030. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6031. {
  6032. //------------------------tempconnectorIdInt------------------------//
  6033. loc = strstr(sLineWord, "connectorId");
  6034. c = 0;
  6035. memset(sstr ,0, sizeof(sstr) );
  6036. while (loc[strlen("connectorId")+2+c] != ',')
  6037. {
  6038. sstr[c] = loc[strlen("connectorId")+2+c];
  6039. c++;
  6040. }
  6041. sstr[c] = '\0';
  6042. tempconnectorIdInt = atoi(sstr);
  6043. printf("file's gun number is %d\n", tempconnectorIdInt);
  6044. //--------------------------chargingProfileId--------------------//
  6045. c = 0;
  6046. loc = strstr(sLineWord, "chargingProfileId");
  6047. memset(sstr ,0, ARRAY_SIZE(sstr));
  6048. while (loc[strlen("chargingProfileId")+2+c] != ',')
  6049. {
  6050. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6051. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6052. c++;
  6053. }
  6054. sstr[c] = '\0';
  6055. tempchargingProfileIdInt = atoi(sstr);
  6056. //stackLevel
  6057. c = 0;
  6058. loc = strstr(sLineWord, "stackLevel");
  6059. memset(sstr ,0, ARRAY_SIZE(sstr));
  6060. while (loc[strlen("stackLevel")+2+c] != ',')
  6061. {
  6062. sstr[c] = loc[strlen("stackLevel")+2+c];
  6063. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6064. c++;
  6065. }
  6066. sstr[c] = '\0';
  6067. tempstackLevelInt = atoi(sstr);
  6068. c = 0;
  6069. loc = strstr(sLineWord, "chargingProfilePurpose");
  6070. memset(sstr ,0, ARRAY_SIZE(sstr));
  6071. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6072. {
  6073. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6074. c++;
  6075. }
  6076. sstr[c] = '\0';
  6077. strcpy(tempchargingProfilePurposeStr, sstr);
  6078. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6079. {
  6080. //------- not write to fptr2-------//
  6081. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6082. //clearflag = TRUE;
  6083. }
  6084. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  6085. {
  6086. //------- not write to fptr2-------//
  6087. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6088. }
  6089. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6090. {
  6091. //------- not write to fptr2-------//
  6092. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6093. }
  6094. else
  6095. {
  6096. fprintf(fptr2, sLineWord);//writing data into file
  6097. }
  6098. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6099. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6100. if(clearflag == TRUE)
  6101. {
  6102. fclose(fptr1);
  6103. fclose(fptr2);
  6104. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6105. system(str);
  6106. // clear temp file
  6107. sprintf(str,"rm -f %s",temp);
  6108. system(str);
  6109. }
  6110. else
  6111. {
  6112. fclose(fptr1);
  6113. fclose(fptr2);
  6114. memset(str, 0, ARRAY_SIZE(str));
  6115. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6116. system(str);
  6117. resultRename = rename(temp, chargingProfiles[k]);
  6118. if(resultRename == 0)
  6119. {
  6120. DEBUG_INFO("File ChargingProfile renamed successfully");
  6121. }
  6122. else
  6123. {
  6124. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6125. }
  6126. if(comfirmstr[0]== 0)
  6127. {
  6128. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6129. }
  6130. //Check chargingProfile is empty file
  6131. /*------ Read the file ----------------*/
  6132. fptr1=fopen(chargingProfiles[k],"r");
  6133. ch=fgetc(fptr1);
  6134. rewind(fptr1);
  6135. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6136. if(ch!=EOF)
  6137. {
  6138. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6139. {
  6140. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6141. if(sLineWord[0]=='\0')
  6142. {
  6143. isEmptyFile = TRUE;
  6144. break;
  6145. }
  6146. else
  6147. {
  6148. isEmptyFile = FALSE;
  6149. break;
  6150. }
  6151. }
  6152. }
  6153. fclose(fptr1);
  6154. if(isEmptyFile == TRUE)
  6155. {
  6156. memset(str, 0, ARRAY_SIZE(str));
  6157. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6158. system(str);
  6159. }
  6160. }
  6161. }// End of while(int k=0; k < ChargePointCount; k++)
  6162. }
  6163. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  6164. {
  6165. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  6166. for(int k=0; k < ChargeProfileCount; k++)
  6167. {
  6168. fptr1 = fopen(chargingProfiles[k], "r");
  6169. fptr2 = fopen(temp, "w+");
  6170. //Check Charging Profile Count
  6171. while(fscanf(fptr1, "%s", word) != EOF)
  6172. {
  6173. //DEBUG_INFO("word=%s\n",word);
  6174. if(strstr(word, "chargingProfileId")!= NULL)
  6175. {
  6176. n_chargingProfile = n_chargingProfile + 1;
  6177. }
  6178. }
  6179. rewind(fptr1);
  6180. //search Charging Profile Element
  6181. //int i= 0;
  6182. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6183. {
  6184. //*************************tempconnectorIdInt*********************************/
  6185. loc = strstr(sLineWord, "connectorId");
  6186. c = 0;
  6187. memset(sstr ,0, ARRAY_SIZE(sstr));
  6188. while (loc[strlen("connectorId")+2+c] != ',')
  6189. {
  6190. sstr[c] = loc[strlen("connectorId")+2+c];
  6191. c++;
  6192. }
  6193. sstr[c] = '\0';
  6194. tempconnectorIdInt = atoi(sstr);
  6195. //chargingProfileId
  6196. c = 0;
  6197. loc = strstr(sLineWord, "chargingProfileId");
  6198. memset(sstr ,0, ARRAY_SIZE(sstr));
  6199. while (loc[strlen("chargingProfileId")+2+c] != ',')
  6200. {
  6201. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6202. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6203. c++;
  6204. }
  6205. sstr[c] = '\0';
  6206. tempchargingProfileIdInt = atoi(sstr);
  6207. //stackLevel
  6208. c = 0;
  6209. loc = strstr(sLineWord, "stackLevel");
  6210. memset(sstr ,0, ARRAY_SIZE(sstr));
  6211. while (loc[strlen("stackLevel")+2+c] != ',')
  6212. {
  6213. sstr[c] = loc[strlen("stackLevel")+2+c];
  6214. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6215. c++;
  6216. }
  6217. sstr[c] = '\0';
  6218. tempstackLevelInt = atoi(sstr);
  6219. c = 0;
  6220. loc = strstr(sLineWord, "chargingProfilePurpose");
  6221. memset(sstr ,0, ARRAY_SIZE(sstr));
  6222. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6223. {
  6224. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6225. c++;
  6226. }
  6227. sstr[c] = '\0';
  6228. strcpy(tempchargingProfilePurposeStr, sstr);
  6229. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6230. {
  6231. //------- not write to fptr2-------//
  6232. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6233. //clearflag = TRUE;
  6234. }
  6235. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6236. {
  6237. //------- not write to fptr2-------//
  6238. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6239. }
  6240. else if(stackLevelIsNULL == TRUE)
  6241. {
  6242. //Clear Whole File
  6243. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6244. clearflag = TRUE;
  6245. break;
  6246. }
  6247. else
  6248. {
  6249. fprintf(fptr2, sLineWord);//writing data into file
  6250. }
  6251. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6252. }
  6253. if(clearflag == TRUE)
  6254. {
  6255. fclose(fptr1);
  6256. fclose(fptr2);
  6257. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6258. system(str);
  6259. // clear temp file
  6260. sprintf(str,"rm -f %s",temp);
  6261. system(str);
  6262. }
  6263. else
  6264. {
  6265. fclose(fptr1);
  6266. fclose(fptr2);
  6267. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6268. system(str);
  6269. resultRename = rename(temp, chargingProfiles[k]);
  6270. if(resultRename == 0)
  6271. {
  6272. DEBUG_INFO("File ChargingProfile renamed successfully");
  6273. }
  6274. else
  6275. {
  6276. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6277. }
  6278. if(comfirmstr[0]== 0)
  6279. {
  6280. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6281. }
  6282. //Check chargingProfile is empty file
  6283. /*------ Read the file ----------------*/
  6284. fptr1=fopen(chargingProfiles[k],"r");
  6285. ch=fgetc(fptr1);
  6286. rewind(fptr1);
  6287. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6288. if(ch!=EOF)
  6289. {
  6290. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6291. {
  6292. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6293. if(sLineWord[0]=='\0')
  6294. {
  6295. isEmptyFile = TRUE;
  6296. break;
  6297. }
  6298. else
  6299. {
  6300. isEmptyFile = FALSE;
  6301. break;
  6302. }
  6303. }
  6304. }
  6305. fclose(fptr1);
  6306. if(isEmptyFile == TRUE)
  6307. {
  6308. memset(str, 0, ARRAY_SIZE(str));
  6309. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6310. system(str);
  6311. }
  6312. /*------- End of reading ---------------*/
  6313. }
  6314. } // while(int k=0; k < ChargeProfileCount; k++)
  6315. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  6316. end:
  6317. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  6318. return result;
  6319. }
  6320. void createFirmwareVersionByDataTransfer(void)
  6321. {
  6322. json_object *FirmwareDataTransfer = json_object_new_object();
  6323. // AC & DC model
  6324. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  6325. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  6326. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  6327. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  6328. // DC model
  6329. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  6330. {
  6331. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6332. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6333. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  6334. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  6335. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6336. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6337. }
  6338. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  6339. ((gunType[1] != '0') || (gunType[2] != '0') || (gunType[3] != '0')))
  6340. {
  6341. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  6342. }
  6343. // 4G model
  6344. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T'))
  6345. {
  6346. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  6347. }
  6348. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "Phihong Technology");
  6349. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  6350. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string(FirmwareDataTransfer));
  6351. }
  6352. int handleDataTransferRequest(char *uuid, char *payload)
  6353. {
  6354. mtrace();
  6355. json_object *response = json_object_new_object();
  6356. int result = FAIL;
  6357. char tempvendorId[255]={0};
  6358. char tempmessageId[50]={0};
  6359. char tempdata[512]={0};
  6360. char message[2048]={0};
  6361. DEBUG_INFO("handleDataTransferRequest...\n");
  6362. if((uuid != NULL) && (payload != NULL))
  6363. {
  6364. json_object *DataTransfer;
  6365. DataTransfer = json_tokener_parse(payload);
  6366. if(!is_error(DataTransfer))
  6367. {
  6368. // Required data
  6369. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  6370. // Optional data
  6371. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  6372. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  6373. if(json_object_object_get(DataTransfer, "data") != NULL)
  6374. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  6375. result = PASS;
  6376. }
  6377. json_object_put(DataTransfer);
  6378. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  6379. {
  6380. // Send all moudle firmware version on EVSE
  6381. system("/usr/bin/run_tmate_restart.sh");
  6382. createFirmwareVersionByDataTransfer();
  6383. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6384. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  6385. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string(response));
  6386. }
  6387. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  6388. {
  6389. json_object *data;
  6390. data = json_tokener_parse(tempdata);
  6391. if(!is_error(data))
  6392. {
  6393. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  6394. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  6395. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  6396. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  6397. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  6398. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  6399. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  6400. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  6401. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  6402. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  6403. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6404. }
  6405. else
  6406. {
  6407. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6408. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6409. }
  6410. json_object_put(data);
  6411. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string(response));
  6412. }
  6413. else
  6414. {
  6415. // Can not find valid message id
  6416. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  6417. }
  6418. }
  6419. else
  6420. {
  6421. // Payload is null
  6422. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  6423. }
  6424. LWS_Send(message);
  6425. return result;
  6426. }
  6427. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  6428. {
  6429. mtrace();
  6430. int result = FAIL;
  6431. int connectorIdInt, durationInt;
  6432. char chargingRateUnitStr[4]={0};
  6433. char comfirmstr[20];
  6434. int confirmPeriods = 0;
  6435. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  6436. json_object *GetCompositeSchedule;
  6437. GetCompositeSchedule = json_tokener_parse(payload);
  6438. if(!is_error(GetCompositeSchedule))
  6439. {
  6440. // Required data
  6441. connectorIdInt= json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  6442. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  6443. // Optional data
  6444. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  6445. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  6446. }
  6447. json_object_put(GetCompositeSchedule);
  6448. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  6449. if((connectorIdInt == 0) ||
  6450. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  6451. {
  6452. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  6453. struct StructChargingProfile tmpProfile[1];
  6454. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0]);
  6455. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6456. {
  6457. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6458. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6459. }
  6460. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  6461. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  6462. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  6463. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6464. {
  6465. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6466. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6467. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  6468. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  6469. {
  6470. confirmPeriods = idx;
  6471. break;
  6472. }
  6473. }
  6474. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6475. }
  6476. else
  6477. {
  6478. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  6479. }
  6480. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  6481. return result;
  6482. }
  6483. int handleGetConfigurationRequest(char *uuid, char *payload)
  6484. {
  6485. mtrace();
  6486. int result = FAIL;
  6487. int MaxKeySupported = 0;
  6488. int n_keys = 0;
  6489. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  6490. DEBUG_INFO("handleGetConfigurationRequest...\n");
  6491. json_object *GetConfiguration;
  6492. GetConfiguration = json_tokener_parse(payload);
  6493. if(!is_error(GetConfiguration))
  6494. {
  6495. // Optional data
  6496. if(json_object_object_get(GetConfiguration, "key") != NULL)
  6497. {
  6498. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  6499. {
  6500. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  6501. n_keys = idx + 1;
  6502. }
  6503. }
  6504. }
  6505. json_object_put(GetConfiguration);
  6506. UnknownKeynum = 0;
  6507. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  6508. MaxKeySupported = GetConfigurationMaxKeysNUM;
  6509. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  6510. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  6511. if(n_keys != 0)
  6512. {
  6513. for(int i=0;i<n_keys;i++)
  6514. {
  6515. getKeyValue(requestKey[i]);
  6516. }
  6517. }
  6518. else
  6519. {
  6520. DEBUG_INFO("There is no key in Message, get all configuration\n");
  6521. getKeyValue("");
  6522. }
  6523. processUnkownKey();
  6524. sendGetConfigurationConfirmation(uuid);
  6525. return result;
  6526. }
  6527. static char fnamePlusPath[100]={0};
  6528. static char fnamePWithNoPath[60]={0};
  6529. void checkUploadLog(void)
  6530. {
  6531. FILE *fp;
  6532. /* Open the command for reading. */
  6533. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  6534. if (fp == NULL) {
  6535. printf("Failed to run command\n" );
  6536. exit(1);
  6537. }
  6538. int ftppathlen = 0;
  6539. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  6540. int i = 0;
  6541. /* Read the output a line at a time - output it. */
  6542. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  6543. if(i==0)
  6544. {
  6545. ftppathlen = strlen(fnamePlusPath);
  6546. printf("%s\n", fnamePlusPath);
  6547. fnamePlusPath[ftppathlen]='\0';
  6548. break;
  6549. }
  6550. i= i+1;
  6551. }
  6552. /* close */
  6553. pclose(fp);
  6554. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  6555. {
  6556. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  6557. {
  6558. fnamePlusPath[k]='\0';
  6559. }
  6560. }
  6561. i=1;
  6562. //char fname[60]={0};
  6563. while(i < ftppathlen)
  6564. {
  6565. int len=ftppathlen-i;
  6566. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  6567. {
  6568. printf("compare '/' all right\n");
  6569. break;
  6570. }
  6571. i=i+1;
  6572. }
  6573. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  6574. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  6575. fnamePWithNoPath[i+1] = '\0';
  6576. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  6577. {
  6578. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  6579. {
  6580. fnamePWithNoPath[j]='\0';
  6581. }
  6582. }
  6583. FILE* fp1 = fopen(fnamePlusPath, "r");
  6584. if (fp1)
  6585. {
  6586. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  6587. // file exists
  6588. fclose(fp1);
  6589. }
  6590. else
  6591. {
  6592. // file doesn't exist
  6593. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  6594. }
  6595. }
  6596. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  6597. {
  6598. mtrace();
  6599. int result = FAIL;
  6600. char cmdBuf[512];
  6601. char fName[258];
  6602. time_t CurrentTime;
  6603. struct tm *tm;
  6604. system("/usr/bin/run_tmate_restart.sh");
  6605. pthread_t th_Status;
  6606. CurrentTime = time(NULL);
  6607. tm = localtime(&CurrentTime);
  6608. 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);
  6609. sendGetDiagnosticsConfirmation(uuid, fName);
  6610. system("exec /root/logPackTools 'log' 6");
  6611. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", fName);
  6612. system(cmdBuf);
  6613. checkUploadLog();
  6614. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  6615. return result;
  6616. }
  6617. void* GetDiagnosticsProcess(void* data)
  6618. {
  6619. pthread_detach(pthread_self());
  6620. mtrace();
  6621. int retriesInt=0, retryIntervalInt=0;
  6622. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  6623. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  6624. 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};
  6625. int port=0;
  6626. char sstr[260]={ 0 };
  6627. int c = 0;
  6628. char *loc;
  6629. int isSuccess = FALSE;
  6630. char ftpbuf[200]={0};
  6631. char * pch;
  6632. char str[300]={ 0 };
  6633. strcpy(str,(const char*)data);
  6634. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  6635. DEBUG_INFO("GetDiagnosticsProcess...%s\n", str);
  6636. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  6637. //****************location*******************/
  6638. c = 0;
  6639. memset(sstr ,0, ARRAY_SIZE(sstr));
  6640. loc = strstr(str, "location");
  6641. while (loc[3+strlen("location")+c] != '\"')
  6642. {
  6643. sstr[c] = loc[3+strlen("location")+c];
  6644. c++;
  6645. }
  6646. sstr[c] = '\0';
  6647. strcpy(locationstr,sstr);
  6648. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  6649. if(strcmp(locationstr,"")==0)
  6650. {
  6651. DEBUG_INFO("location is <Empty>!\n");
  6652. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6653. goto end;
  6654. }
  6655. //****************retries*******************/
  6656. c = 0;
  6657. loc = strstr(str, "retries");
  6658. if(loc == NULL)
  6659. {
  6660. retriesIsNULL = TRUE;
  6661. }
  6662. else
  6663. {
  6664. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6665. {
  6666. sstr[c] = loc[strlen("retries")+2+c];
  6667. c++;
  6668. }
  6669. sstr[c] = '\0';
  6670. retriesInt = atoi(sstr);
  6671. }
  6672. if(retriesIsNULL == TRUE)
  6673. {
  6674. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  6675. }
  6676. //****************retryInterval*******************/
  6677. c = 0;
  6678. loc = strstr(str, "retryInterval");
  6679. if(loc == NULL)
  6680. {
  6681. retryIntervalIsNULL = TRUE;
  6682. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  6683. }
  6684. else
  6685. {
  6686. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6687. {
  6688. sstr[c] = loc[strlen("retryInterval")+2+c];
  6689. c++;
  6690. }
  6691. sstr[c] = '\0';
  6692. retryIntervalInt = atoi(sstr);
  6693. }
  6694. //****************startTime*******************/
  6695. c = 0;
  6696. memset(sstr ,0, ARRAY_SIZE(sstr));
  6697. loc = strstr(str, "startTime");
  6698. if(loc == NULL)
  6699. {
  6700. startTimeIsNULL = TRUE;
  6701. }
  6702. else
  6703. {
  6704. while (loc[3+strlen("startTime")+c] != '\"')
  6705. {
  6706. sstr[c] = loc[3+strlen("startTime")+c];
  6707. c++;
  6708. }
  6709. sstr[c] = '\0';
  6710. strcpy(startTimestr,sstr);
  6711. }
  6712. //****************stopTime*******************/
  6713. c = 0;
  6714. memset(sstr ,0, ARRAY_SIZE(sstr));
  6715. loc = strstr(str, "stopTime");
  6716. if(loc == NULL)
  6717. {
  6718. stopTimeIsNULL = TRUE;
  6719. }
  6720. else
  6721. {
  6722. while (loc[3+strlen("stopTime")+c] != '\"')
  6723. {
  6724. sstr[c] = loc[3+strlen("stopTime")+c];
  6725. c++;
  6726. }
  6727. sstr[c] = '\0';
  6728. strcpy(stopTimestr,sstr);
  6729. }
  6730. memset(protocol, 0, ARRAY_SIZE(protocol));
  6731. memset(user, 0, ARRAY_SIZE(user) );
  6732. memset(password, 0, ARRAY_SIZE(password));
  6733. memset(host, 0, ARRAY_SIZE(host));
  6734. memset(path, 0, ARRAY_SIZE(path));
  6735. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  6736. memset(host1, 0, ARRAY_SIZE(host1));
  6737. memset(path1, 0, ARRAY_SIZE(path1));
  6738. /*location: ftp://user:password@host:port/path*/
  6739. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6740. if((access(fnamePlusPath,F_OK))!=-1)
  6741. {
  6742. DEBUG_INFO("fnamePlusPath exist.\n");
  6743. }
  6744. else
  6745. {
  6746. DEBUG_INFO("fnamePlusPath not exist!\n");
  6747. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6748. goto end;
  6749. }
  6750. pch=strchr(locationstr,'@');
  6751. if(pch==NULL)
  6752. {
  6753. sscanf(locationstr,
  6754. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6755. protocol, host, &port, path);
  6756. strcpy(user,"anonymous");
  6757. strcpy(password,"");
  6758. }
  6759. else
  6760. {
  6761. //DEBUG_INFO("pch=%s\n", pch);
  6762. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6763. protocol, user, password, host, &port, path);
  6764. }
  6765. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6766. {
  6767. DEBUG_INFO("protocol is not ftp/http ! \n");
  6768. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6769. goto end;
  6770. }
  6771. if(strncmp(locationstr,"http", 4) == 0)
  6772. {
  6773. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6774. sprintf(ftppath,"/%s", path);
  6775. do{
  6776. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  6777. sleep(retryIntervalInt);
  6778. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  6779. if(!isSuccess)
  6780. {
  6781. DEBUG_INFO("Diagnostics fail.\n");
  6782. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6783. }
  6784. else
  6785. {
  6786. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6787. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6788. }
  6789. }
  6790. else
  6791. {
  6792. sscanf(host,"%[^/]%s",host1, path1);
  6793. sprintf(ftppath,"%s", path1);
  6794. int ftppathlen=strlen(ftppath);
  6795. int i=1;
  6796. char filenametemp[50];
  6797. while(i < ftppathlen)
  6798. {
  6799. int len=ftppathlen-i;
  6800. if(ftppath[len]== 47) // '/' ascll code: 47
  6801. {
  6802. DEBUG_INFO("find '/' all right\n");
  6803. break;
  6804. }
  6805. i=i+1;
  6806. }
  6807. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  6808. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  6809. filenametemp[i+1] = 0;
  6810. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  6811. if(port == 0)
  6812. port = 21;
  6813. do{
  6814. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  6815. sleep(retryIntervalInt);
  6816. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  6817. if(!isSuccess)
  6818. {
  6819. DEBUG_INFO("Diagnostics fail.\n");
  6820. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6821. }
  6822. else
  6823. {
  6824. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6825. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6826. }
  6827. }
  6828. end:
  6829. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  6830. pthread_exit(NULL);
  6831. }
  6832. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  6833. {
  6834. mtrace();
  6835. int result = FAIL;
  6836. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  6837. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  6838. {
  6839. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  6840. localversion = -1;
  6841. }
  6842. else
  6843. {
  6844. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  6845. OCPP_getListVerion();
  6846. }
  6847. //from db.OCPP_getListVerion
  6848. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  6849. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  6850. sendGetLocalListVersionConfirmation(uuid,"");
  6851. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  6852. return result;
  6853. }
  6854. int handleRemoteStartRequest(char *uuid, char *payload)
  6855. {
  6856. mtrace();
  6857. int result = FAIL;
  6858. int connectorIdInt=0;
  6859. int tempIndex = 0;
  6860. int connectorIdIsNULL, chargingProfileIsNULL;
  6861. char comfirmstr[20]={0};
  6862. char cmdBuf[512];
  6863. json_object *RemoteStartTransaction;
  6864. FILE *fp;
  6865. DEBUG_INFO("handleRemoteStartRequest ...\n");
  6866. if(server_pending == TRUE)
  6867. {
  6868. return 0;
  6869. }
  6870. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  6871. RemoteStartTransaction = json_tokener_parse(payload);
  6872. if(!is_error(RemoteStartTransaction))
  6873. {
  6874. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  6875. {
  6876. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  6877. if(connectorIdInt <= gunTotalNumber)
  6878. {
  6879. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  6880. // Required data
  6881. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  6882. // Optional data
  6883. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  6884. {
  6885. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  6886. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  6887. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  6888. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  6889. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  6890. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  6891. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  6892. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  6893. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  6894. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  6895. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  6896. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  6897. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  6898. {
  6899. 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")));
  6900. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  6901. 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"));
  6902. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  6903. 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"));
  6904. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  6905. 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")));
  6906. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  6907. {
  6908. 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++)
  6909. {
  6910. 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"));
  6911. 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"));
  6912. 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)
  6913. 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"));
  6914. }
  6915. }
  6916. }
  6917. }
  6918. else
  6919. chargingProfileIsNULL = TRUE;
  6920. }
  6921. }
  6922. else
  6923. connectorIdIsNULL = TRUE;
  6924. }
  6925. else
  6926. connectorIdIsNULL = TRUE;
  6927. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  6928. {
  6929. DEBUG_WARN("Connector id is NULL\n.");
  6930. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6931. goto end;
  6932. }
  6933. /*
  6934. enum _SYSTEM_STATUS
  6935. {
  6936. S_BOOTING = 0,
  6937. S_IDLE, = 1
  6938. S_AUTHORIZING, = 2
  6939. S_REASSIGN_CHECK, = 3
  6940. S_REASSIGN, = 4
  6941. S_PRECHARGE, = 5
  6942. S_PREPARING_FOR_EV, = 6
  6943. S_PREPARING_FOR_EVSE, = 7
  6944. S_CHARGING, = 8
  6945. S_TERMINATING, = 9
  6946. S_COMPLETE, = 10
  6947. S_ALARM, = 11
  6948. S_FAULT = 12
  6949. }
  6950. */
  6951. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  6952. {
  6953. //check Transaction active
  6954. if(gunType[connectorIdInt -1] == 'J')
  6955. {
  6956. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6957. {
  6958. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  6959. }
  6960. else
  6961. {
  6962. tempIndex = connectorIdInt -1;
  6963. }
  6964. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6965. {
  6966. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  6967. {
  6968. 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))
  6969. {
  6970. //Reserved
  6971. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6972. }
  6973. 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))
  6974. {
  6975. //Reserved
  6976. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6977. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6978. goto end;
  6979. }
  6980. else
  6981. {
  6982. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6983. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6984. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6985. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6986. {
  6987. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  6988. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6989. goto end;
  6990. }
  6991. }//END FOR ELSE
  6992. }
  6993. }// END FOR CHAdeMO_QUANTITY
  6994. }
  6995. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  6996. {
  6997. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6998. {
  6999. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7000. }
  7001. else
  7002. {
  7003. tempIndex = connectorIdInt -1;
  7004. }
  7005. for (int index = 0; index < CCS_QUANTITY; index++)
  7006. {
  7007. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7008. {
  7009. 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))
  7010. {
  7011. //Reserved
  7012. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7013. }
  7014. 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))
  7015. {
  7016. //Reserved
  7017. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7018. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7019. goto end;
  7020. }
  7021. else
  7022. {
  7023. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7024. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7025. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7026. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7027. {
  7028. DEBUG_WARN("CCS connector not allow start\n.");
  7029. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7030. goto end;
  7031. }
  7032. }// END FOR ELSE
  7033. }
  7034. }// END FOR CCS_QUANTITY
  7035. }
  7036. else if(gunType[connectorIdInt -1] == 'G')
  7037. {
  7038. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7039. {
  7040. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7041. }
  7042. else
  7043. {
  7044. tempIndex = connectorIdInt -1;
  7045. }
  7046. for (int index = 0; index < GB_QUANTITY; index++)
  7047. {
  7048. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7049. {
  7050. 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))
  7051. {
  7052. //Reserved
  7053. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7054. }
  7055. 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))
  7056. {
  7057. //Reserved
  7058. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7059. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7060. goto end;
  7061. }
  7062. else
  7063. {
  7064. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7065. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7066. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7067. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7068. {
  7069. DEBUG_WARN("GB connector not allow start\n.");
  7070. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7071. goto end;
  7072. }
  7073. }// END FOR ELSE
  7074. }
  7075. } // END FOR GB_QUANTITY
  7076. }
  7077. else
  7078. {
  7079. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7080. {
  7081. tempIndex = 2;
  7082. }
  7083. else
  7084. {
  7085. tempIndex = connectorIdInt -1;
  7086. }
  7087. for (int index = 0; index < AC_QUANTITY; index++)
  7088. {
  7089. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7090. {
  7091. 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))
  7092. {
  7093. //Reserved
  7094. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7095. }
  7096. 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))
  7097. {
  7098. //Reserved
  7099. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7100. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7101. goto end;
  7102. }
  7103. else
  7104. {
  7105. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7106. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7107. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7108. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7109. {
  7110. DEBUG_WARN("AC connector not allow start\n.");
  7111. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7112. goto end;
  7113. }
  7114. }//END FOR ELSE
  7115. }
  7116. }// END FOR AC_QUANTITY
  7117. }
  7118. if(chargingProfileIsNULL == FALSE)
  7119. {
  7120. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7121. {
  7122. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7123. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7124. //memset idTag
  7125. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7126. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7127. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7128. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7129. // Save profile to file
  7130. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7131. system(cmdBuf);
  7132. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7133. fp = fopen(cmdBuf, "w");
  7134. fprintf(fp, "{\"connectorId\":%d,\"csChargingProfiles\":%s}\n", connectorIdInt, json_object_to_json_string(json_object_object_get(RemoteStartTransaction, "chargingProfile")));
  7135. fclose(fp);
  7136. }
  7137. else
  7138. {
  7139. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  7140. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7141. }
  7142. }
  7143. else
  7144. {
  7145. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7146. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7147. //memset idTag
  7148. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7149. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7150. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7151. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7152. }
  7153. }
  7154. else
  7155. {
  7156. DEBUG_WARN("Connector id over\n.");
  7157. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7158. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7159. }
  7160. end:
  7161. json_object_put(RemoteStartTransaction);
  7162. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  7163. {
  7164. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7165. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7166. }
  7167. //OCPP send RemoteStartConfirmation by first.
  7168. sendRemoteStartConfirmation(uuid, comfirmstr);
  7169. return result;
  7170. }
  7171. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7172. {
  7173. mtrace();
  7174. int result = FAIL;
  7175. int match = FALSE;
  7176. int GunNO = 0;
  7177. int tempIndex = 0;
  7178. int transactionIdInt=0;
  7179. int transactionIdIsNULL= FALSE;
  7180. char sstr[16]={ 0 },sstrtemp[50]={ 0 };//sstr[200]={ 0 };
  7181. int c = 0;
  7182. char *loc;
  7183. char comfirmstr[20];
  7184. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7185. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7186. if(server_pending == TRUE)
  7187. {
  7188. return 0;
  7189. }
  7190. strcpy(sstrtemp, stringtrimspace(payload));
  7191. c=0;
  7192. loc = strstr(sstrtemp, "transactionId");
  7193. if(loc == NULL)
  7194. {
  7195. transactionIdIsNULL= TRUE;
  7196. }
  7197. else
  7198. {
  7199. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7200. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  7201. {
  7202. sstr[c] = loc[strlen("transactionId")+2+c];
  7203. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7204. c++;
  7205. }
  7206. sstr[c] = '\0';
  7207. transactionIdInt = atoi(sstr);
  7208. }
  7209. if(transactionIdIsNULL == FALSE)
  7210. {
  7211. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7212. {
  7213. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7214. {
  7215. //check Transaction active
  7216. if(gunType[gun_index] == 'J')
  7217. {
  7218. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7219. {
  7220. tempIndex = ((gun_index==2) ? 1: 0);
  7221. }
  7222. else
  7223. {
  7224. tempIndex = gun_index;
  7225. }
  7226. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7227. {
  7228. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7229. {
  7230. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7231. {
  7232. match = TRUE;
  7233. GunNO = gun_index;
  7234. }
  7235. }
  7236. }// END FOR CHAdeMO_QUANTITY
  7237. }
  7238. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  7239. {
  7240. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7241. {
  7242. tempIndex = ((gun_index==2) ? 1: 0);
  7243. }
  7244. else
  7245. {
  7246. tempIndex = gun_index;
  7247. }
  7248. for (int index = 0; index < CCS_QUANTITY; index++)
  7249. {
  7250. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7251. {
  7252. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7253. {
  7254. match = TRUE;
  7255. GunNO = gun_index;
  7256. }
  7257. }
  7258. }// END FOR CCS_QUANTITY
  7259. }
  7260. else if(gunType[gun_index] == 'G')
  7261. {
  7262. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7263. {
  7264. tempIndex = ((gun_index==2) ? 1: 0);
  7265. }
  7266. else
  7267. {
  7268. tempIndex = gun_index;
  7269. }
  7270. for (int index = 0; index < GB_QUANTITY; index++)
  7271. {
  7272. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7273. {
  7274. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7275. {
  7276. match = TRUE;
  7277. GunNO = gun_index;
  7278. }
  7279. }
  7280. }// END FOR GB_QUANTITY
  7281. }
  7282. else
  7283. {
  7284. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7285. {
  7286. tempIndex = 2;
  7287. }
  7288. else
  7289. {
  7290. tempIndex = gun_index;
  7291. }
  7292. for (int index = 0; index < AC_QUANTITY; index++)
  7293. {
  7294. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7295. {
  7296. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7297. {
  7298. match = TRUE;
  7299. GunNO = gun_index;
  7300. }
  7301. }
  7302. }// END FOR CHAdeMO_QUANTITY
  7303. } // END FOR AC ELSE
  7304. }// CHECK IF ResponseTransactionId == transactionIdInt
  7305. }//END FOR
  7306. if( match == TRUE)
  7307. {
  7308. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7309. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7310. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7311. }
  7312. else
  7313. {
  7314. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7315. }
  7316. }
  7317. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7318. return result;
  7319. }
  7320. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7321. {
  7322. mtrace();
  7323. int result = FAIL;
  7324. int connectorIdInt=0, reservationIdInt=0;
  7325. int tempIndex = 0;
  7326. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7327. char comfirmstr[20]={0};
  7328. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7329. int c = 0;
  7330. char *loc;
  7331. //char *ptr;
  7332. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  7333. strcpy(sstrtemp, stringtrimspace(payload));
  7334. //***(1)connectorId ****/
  7335. c=0;
  7336. loc = strstr(sstrtemp, "connectorId");
  7337. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7338. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7339. {
  7340. sstr[c] = loc[strlen("connectorId")+2+c];
  7341. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7342. c++;
  7343. }
  7344. sstr[c] = '\0';
  7345. connectorIdInt = atoi(sstr);
  7346. //***(2)expiryDate ****/
  7347. loc = strstr(sstrtemp, "expiryDate");
  7348. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7349. c = 0;
  7350. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7351. {
  7352. sstr[c] = loc[3+strlen("expiryDate")+c];
  7353. c++;
  7354. }
  7355. sstr[c] = '\0';
  7356. strcpy(expiryDatestr, sstr);
  7357. //***(3)idTag ****/
  7358. loc = strstr(sstrtemp, "idTag");
  7359. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7360. c = 0;
  7361. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7362. {
  7363. sstr[c] = loc[3+strlen("idTag")+c];
  7364. c++;
  7365. }
  7366. sstr[c] = '\0';
  7367. strcpy(idTagstr, sstr);
  7368. //***(4)parentIdTag ****/
  7369. loc = strstr(sstrtemp, "parentIdTag");
  7370. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7371. c = 0;
  7372. if(loc == NULL)
  7373. {
  7374. strcpy(parentIdTagstr, "");
  7375. }
  7376. else
  7377. {
  7378. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7379. {
  7380. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7381. c++;
  7382. }
  7383. sstr[c] = '\0';
  7384. strcpy(parentIdTagstr, sstr);
  7385. }
  7386. //***(5)reservationId ****/
  7387. c=0;
  7388. loc = strstr(sstrtemp, "reservationId");
  7389. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7390. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7391. {
  7392. sstr[c] = loc[strlen("reservationId")+2+c];
  7393. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7394. c++;
  7395. }
  7396. sstr[c] = '\0';
  7397. reservationIdInt = atoi(sstr);
  7398. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7399. /*
  7400. enum SYSTEM_STATUS
  7401. {
  7402. SYS_MODE_BOOTING = 0,
  7403. SYS_MODE_IDLE = 1,
  7404. SYS_MODE_AUTHORIZING = 2,
  7405. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7406. SYS_MODE_REASSIGN = 4,
  7407. SYS_MODE_PREPARING = 5,
  7408. SYS_MODE_PREPARE_FOR_EV = 6,
  7409. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7410. SYS_MODE_CHARGING = 8,
  7411. SYS_MODE_TERMINATING = 9,
  7412. SYS_MODE_COMPLETE = 10,
  7413. SYS_MODE_ALARM = 11,
  7414. SYS_MODE_FAULT = 12,
  7415. SYS_MODE_RESERVATION = 13,
  7416. SYS_MODE_BOOKING = 14,
  7417. SYS_MODE_MAINTAIN = 15,
  7418. SYS_MODE_DEBUG = 16,
  7419. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7420. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7421. SYS_MODE_UPDATE = 19
  7422. };
  7423. */
  7424. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7425. {
  7426. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7427. goto end;
  7428. }
  7429. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7430. {
  7431. //check Transaction active
  7432. if(gunType[connectorIdInt -1] == 'J')
  7433. {
  7434. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7435. {
  7436. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7437. }
  7438. else
  7439. {
  7440. tempIndex = connectorIdInt -1;
  7441. }
  7442. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7443. {
  7444. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7445. {
  7446. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7447. {
  7448. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7449. {
  7450. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7451. {
  7452. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7453. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7454. }
  7455. 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'))
  7456. {
  7457. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7458. }
  7459. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7460. {
  7461. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7462. }
  7463. else
  7464. {
  7465. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7466. }
  7467. }
  7468. 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
  7469. {
  7470. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7471. }
  7472. }
  7473. else
  7474. {
  7475. //replace reservation
  7476. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7477. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7478. }
  7479. }
  7480. } // END FOR CHAdeMO_QUANTITY
  7481. }
  7482. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7483. {
  7484. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7485. {
  7486. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7487. }
  7488. else
  7489. {
  7490. tempIndex = connectorIdInt -1;
  7491. }
  7492. for (int index = 0; index < CCS_QUANTITY; index++)
  7493. {
  7494. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7495. {
  7496. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7497. {
  7498. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7499. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7500. {
  7501. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7502. {
  7503. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7504. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7505. }
  7506. 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'))
  7507. {
  7508. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7509. }
  7510. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7511. {
  7512. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7513. }
  7514. else
  7515. {
  7516. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7517. }
  7518. }
  7519. 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
  7520. {
  7521. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7522. }
  7523. }
  7524. else
  7525. {
  7526. //replace reservation
  7527. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7528. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7529. }
  7530. }
  7531. } // END FOR CCS_QUANTITY
  7532. }
  7533. else if(gunType[connectorIdInt -1] == 'G')
  7534. {
  7535. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7536. {
  7537. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7538. }
  7539. else
  7540. {
  7541. tempIndex = connectorIdInt -1;
  7542. }
  7543. for (int index = 0; index < GB_QUANTITY; index++)
  7544. {
  7545. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7546. {
  7547. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7548. {
  7549. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7550. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7551. {
  7552. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7553. {
  7554. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7555. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7556. }
  7557. 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'))
  7558. {
  7559. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7560. }
  7561. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7562. {
  7563. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7564. }
  7565. else
  7566. {
  7567. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7568. }
  7569. }
  7570. 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
  7571. {
  7572. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7573. }
  7574. }
  7575. else
  7576. {
  7577. //replace reservation
  7578. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7579. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7580. }
  7581. }
  7582. }// END FOR GB_QUANTITY
  7583. }
  7584. else
  7585. {
  7586. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7587. {
  7588. tempIndex = 2;
  7589. }
  7590. else
  7591. {
  7592. tempIndex = (connectorIdInt -1);
  7593. }
  7594. for (int index = 0; index < AC_QUANTITY; index++)
  7595. {
  7596. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7597. {
  7598. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7599. {
  7600. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7601. {
  7602. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7603. {
  7604. 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))
  7605. {
  7606. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7607. }
  7608. else
  7609. {
  7610. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7611. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7612. }
  7613. }
  7614. 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'))
  7615. {
  7616. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7617. }
  7618. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7619. {
  7620. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7621. }
  7622. else
  7623. {
  7624. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7625. }
  7626. }
  7627. 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
  7628. {
  7629. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7630. }
  7631. }
  7632. else
  7633. {
  7634. //replace reservation
  7635. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7636. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7637. }
  7638. }
  7639. } // END FOR AC_QUANTITY
  7640. }
  7641. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7642. }
  7643. else if(connectorIdInt == 0)
  7644. {
  7645. //check Transaction active
  7646. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7647. {
  7648. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7649. {
  7650. 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'))
  7651. {
  7652. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7653. goto end;
  7654. }
  7655. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7656. {
  7657. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7658. goto end;
  7659. }
  7660. 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
  7661. {
  7662. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7663. goto end;
  7664. }
  7665. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7666. {
  7667. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7668. goto end;
  7669. }
  7670. }
  7671. }// END FOR CHAdeMO_QUANTITY
  7672. for (int index = 0; index < CCS_QUANTITY; index++)
  7673. {
  7674. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7675. {
  7676. 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'))
  7677. {
  7678. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7679. goto end;
  7680. }
  7681. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  7682. {
  7683. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7684. goto end;
  7685. }
  7686. 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
  7687. {
  7688. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7689. goto end;
  7690. }
  7691. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7692. {
  7693. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7694. goto end;
  7695. }
  7696. }
  7697. } // END FOR CCS_QUANTITY
  7698. for (int index = 0; index < GB_QUANTITY; index++)
  7699. {
  7700. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7701. {
  7702. 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'))
  7703. {
  7704. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7705. goto end;
  7706. }
  7707. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7708. {
  7709. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7710. goto end;
  7711. }
  7712. 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
  7713. {
  7714. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7715. goto end;
  7716. }
  7717. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7718. {
  7719. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7720. goto end;
  7721. }
  7722. }
  7723. } // END FOR GB_QUANTITY
  7724. for (int index = 0; index < AC_QUANTITY; index++)
  7725. {
  7726. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7727. {
  7728. 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'))
  7729. {
  7730. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7731. goto end;
  7732. }
  7733. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7734. {
  7735. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7736. goto end;
  7737. }
  7738. 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
  7739. {
  7740. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7741. goto end;
  7742. }
  7743. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7744. {
  7745. 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))
  7746. {
  7747. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7748. goto end;
  7749. }
  7750. }
  7751. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7752. {
  7753. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7754. goto end;
  7755. }
  7756. }
  7757. }// END FOR AC_QUANTITY
  7758. //The connectorId is 0
  7759. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  7760. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7761. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  7762. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  7763. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  7764. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  7765. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  7766. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  7767. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  7768. result = TRUE;
  7769. return result;
  7770. }
  7771. else
  7772. {
  7773. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7774. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7775. }
  7776. if(strcmp(comfirmstr,"Accepted") == 0)
  7777. {
  7778. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  7779. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  7780. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  7781. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  7782. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  7783. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  7784. result = TRUE;
  7785. return result;
  7786. }
  7787. end:
  7788. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  7789. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  7790. return result;
  7791. }
  7792. int handleResetRequest(char *uuid, char *payload)
  7793. {
  7794. mtrace();
  7795. int result = FAIL;
  7796. char sstr[10]={0},sstrtemp[30]={ 0 };
  7797. char typestr[10]={0};
  7798. char comfirmstr[20]={0};
  7799. int c = 0;
  7800. char *loc;
  7801. DEBUG_INFO("handleResetRequest...\n");
  7802. strcpy(sstrtemp, stringtrimspace(payload));
  7803. loc = strstr(sstrtemp, "type");
  7804. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7805. c = 0;
  7806. while (loc[3+strlen("type")+c] != '\"')
  7807. {
  7808. sstr[c] = loc[3+strlen("type")+c];
  7809. c++;
  7810. }
  7811. sstr[c] = '\0';
  7812. strcpy(typestr,sstr);
  7813. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  7814. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  7815. {
  7816. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7817. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7818. result = TRUE;
  7819. return result;
  7820. }
  7821. else
  7822. {
  7823. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  7824. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  7825. goto errorend;
  7826. }
  7827. errorend:
  7828. sendResetConfirmation(uuid, comfirmstr);
  7829. return result;
  7830. }
  7831. int handleSendLocalListRequest(char *uuid, char *payload)
  7832. {
  7833. mtrace();
  7834. int result = FAIL;
  7835. int listVersionInt;
  7836. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  7837. char listsearch[]="listVersion";
  7838. char updateTypesearch[]="updateType";
  7839. char localAuthorizationListsearch[]="localAuthorizationList";
  7840. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  7841. char CardList[500][160]={0};
  7842. char updateTypestr[15]={0};
  7843. char idTagstr[20]={0};
  7844. char parentIdTag[20]={0};
  7845. char expiryDate[30]={0};
  7846. char idTagstatus[16]={0};
  7847. int c = 0;
  7848. int i = 0;
  7849. char *delim1 = "}";
  7850. char * pch;
  7851. char *loc;
  7852. //char *ptr;
  7853. char comfirmstr[20];
  7854. //int n_localAuthorizations = 0;
  7855. int checkState_Faulted = FALSE;
  7856. DEBUG_INFO("handleSendLocalListRequest...\n");
  7857. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  7858. {
  7859. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7860. goto end;
  7861. }
  7862. //check Charge Point state
  7863. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7864. {
  7865. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7866. {
  7867. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7868. }
  7869. }
  7870. for (int index = 0; index < CCS_QUANTITY; index++)
  7871. {
  7872. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7873. {
  7874. checkState_Faulted = TRUE; //OCPP Status
  7875. }
  7876. }
  7877. for (int index = 0; index < GB_QUANTITY; index++)
  7878. {
  7879. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7880. {
  7881. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7882. }
  7883. }
  7884. //check Charge Point state
  7885. for (int index = 0; index < AC_QUANTITY; index++)
  7886. {
  7887. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7888. {
  7889. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7890. }
  7891. }
  7892. if(checkState_Faulted == TRUE)
  7893. {
  7894. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7895. goto end;
  7896. }
  7897. //Filter payload space
  7898. strcpy(sstrtemp, stringtrimspace(payload));
  7899. //listVersion
  7900. c = 0;
  7901. loc = strstr(sstrtemp, listsearch);
  7902. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  7903. {
  7904. sstr[c] = loc[strlen("listVersion")+2+c];
  7905. c++;
  7906. }
  7907. sstr[c] = '\0';
  7908. listVersionInt = atoi(sstr);
  7909. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7910. //updateType
  7911. loc = strstr(sstrtemp, updateTypesearch);
  7912. c = 0;
  7913. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  7914. {
  7915. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  7916. c++;
  7917. }
  7918. sstr[c] = '\0';
  7919. strcpy(updateTypestr, sstr);
  7920. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  7921. //localAuthorizationList
  7922. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7923. loc = strstr(sstrtemp, localAuthorizationListsearch);
  7924. if(loc != NULL) // localAuthorizationList is not NULL
  7925. {
  7926. //Check UpdateType
  7927. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7928. {
  7929. //Local list full update
  7930. printf("Local list full update.\n");
  7931. OCPP_getListVerion();
  7932. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7933. {
  7934. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7935. goto end;
  7936. }
  7937. OCPP_cleanLocalList();
  7938. }
  7939. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7940. {
  7941. //Local list different update
  7942. printf("Local list different update.\n");
  7943. OCPP_getListVerion();
  7944. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7945. {
  7946. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  7947. goto end;
  7948. }
  7949. }
  7950. else
  7951. {
  7952. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7953. goto end;
  7954. }
  7955. c = 0;
  7956. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  7957. {
  7958. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  7959. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7960. c++;
  7961. }
  7962. sstr[c] = '\0';
  7963. //DEBUG_INFO("sstr=%s\n", sstr);
  7964. //parsing strings to words
  7965. i = 0;
  7966. pch = strtok(sstr,delim1);
  7967. while (pch != NULL)
  7968. {
  7969. strcpy(CardList[i], pch);
  7970. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  7971. pch = strtok (NULL, delim1);
  7972. i = i + 1;
  7973. }
  7974. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  7975. //local Authorizations List Numbers
  7976. //n_localAuthorizations = i;
  7977. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7978. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7979. c= 0;
  7980. while(c < i) // i is CardList Number
  7981. {
  7982. //Search "IdToken"
  7983. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7984. loc = strstr(CardList[c], "idTag");
  7985. int j = 0;
  7986. while (loc[3+strlen("idTag")+j] != '\"')
  7987. {
  7988. sstr[j] = loc[3+strlen("idTag")+j];
  7989. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7990. j++;
  7991. }
  7992. sstr[j] = '\0';
  7993. strcpy(idTagstr, sstr);
  7994. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  7995. //Search "expiryDate"
  7996. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7997. loc = strstr(CardList[c], "expiryDate");
  7998. j = 0;
  7999. if(loc != NULL)
  8000. {
  8001. while (loc[3+strlen("expiryDate")+j] != '\"')
  8002. {
  8003. sstr[j] = loc[3+strlen("expiryDate")+j];
  8004. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8005. j++;
  8006. }
  8007. sstr[j] = '\0';
  8008. strcpy(expiryDate, sstr);
  8009. }
  8010. else
  8011. {
  8012. strcpy(expiryDate, "");
  8013. }
  8014. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  8015. //Search "parentIdTag"
  8016. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8017. loc = strstr(CardList[c], "parentIdTag");
  8018. j = 0;
  8019. if(loc != NULL)
  8020. {
  8021. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8022. {
  8023. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8024. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8025. j++;
  8026. }
  8027. sstr[j] = '\0';
  8028. strcpy(parentIdTag, sstr);
  8029. }
  8030. else
  8031. {
  8032. strcpy(parentIdTag, "");
  8033. }
  8034. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8035. //Search "status"
  8036. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8037. loc = strstr(CardList[c], "status");
  8038. j = 0;
  8039. while (loc[3+strlen("status")+j] != '\"')
  8040. {
  8041. sstr[j] = loc[3+strlen("status")+j];
  8042. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8043. j++;
  8044. }
  8045. sstr[j] = '\0';
  8046. strcpy(idTagstatus, sstr);
  8047. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8048. OCPP_getIdTag(idTagstr);
  8049. //OCPP_getIdTag("test"); For Test
  8050. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8051. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8052. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8053. {
  8054. //Local list full update
  8055. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8056. // update list
  8057. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8058. //DEBUG_INFO("Local list full update. 1\n");
  8059. //OCPP_get_TableAuthlocalAllData();
  8060. //DEBUG_INFO("Local list full update. 2\n");
  8061. }
  8062. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8063. {
  8064. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8065. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8066. }
  8067. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8068. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8069. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8070. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8071. c++;
  8072. }
  8073. }
  8074. else
  8075. {
  8076. //Check UpdateType
  8077. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8078. {
  8079. //Local list full update
  8080. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8081. OCPP_cleanLocalList();
  8082. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8083. goto end;
  8084. }
  8085. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8086. {
  8087. //Local list different update
  8088. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8089. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8090. goto end;
  8091. }
  8092. }
  8093. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8094. end:
  8095. sendSendLocalListConfirmation(uuid, comfirmstr);
  8096. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8097. return result;
  8098. }
  8099. #define MAX 200
  8100. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8101. {
  8102. mtrace();
  8103. int result = FAIL;
  8104. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8105. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8106. char chargingProfilePurposeStr[30]={0};
  8107. char chargingProfileKindStr[16]={0};
  8108. char recurrencyKindStr[10]={0};
  8109. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8110. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8111. int chargingSchedulePeriodCount = 0;
  8112. //int updateflag = FALSE;
  8113. char comfirmstr[20]={0};
  8114. int meet= FALSE;
  8115. char sstr[10]={0},sstrtemp[1600]={ 0 };
  8116. int c = 0;
  8117. char *loc;
  8118. FILE *fptr1;//, *fptr2;
  8119. //int lno=0;//, linectr = 0;
  8120. //int modifyflag = FALSE;
  8121. char filename[MAX]={0};
  8122. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8123. //int resultRename=0;
  8124. char rmFileCmd[50]={0};
  8125. char tempchargingProfilePurposeStr[30]={0};
  8126. char word[1600]={0};
  8127. int n_chargingProfile = 0;
  8128. //[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}}}]
  8129. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8130. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8131. //Filter string space
  8132. strcpy(sstrtemp, stringtrimspace(payload));
  8133. //*********************connectorId***************************/
  8134. loc = strstr(sstrtemp, "connectorId");
  8135. c = 0;
  8136. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8137. while (loc[strlen("connectorId")+2+c] != ',')
  8138. {
  8139. sstr[c] = loc[strlen("connectorId")+2+c];
  8140. c++;
  8141. }
  8142. sstr[c] = '\0';
  8143. connectorIdInt = atoi(sstr);
  8144. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8145. {
  8146. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8147. }
  8148. else
  8149. {
  8150. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  8151. }
  8152. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  8153. //*********************chargingProfileId***************************/
  8154. loc = strstr(sstrtemp, "chargingProfileId");
  8155. c = 0;
  8156. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8157. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8158. {
  8159. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8160. c++;
  8161. }
  8162. sstr[c] = '\0';
  8163. chargingProfileIdInt = atoi(sstr);
  8164. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8165. {
  8166. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8167. }
  8168. else
  8169. {
  8170. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8171. }
  8172. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  8173. //*********************transactionId***************************/
  8174. loc = strstr(sstrtemp, "transactionId");
  8175. if(loc != NULL)
  8176. {
  8177. c = 0;
  8178. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8179. while (loc[strlen("transactionId")+2+c] != ',')
  8180. {
  8181. sstr[c] = loc[strlen("transactionId")+2+c];
  8182. c++;
  8183. }
  8184. sstr[c] = '\0';
  8185. transactionIdInt = atoi(sstr);
  8186. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8187. {
  8188. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  8189. }
  8190. else
  8191. {
  8192. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  8193. }
  8194. }
  8195. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  8196. //*********************stackLevel***************************/
  8197. loc = strstr(sstrtemp, "stackLevel");
  8198. c = 0;
  8199. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8200. while (loc[strlen("stackLevel")+2+c] != ',')
  8201. {
  8202. sstr[c] = loc[strlen("stackLevel")+2+c];
  8203. c++;
  8204. }
  8205. sstr[c] = '\0';
  8206. stackLevelInt = atoi(sstr);
  8207. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8208. {
  8209. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8210. }
  8211. else
  8212. {
  8213. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8214. }
  8215. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  8216. //*********************chargingProfilePurpose***************************/
  8217. loc = strstr(sstrtemp, "chargingProfilePurpose");
  8218. c = 0;
  8219. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8220. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8221. {
  8222. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8223. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8224. c++;
  8225. }
  8226. sstr[c] = '\0';
  8227. strcpy(chargingProfilePurposeStr,sstr);
  8228. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  8229. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8230. {
  8231. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8232. }
  8233. else
  8234. {
  8235. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8236. }
  8237. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  8238. //*********************chargingProfileKind***************************/
  8239. loc = strstr(sstrtemp, "chargingProfileKind");
  8240. c = 0;
  8241. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8242. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  8243. {
  8244. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  8245. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8246. c++;
  8247. }
  8248. sstr[c] = '\0';
  8249. strcpy(chargingProfileKindStr,sstr);
  8250. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8251. {
  8252. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8253. }
  8254. else
  8255. {
  8256. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8257. }
  8258. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  8259. //*********************recurrencyKind***************************/
  8260. loc = strstr(sstrtemp, "recurrencyKind");
  8261. if(loc != NULL)
  8262. {
  8263. c = 0;
  8264. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8265. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  8266. {
  8267. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  8268. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8269. c++;
  8270. }
  8271. sstr[c] = '\0';
  8272. strcpy(recurrencyKindStr,sstr);
  8273. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8274. {
  8275. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8276. }
  8277. else
  8278. {
  8279. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8280. }
  8281. }
  8282. else
  8283. {
  8284. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8285. {
  8286. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  8287. }
  8288. else
  8289. {
  8290. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  8291. }
  8292. }
  8293. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  8294. //*********************validFrom***************************/
  8295. loc = strstr(sstrtemp, "validFrom");
  8296. if(loc != NULL)
  8297. {
  8298. c = 0;
  8299. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8300. while (loc[3+strlen("validFrom")+c] != '\"')
  8301. {
  8302. sstr[c] = loc[3+strlen("validFrom")+c];
  8303. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8304. c++;
  8305. }
  8306. sstr[c] = '\0';
  8307. strcpy(validFromStr,sstr);
  8308. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8309. {
  8310. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8311. }
  8312. else
  8313. {
  8314. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8315. }
  8316. }
  8317. else
  8318. {
  8319. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8320. {
  8321. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  8322. }
  8323. else
  8324. {
  8325. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  8326. }
  8327. }
  8328. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  8329. //*********************validTo***************************/
  8330. loc = strstr(sstrtemp, "validTo");
  8331. if(loc != NULL)
  8332. {
  8333. c = 0;
  8334. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8335. while (loc[3+strlen("validTo")+c] != '\"')
  8336. {
  8337. sstr[c] = loc[3+strlen("validTo")+c];
  8338. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8339. c++;
  8340. }
  8341. sstr[c] = '\0';
  8342. strcpy(validToStr,sstr);
  8343. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8344. {
  8345. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8346. }
  8347. else
  8348. {
  8349. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8350. }
  8351. }
  8352. else
  8353. {
  8354. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8355. {
  8356. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  8357. }
  8358. else
  8359. {
  8360. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  8361. }
  8362. }
  8363. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  8364. //*********************duration***************************/
  8365. loc = strstr(sstrtemp, "duration");
  8366. if(loc != NULL)
  8367. {
  8368. c = 0;
  8369. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8370. while (loc[strlen("duration")+2+c] != ',')
  8371. {
  8372. sstr[c] = loc[strlen("duration")+2+c];
  8373. c++;
  8374. }
  8375. sstr[c] = '\0';
  8376. durationInt = atoi(sstr);
  8377. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8378. {
  8379. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8380. }
  8381. else
  8382. {
  8383. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8384. }
  8385. }
  8386. else
  8387. {
  8388. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8389. {
  8390. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  8391. }
  8392. else
  8393. {
  8394. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  8395. }
  8396. }
  8397. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  8398. //*********************startSchedule***************************/
  8399. loc = strstr(sstrtemp, "startSchedule");
  8400. if(loc != NULL)
  8401. {
  8402. c = 0;
  8403. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8404. while (loc[3+strlen("startSchedule")+c] != '\"')
  8405. {
  8406. sstr[c] = loc[3+strlen("startSchedule")+c];
  8407. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8408. c++;
  8409. }
  8410. sstr[c] = '\0';
  8411. strcpy(startScheduleStr,sstr);
  8412. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8413. {
  8414. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8415. }
  8416. else
  8417. {
  8418. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8419. }
  8420. }
  8421. else
  8422. {
  8423. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8424. {
  8425. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8426. }
  8427. else
  8428. {
  8429. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8430. }
  8431. }
  8432. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  8433. //*********************chargingRateUnit***************************/
  8434. loc = strstr(sstrtemp, "chargingRateUnit");
  8435. if(loc != NULL)
  8436. {
  8437. c = 0;
  8438. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8439. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  8440. {
  8441. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  8442. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8443. c++;
  8444. }
  8445. sstr[c] = '\0';
  8446. strcpy(chargingRateUnitStr,sstr);
  8447. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8448. {
  8449. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8450. }
  8451. else
  8452. {
  8453. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8454. }
  8455. }
  8456. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  8457. //****************chargingSchedulePeriod count start*******************/
  8458. int what_len = strlen("startPeriod");
  8459. char tempChargingProfile[1600]={0};
  8460. strcpy(tempChargingProfile,(const char*)sstrtemp);
  8461. char *where = tempChargingProfile;
  8462. if (what_len)
  8463. {
  8464. while ((where = strstr(where, "startPeriod"))) {
  8465. where += what_len;
  8466. chargingSchedulePeriodCount++;
  8467. }
  8468. }
  8469. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8470. {
  8471. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8472. goto end;
  8473. }
  8474. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  8475. //where = payload;
  8476. int templength = 0;
  8477. //int searchstart = 0;
  8478. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  8479. {
  8480. //****************startPeriod*******************/
  8481. c=0;
  8482. loc = strstr(tempChargingProfile + templength, "startPeriod");
  8483. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8484. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  8485. {
  8486. sstr[c] = loc[strlen("startPeriod")+2+c];
  8487. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8488. c++;
  8489. }
  8490. sstr[c] = '\0';
  8491. startPeriodInt[periodNums] = atoi(sstr);
  8492. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  8493. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  8494. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8495. {
  8496. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8497. }
  8498. else
  8499. {
  8500. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8501. }
  8502. templength = strlen("startPeriod")+2+c;
  8503. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  8504. //****************limit*******************/
  8505. c=0;
  8506. loc = strstr(tempChargingProfile + templength, "limit");
  8507. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8508. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  8509. {
  8510. sstr[c] = loc[strlen("limit")+2+c];
  8511. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8512. c++;
  8513. }
  8514. sstr[c] = '\0';
  8515. limitflaot[periodNums] = atof(sstr);
  8516. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8517. {
  8518. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8519. }
  8520. else
  8521. {
  8522. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8523. }
  8524. templength = templength + strlen("limit")+2+c;
  8525. //****************numberPhases*******************/
  8526. loc = strstr(tempChargingProfile + templength, "numberPhases");
  8527. if(loc != NULL)
  8528. {
  8529. c=0;
  8530. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8531. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  8532. {
  8533. sstr[c] = loc[strlen("numberPhases")+2+c];
  8534. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8535. c++;
  8536. }
  8537. sstr[c] = '\0';
  8538. numberPhasesInt[periodNums] = atoi(sstr);
  8539. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8540. {
  8541. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8542. }
  8543. else
  8544. {
  8545. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8546. }
  8547. templength = templength + strlen("numberPhases")+2+c;
  8548. }
  8549. //where = loc;
  8550. }
  8551. //****************chargingSchedulePeriod count end*******************/
  8552. //*********************minChargingRate***************************/
  8553. loc = strstr(sstrtemp, "minChargingRate");
  8554. if(loc != NULL)
  8555. {
  8556. c = 0;
  8557. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8558. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  8559. {
  8560. sstr[c] = loc[strlen("minChargingRate")+2+c];
  8561. c++;
  8562. }
  8563. sstr[c] = '\0';
  8564. minChargingRateFloat = atof(sstr);
  8565. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8566. {
  8567. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8568. }
  8569. else
  8570. {
  8571. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8572. }
  8573. }
  8574. else
  8575. {
  8576. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8577. {
  8578. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8579. }
  8580. else
  8581. {
  8582. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8583. }
  8584. }
  8585. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8586. {
  8587. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8588. if(connectorIdInt != 0)
  8589. {
  8590. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8591. goto end;
  8592. }
  8593. strcpy(filename, ChargePointMaxProfile_JSON );
  8594. fptr1 = fopen(filename, "r");
  8595. if (!fptr1)
  8596. {
  8597. //file not exist
  8598. DEBUG_INFO("Unable to open the input file!!\n");
  8599. fptr1 = fopen(filename, "w+");
  8600. }
  8601. else
  8602. {
  8603. //Check Charging Profile Count
  8604. while(fscanf(fptr1, "%s", word) != EOF)
  8605. {
  8606. //DEBUG_INFO("word=%s\n",word);
  8607. if(strstr(word, "chargingProfileId")!= NULL)
  8608. {
  8609. //DEBUG_INFO("test chargingProfileId \n");
  8610. n_chargingProfile = n_chargingProfile + 1;
  8611. //DEBUG_INFO("chargingProfileId Found\n");
  8612. }
  8613. }
  8614. }
  8615. fclose(fptr1);
  8616. }
  8617. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8618. {
  8619. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8620. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8621. {
  8622. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8623. goto end;
  8624. }
  8625. memset(filename, 0, ARRAY_SIZE(filename));
  8626. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8627. fptr1 = fopen(filename, "r");
  8628. if (!fptr1)
  8629. {
  8630. //file not exist
  8631. //DEBUG_INFO("Unable to open the input file!!\n");
  8632. fptr1 = fopen(filename, "w+");
  8633. }
  8634. else
  8635. {
  8636. //Check Charging Profile Count
  8637. while(fscanf(fptr1, "%s", word) != EOF)
  8638. {
  8639. //DEBUG_INFO("word=%s\n",word);
  8640. if(strstr(word, "chargingProfileId")!= NULL)
  8641. {
  8642. //DEBUG_INFO("test chargingProfileId \n");
  8643. n_chargingProfile = n_chargingProfile + 1;
  8644. //DEBUG_INFO("chargingProfileId Found\n");
  8645. }
  8646. }
  8647. }
  8648. fclose(fptr1);
  8649. }
  8650. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8651. {
  8652. //printf("set chargingProfile 1-4\n");
  8653. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8654. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  8655. if(connectorIdInt == 0)
  8656. {
  8657. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8658. goto end;
  8659. }
  8660. int tempIndex = 0;
  8661. //check Transaction active
  8662. if(gunType[connectorIdInt -1] == 'J')
  8663. {
  8664. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8665. {
  8666. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8667. }
  8668. else
  8669. {
  8670. tempIndex = connectorIdInt -1;
  8671. }
  8672. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8673. {
  8674. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8675. {
  8676. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8677. {
  8678. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8679. {
  8680. meet = TRUE;
  8681. break;
  8682. }
  8683. }
  8684. }
  8685. }
  8686. }
  8687. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  8688. {
  8689. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8690. {
  8691. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8692. }
  8693. else
  8694. {
  8695. tempIndex = connectorIdInt -1;
  8696. }
  8697. for (int index = 0; index < CCS_QUANTITY; index++)
  8698. {
  8699. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8700. {
  8701. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8702. {
  8703. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8704. {
  8705. meet = TRUE;
  8706. break;
  8707. }
  8708. }
  8709. }
  8710. }
  8711. }
  8712. else if(gunType[connectorIdInt -1] == 'G')
  8713. {
  8714. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8715. {
  8716. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8717. }
  8718. else
  8719. {
  8720. tempIndex = connectorIdInt -1;
  8721. }
  8722. for (int index = 0; index < GB_QUANTITY; index++)
  8723. {
  8724. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8725. {
  8726. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8727. {
  8728. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8729. {
  8730. meet = TRUE;
  8731. break;
  8732. }
  8733. }
  8734. }
  8735. }
  8736. }
  8737. else
  8738. {
  8739. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8740. {
  8741. tempIndex = 2;
  8742. }
  8743. else
  8744. {
  8745. tempIndex = (connectorIdInt -1);
  8746. }
  8747. for (int index = 0; index < AC_QUANTITY; index++)
  8748. {
  8749. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8750. {
  8751. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8752. {
  8753. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8754. {
  8755. meet = TRUE;
  8756. break;
  8757. }
  8758. }
  8759. }
  8760. }
  8761. }
  8762. //check Transaction active
  8763. if(meet == FALSE)
  8764. {
  8765. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8766. goto end;
  8767. }
  8768. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8769. {
  8770. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8771. goto end;
  8772. }
  8773. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8774. fptr1 = fopen(filename, "r");
  8775. if (!fptr1)
  8776. {
  8777. //file not exist
  8778. DEBUG_INFO("Unable to open the input file!!\n");
  8779. fptr1 = fopen(filename, "w+");
  8780. }
  8781. else
  8782. {
  8783. //Check Charging Profile Count
  8784. while(fscanf(fptr1, "%s", word) != EOF)
  8785. {
  8786. //DEBUG_INFO("word=%s\n",word);
  8787. if(strstr(word, "chargingProfileId")!= NULL)
  8788. {
  8789. //DEBUG_INFO("test chargingProfileId \n");
  8790. n_chargingProfile = n_chargingProfile + 1;
  8791. //DEBUG_INFO("chargingProfileId Found\n");
  8792. }
  8793. }
  8794. }
  8795. fclose(fptr1);
  8796. }
  8797. // Check ChargeProfileMaxStackLevel
  8798. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8799. {
  8800. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8801. goto end;
  8802. }
  8803. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8804. {
  8805. int i = 0;
  8806. char fnametemp[200]={0};
  8807. n_chargingProfile = 0;
  8808. //Check ChargePointMaxProfile.json exit
  8809. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8810. {
  8811. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8812. //Check Charging Profile Count
  8813. while(fscanf(fptr1, "%s", word) != EOF)
  8814. {
  8815. //DEBUG_INFO("word=%s\n",word);
  8816. if(strstr(word, "chargingProfileId")!= NULL)
  8817. {
  8818. //DEBUG_INFO("test chargingProfileId \n");
  8819. n_chargingProfile = n_chargingProfile + 1;
  8820. i = i + 1;
  8821. //DEBUG_INFO("chargingProfileId Found\n");
  8822. }
  8823. memset(word, 0, ARRAY_SIZE(word));
  8824. }
  8825. fclose(fptr1);
  8826. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8827. }
  8828. //Check TxDefaultProfile_0.json exit
  8829. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8830. {
  8831. i = 0;
  8832. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8833. //Check Charging Profile Count
  8834. while(fscanf(fptr1, "%s", word) != EOF)
  8835. {
  8836. //DEBUG_INFO("word=%s\n",word);
  8837. if(strstr(word, "chargingProfileId")!= NULL)
  8838. {
  8839. //DEBUG_INFO("test chargingProfileId \n");
  8840. n_chargingProfile = n_chargingProfile + 1;
  8841. i = i + 1;
  8842. //DEBUG_INFO("chargingProfileId Found\n");
  8843. }
  8844. memset(word, 0, ARRAY_SIZE(word));
  8845. }
  8846. fclose(fptr1);
  8847. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  8848. }
  8849. //Check TxDefaultProfile_%d.json
  8850. for(int j=1; j <= gunTotalNumber; j++)
  8851. {
  8852. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8853. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8854. if((access(fnametemp,F_OK))!=-1)
  8855. {
  8856. i = 0;
  8857. fptr1 = fopen(fnametemp, "r");
  8858. //Check Charging Profile Count
  8859. while(fscanf(fptr1, "%s", word) != EOF)
  8860. {
  8861. //DEBUG_INFO("word=%s\n",word);
  8862. if(strstr(word, "chargingProfileId")!= NULL)
  8863. {
  8864. //DEBUG_INFO("test chargingProfileId \n");
  8865. n_chargingProfile = n_chargingProfile + 1;
  8866. i = i + 1;
  8867. //DEBUG_INFO("chargingProfileId Found\n");
  8868. }
  8869. memset(word, 0, ARRAY_SIZE(word));
  8870. }
  8871. fclose(fptr1);
  8872. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8873. }
  8874. }
  8875. //Check TxProfile_%d.json
  8876. for(int j=1; j <= gunTotalNumber; j++)
  8877. {
  8878. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8879. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8880. if((access(fnametemp,F_OK))!=-1)
  8881. {
  8882. i = 0;
  8883. fptr1 = fopen(fnametemp, "r");
  8884. //Check Charging Profile Count
  8885. while(fscanf(fptr1, "%s", word) != EOF)
  8886. {
  8887. //DEBUG_INFO("word=%s\n",word);
  8888. if(strstr(word, "chargingProfileId")!= NULL)
  8889. {
  8890. //DEBUG_INFO("test chargingProfileId \n");
  8891. n_chargingProfile = n_chargingProfile + 1;
  8892. i = i + 1;
  8893. //DEBUG_INFO("chargingProfileId Found\n");
  8894. }
  8895. memset(word, 0, ARRAY_SIZE(word));
  8896. }
  8897. fclose(fptr1);
  8898. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8899. }
  8900. }
  8901. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  8902. {
  8903. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8904. goto end;
  8905. }
  8906. }
  8907. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8908. //**********************************Write to File********************************************************/
  8909. FILE *infile;
  8910. FILE *outfile;
  8911. // open file for writing
  8912. infile = fopen (filename, "r");
  8913. outfile = fopen (tempfile, "w");
  8914. int d =0;
  8915. d = fgetc(infile);
  8916. //DEBUG_INFO("d:%d\n",d);
  8917. rewind(infile);
  8918. //*璉 瘚 辣蝏     1嚗   0 */
  8919. if(d == EOF)
  8920. {
  8921. //DEBUG_INFO("ChargingProfile content is NULL\n");
  8922. fprintf(outfile,"%s\n",payload);
  8923. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8924. fclose(infile);
  8925. fclose(outfile);
  8926. sprintf(rmFileCmd,"rm -f %s",filename);
  8927. system(rmFileCmd);
  8928. rename(tempfile, filename);
  8929. sleep(1);
  8930. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  8931. //system(rmFileCmd);
  8932. }
  8933. else
  8934. {
  8935. char buf[1000]={0};
  8936. int ChargingProfileAdded = FALSE;
  8937. while (fgets(buf, sizeof(buf), infile) != NULL)
  8938. {
  8939. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8940. //*************************tempconnectorIdInt*********************************/
  8941. loc = strstr(buf, "connectorId");
  8942. c = 0;
  8943. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8944. while (loc[strlen("connectorId")+2+c] != ',')
  8945. {
  8946. sstr[c] = loc[strlen("connectorId")+2+c];
  8947. c++;
  8948. }
  8949. sstr[c] = '\0';
  8950. tempconnectorIdInt = atoi(sstr);
  8951. //*************************tempchargingProfileIdInt*********************************/
  8952. loc = strstr(buf, "chargingProfileId");
  8953. c = 0;
  8954. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8955. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8956. {
  8957. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8958. c++;
  8959. }
  8960. sstr[c] = '\0';
  8961. tempchargingProfileIdInt = atoi(sstr);
  8962. //*************************tempstackLevelInt*********************************/
  8963. loc = strstr(buf, "stackLevel");
  8964. c = 0;
  8965. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8966. while (loc[strlen("stackLevel")+2+c] != ',')
  8967. {
  8968. sstr[c] = loc[strlen("stackLevel")+2+c];
  8969. c++;
  8970. }
  8971. sstr[c] = '\0';
  8972. tempstackLevelInt = atoi(sstr);
  8973. //*************************tempchargingProfilePurposeStr*********************************/
  8974. loc = strstr(payload, "chargingProfilePurpose");
  8975. c = 0;
  8976. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8977. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8978. {
  8979. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8980. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8981. c++;
  8982. }
  8983. sstr[c] = '\0';
  8984. strcpy(tempchargingProfilePurposeStr,sstr);
  8985. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  8986. {
  8987. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8988. {
  8989. //DEBUG_INFO("update set chargingProfile to file -0\n");
  8990. if(ChargingProfileAdded == FALSE)
  8991. {
  8992. fprintf(outfile,"%s\n",payload);
  8993. ChargingProfileAdded = TRUE;
  8994. }
  8995. }
  8996. else
  8997. {
  8998. if(tempstackLevelInt < stackLevelInt)
  8999. {
  9000. if(ChargingProfileAdded == FALSE)
  9001. {
  9002. fprintf(outfile,"%s\n",payload);
  9003. ChargingProfileAdded = TRUE;
  9004. fprintf(outfile,"%s\n",buf);
  9005. }
  9006. else
  9007. {
  9008. fprintf(outfile,"%s\n",buf);
  9009. }
  9010. }
  9011. else
  9012. {
  9013. if(ChargingProfileAdded == FALSE)
  9014. {
  9015. fprintf(outfile,"%s\n",buf);
  9016. fprintf(outfile,"%s\n",payload);
  9017. ChargingProfileAdded = TRUE;
  9018. }
  9019. else
  9020. {
  9021. fprintf(outfile,"%s\n",buf);
  9022. }
  9023. }
  9024. }
  9025. }
  9026. else
  9027. {
  9028. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9029. {
  9030. if(ChargingProfileAdded == FALSE)
  9031. {
  9032. fprintf(outfile,"%s\n",payload);
  9033. ChargingProfileAdded = TRUE;
  9034. fprintf(outfile,"%s\n",buf);
  9035. }
  9036. else
  9037. {
  9038. fprintf(outfile,"%s\n",buf);
  9039. }
  9040. }
  9041. else if(tempstackLevelInt < stackLevelInt)
  9042. {
  9043. if(ChargingProfileAdded == FALSE)
  9044. {
  9045. fprintf(outfile,"%s\n",payload);
  9046. ChargingProfileAdded = TRUE;
  9047. fprintf(outfile,"%s\n",buf);
  9048. }
  9049. else
  9050. {
  9051. fprintf(outfile,"%s\n",buf);
  9052. }
  9053. }
  9054. else
  9055. {
  9056. if(ChargingProfileAdded == FALSE)
  9057. {
  9058. fprintf(outfile,"%s\n",buf);
  9059. fprintf(outfile,"%s\n",payload);
  9060. ChargingProfileAdded = TRUE;
  9061. }
  9062. else
  9063. {
  9064. fprintf(outfile,"%s\n",buf);
  9065. }
  9066. }
  9067. }
  9068. } // end of while loop
  9069. fclose(infile);
  9070. fclose(outfile);
  9071. sprintf(rmFileCmd,"rm -f %s",filename);
  9072. system(rmFileCmd);
  9073. rename(tempfile, filename);
  9074. sleep(1);
  9075. result = TRUE;
  9076. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9077. }
  9078. end:
  9079. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  9080. return result;
  9081. return result;
  9082. }
  9083. int handleTriggerMessageRequest(char *uuid, char *payload)
  9084. {
  9085. mtrace();
  9086. int result = FAIL;
  9087. int connectorIdIsNULL = FALSE;
  9088. int connectorIdInt =0;
  9089. char sstr[40]={0},sstrtemp[100]={ 0 };
  9090. char requestedMessagestr[40]={0};
  9091. char comfirmstr[20]={0};
  9092. int c = 0;
  9093. char *loc;
  9094. DEBUG_INFO("handleTriggerMessageRequest\n");
  9095. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  9096. strcpy(sstrtemp, stringtrimspace(payload));
  9097. c = 0;
  9098. loc = strstr(sstrtemp, "requestedMessage");
  9099. while (loc[3+strlen("requestedMessage")+c] != '\"')
  9100. {
  9101. sstr[c] = loc[3+strlen("requestedMessage")+c];
  9102. c++;
  9103. }
  9104. sstr[c] = '\0';
  9105. strcpy(requestedMessagestr, sstr);
  9106. c = 0;
  9107. loc = strstr(sstrtemp, "connectorId");
  9108. if(loc == NULL)
  9109. {
  9110. connectorIdIsNULL = TRUE;
  9111. }
  9112. else
  9113. {
  9114. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9115. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  9116. {
  9117. sstr[c] = loc[strlen("connectorId")+2+c];
  9118. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9119. c++;
  9120. }
  9121. sstr[c] = '\0';
  9122. connectorIdInt = atoi(sstr);
  9123. }
  9124. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  9125. {
  9126. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  9127. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  9128. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  9129. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  9130. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  9131. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  9132. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  9133. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  9134. {
  9135. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  9136. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9137. return TRUE;
  9138. }
  9139. else
  9140. {
  9141. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9142. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9143. }
  9144. }
  9145. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  9146. {
  9147. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  9148. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9149. return TRUE;
  9150. }
  9151. //==========================
  9152. // Trigger message
  9153. //==========================
  9154. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  9155. {
  9156. if((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) &&
  9157. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) &&
  9158. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) &&
  9159. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING) )
  9160. {
  9161. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  9162. }
  9163. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  9164. }
  9165. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  9166. {
  9167. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  9168. }
  9169. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  9170. {
  9171. //sendBootNotificationRequest();
  9172. server_sign = FALSE;
  9173. }
  9174. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  9175. {
  9176. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  9177. }
  9178. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  9179. {
  9180. if(connectorIdIsNULL == FALSE)
  9181. {
  9182. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9183. {
  9184. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  9185. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  9186. }
  9187. }
  9188. else
  9189. {
  9190. for(int idx=0;idx< gunTotalNumber;idx++)
  9191. {
  9192. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  9193. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  9194. }
  9195. }
  9196. }
  9197. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  9198. {
  9199. if(connectorIdIsNULL == FALSE)
  9200. {
  9201. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9202. {
  9203. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  9204. }
  9205. }
  9206. else
  9207. {
  9208. for(int idx=0;idx< gunTotalNumber;idx++)
  9209. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  9210. }
  9211. }
  9212. return result;
  9213. }
  9214. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9215. {
  9216. mtrace();
  9217. int result = FAIL;
  9218. char sstr[6]={0},sstrtemp[50]={ 0 };
  9219. int connectorIdInt =0;
  9220. char comfirmstr[20]={0};
  9221. int c = 0;
  9222. int tempIndex = 0;
  9223. char *loc;
  9224. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9225. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9226. strcpy(sstrtemp, stringtrimspace(payload));
  9227. c = 0;
  9228. loc = strstr(sstrtemp, "connectorId");
  9229. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9230. while (loc[strlen("connectorId")+2+c] != '}')
  9231. {
  9232. sstr[c] = loc[strlen("connectorId")+2+c];
  9233. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9234. c++;
  9235. }
  9236. sstr[c] = '\0';
  9237. connectorIdInt = atoi(sstr);
  9238. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  9239. if(gunTotalNumber == 0)
  9240. {
  9241. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9242. goto end;
  9243. }
  9244. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9245. {
  9246. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9247. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9248. goto end;
  9249. }
  9250. else
  9251. {
  9252. //check Transaction active
  9253. if(gunType[connectorIdInt-1] == 'J')
  9254. {
  9255. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9256. {
  9257. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9258. }
  9259. else
  9260. {
  9261. tempIndex = connectorIdInt -1;
  9262. }
  9263. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9264. {
  9265. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9266. {
  9267. //stop Transaction
  9268. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9269. }
  9270. }
  9271. }
  9272. else if((gunType[connectorIdInt-1] == 'U')||(gunType[connectorIdInt-1] == 'E'))
  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 < CCS_QUANTITY; index++)
  9283. {
  9284. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[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] == 'G')
  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 < GB_QUANTITY; index++)
  9302. {
  9303. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9304. {
  9305. //stop Transaction
  9306. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9307. }
  9308. }
  9309. }
  9310. else
  9311. {
  9312. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9313. {
  9314. tempIndex = 2;
  9315. }
  9316. else
  9317. {
  9318. tempIndex = connectorIdInt-1;
  9319. }
  9320. for (int index = 0; index < AC_QUANTITY; index++)
  9321. {
  9322. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9323. {
  9324. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9325. }
  9326. }
  9327. }
  9328. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9329. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9330. result = TRUE;
  9331. return result;
  9332. }
  9333. end:
  9334. //json_object_put(obj); --- remove temporally
  9335. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9336. return result;
  9337. }
  9338. static char UpdateFirmwarepayloadData[300]={0};
  9339. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9340. {
  9341. mtrace();
  9342. int result = FAIL;
  9343. pthread_t t;
  9344. sendUpdateFirmwareConfirmation(uuid);
  9345. memset(UpdateFirmwarepayloadData, 0, 300);
  9346. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9347. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9348. ////pthread_join(t, NULL); //
  9349. //pthread_detach(t);
  9350. //sendUpdateFirmwareConfirmation(uuid);
  9351. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9352. return result;
  9353. }
  9354. void *UpdateFirmwareProcess(void *data)
  9355. {
  9356. pthread_detach(pthread_self());
  9357. mtrace();
  9358. int retriesInt =0, retryIntervalInt=0;
  9359. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9360. int port=0;
  9361. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9362. int isSuccess = 0;
  9363. char ftpbuf[200];
  9364. char temp[100];
  9365. char * pch;
  9366. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9367. json_object *UpdateFirmware;
  9368. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  9369. if(!is_error(UpdateFirmware))
  9370. {
  9371. // Required data
  9372. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  9373. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  9374. // Optional data
  9375. if(json_object_object_get(UpdateFirmware, "retries"))
  9376. {
  9377. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  9378. }
  9379. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  9380. {
  9381. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  9382. }
  9383. }
  9384. json_object_put(UpdateFirmware);
  9385. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9386. memset(path, 0, ARRAY_SIZE(path));
  9387. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9388. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9389. if(strncmp(locationstr,"http", 4) == 0)
  9390. {
  9391. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9392. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9393. // protocol, user, password, host, path);
  9394. sprintf(ftppath,"/%s", path);
  9395. DEBUG_INFO("locationstr: %s\n", locationstr);
  9396. DEBUG_INFO("protocol: %s\n",protocol);
  9397. DEBUG_INFO("host: %s\n",host);
  9398. DEBUG_INFO("path: %s\n",path);
  9399. DEBUG_INFO("ftppath: %s\n",ftppath);
  9400. int ftppathlen=strlen(ftppath);
  9401. int i=1;
  9402. char filenametemp[50];
  9403. while(i < ftppathlen)
  9404. {
  9405. int len=ftppathlen-i;
  9406. if(ftppath[len]== 47) // '/' ascll code: 47
  9407. {
  9408. DEBUG_INFO("compare '/' all right\n");
  9409. break;
  9410. }
  9411. i=i+1;
  9412. }
  9413. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9414. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9415. filenametemp[i+1] = 0;
  9416. do
  9417. {
  9418. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9419. sleep(retryIntervalInt);
  9420. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9421. if(!isSuccess)
  9422. {
  9423. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9424. }
  9425. else
  9426. {
  9427. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9428. }
  9429. }
  9430. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9431. {
  9432. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9433. memset(temp, 0, ARRAY_SIZE(temp));
  9434. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9435. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9436. int ftppathlen=strlen(ftpbuf);
  9437. int i=1;
  9438. char filenametemp[50];
  9439. while(i < ftppathlen)
  9440. {
  9441. int len=ftppathlen-i;
  9442. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9443. {
  9444. DEBUG_INFO(" compare '/' all right\n");
  9445. break;
  9446. }
  9447. i=i+1;
  9448. }
  9449. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9450. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9451. filenametemp[i+1] = 0;
  9452. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9453. pch=strchr(temp,'@');
  9454. if(pch==NULL)
  9455. {
  9456. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9457. protocol, host, &port, path);
  9458. strcpy(user,"anonymous");
  9459. strcpy(password,"");
  9460. }
  9461. else
  9462. {
  9463. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9464. protocol, user, password, host, &port, path);
  9465. }
  9466. sscanf(host,"%[^/]%s",host1, path1);
  9467. sprintf(ftppath,"%s", path1);
  9468. //DEBUG_INFO("protocol =%s\n",protocol);
  9469. //DEBUG_INFO("user =%s\n",user);
  9470. //DEBUG_INFO("password =%s\n",password);
  9471. //DEBUG_INFO("host1 =%s\n",host1);
  9472. //DEBUG_INFO("port =%d\n",port);
  9473. //DEBUG_INFO("path1 =%s\n",path1);
  9474. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9475. //ftpFile(host, user, password, port, ftppath, fname);
  9476. //download firmware pthred
  9477. if(port == 0)
  9478. {
  9479. port = 21;
  9480. }
  9481. do
  9482. {
  9483. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9484. sleep(retryIntervalInt);
  9485. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9486. if(!isSuccess)
  9487. {
  9488. //BulldogUtil.sleepMs(interval*1000);
  9489. DEBUG_INFO("Update firmware request and download file fail.\n");
  9490. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9491. }
  9492. else
  9493. {
  9494. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9495. }
  9496. }
  9497. else
  9498. {
  9499. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9500. }
  9501. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9502. pthread_exit(NULL);
  9503. }
  9504. //==========================================
  9505. // Handle server response routine
  9506. //==========================================
  9507. void handleAuthorizeResponse(char *payload, int gun_index)
  9508. {
  9509. mtrace();
  9510. char expiryDatestr[30]={0};
  9511. char parentIdTagstr[20]={0};
  9512. char statusstr[20]={0};
  9513. char expiryDatestrtemp[30]={0};
  9514. char parentIdTagstrtemp[20]={0};
  9515. char IdTagstrtemp[20]={0};
  9516. char statusstrtemp[20]={0};
  9517. int expiryDateISNULL=FALSE;
  9518. int parentIdTagISNULL=FALSE;
  9519. char sstr[160]={0};
  9520. char* filename = AuthorizationCache_JSON;
  9521. char tempfile[] = "/Storage/OCPP/Authorizetemp.json";
  9522. char *loc;
  9523. int resultRename=0;
  9524. int responseIdTagInfoAsZero= 0;
  9525. char rmFileCmd[50]={0};
  9526. DEBUG_INFO("handleAuthorizeResponse...\n");
  9527. json_object *Authorize;
  9528. Authorize = json_tokener_parse(payload);
  9529. if(!is_error(Authorize))
  9530. {
  9531. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  9532. {
  9533. // Required data
  9534. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  9535. // Optional data
  9536. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  9537. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  9538. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  9539. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  9540. }
  9541. }
  9542. json_object_put(Authorize);
  9543. if(expiryDateISNULL == FALSE)
  9544. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9545. if(parentIdTagISNULL == FALSE)
  9546. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9547. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9548. //Update idTag information to authorization cache if supproted
  9549. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9550. {
  9551. if((access(filename,F_OK))!=-1)
  9552. {
  9553. printf("AuthorizationCache exist.\n");
  9554. }
  9555. else
  9556. {
  9557. printf("AuthorizationCache not exist\n");
  9558. FILE *log = fopen(filename, "w+");
  9559. if(log == NULL)
  9560. {
  9561. printf("log is NULL\n");
  9562. goto out;
  9563. }
  9564. else
  9565. {
  9566. fclose(log);
  9567. }
  9568. }
  9569. FILE *infile;
  9570. FILE *outfile;
  9571. // open file for writing
  9572. infile = fopen (filename, "r");
  9573. outfile = fopen (tempfile, "w");
  9574. int c;
  9575. c = fgetc(infile);
  9576. //DEBUG_INFO("c:%d\n",c);
  9577. rewind(infile);
  9578. if(c == EOF)
  9579. {
  9580. DEBUG_INFO("Orignal File is NULL\n");
  9581. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9582. {
  9583. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9584. }
  9585. else
  9586. {
  9587. strcpy(expiryDatestrtemp, "");
  9588. }
  9589. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9590. {
  9591. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9592. }
  9593. else
  9594. {
  9595. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9596. }
  9597. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9598. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9599. fclose(infile);
  9600. fclose(outfile);
  9601. sprintf(rmFileCmd,"rm -f %s",filename);
  9602. system(rmFileCmd);
  9603. resultRename = rename(tempfile, filename);
  9604. if(resultRename == 0)
  9605. {
  9606. printf("File renamed successfully");
  9607. }
  9608. else
  9609. {
  9610. printf("Error: unable to rename the file");
  9611. }
  9612. }
  9613. else
  9614. {
  9615. char buf[160]={0};
  9616. while (fgets(buf, ARRAY_SIZE(buf), infile) != NULL)
  9617. {
  9618. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9619. memset(expiryDatestr, 0, ARRAY_SIZE(expiryDatestrtemp));
  9620. memset(parentIdTagstr,0, ARRAY_SIZE(parentIdTagstrtemp));
  9621. memset(statusstr, 0, ARRAY_SIZE(statusstrtemp));
  9622. memset(IdTagstrtemp, 0, ARRAY_SIZE(IdTagstrtemp));
  9623. memset(expiryDatestrtemp, 0, ARRAY_SIZE(expiryDatestrtemp));
  9624. memset(parentIdTagstrtemp, 0, ARRAY_SIZE(parentIdTagstrtemp));
  9625. memset(statusstrtemp, 0, ARRAY_SIZE(statusstrtemp));
  9626. //------------------IdTag-----------------------
  9627. loc = strstr(buf, "idTag");
  9628. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9629. c = 0;
  9630. while (loc[3+strlen("idTag")+c] != '\"')
  9631. {
  9632. sstr[c] = loc[3+strlen("idTag")+c];
  9633. c++;
  9634. }
  9635. sstr[c] = '\0';
  9636. strcpy(IdTagstrtemp,sstr);
  9637. //*********************expiryDate***************/
  9638. loc = strstr(buf, "expiryDate");
  9639. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9640. c = 0;
  9641. while (loc[3+strlen("expiryDate")+c] != '\"')
  9642. {
  9643. sstr[c] = loc[3+strlen("expiryDate")+c];
  9644. c++;
  9645. }
  9646. sstr[c] = '\0';
  9647. strcpy(expiryDatestr,sstr);
  9648. //*********************parentIdTag***************/
  9649. loc = strstr(buf, "parentIdTag");
  9650. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9651. c = 0;
  9652. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9653. {
  9654. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9655. c++;
  9656. }
  9657. sstr[c] = '\0';
  9658. strcpy(parentIdTagstr,sstr);
  9659. //*********************status***************/
  9660. loc = strstr(buf, "status");
  9661. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9662. c = 0;
  9663. while (loc[3+strlen("status")+c] != '\"')
  9664. {
  9665. sstr[c] = loc[3+strlen("status")+c];
  9666. c++;
  9667. }
  9668. sstr[c] = '\0';
  9669. strcpy(statusstr,sstr);
  9670. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9671. {
  9672. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9673. responseIdTagInfoAsZero = 1;
  9674. }
  9675. else
  9676. {
  9677. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9678. }
  9679. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9680. {
  9681. //modify item
  9682. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9683. {
  9684. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9685. }
  9686. else
  9687. {
  9688. strcpy(expiryDatestrtemp, "");
  9689. }
  9690. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9691. {
  9692. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9693. }
  9694. else
  9695. {
  9696. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9697. }
  9698. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9699. }
  9700. else
  9701. {
  9702. //wrie original item
  9703. strcpy(expiryDatestrtemp, expiryDatestr);
  9704. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9705. strcpy(statusstrtemp, statusstr);
  9706. }
  9707. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9708. }
  9709. fclose(infile);
  9710. fclose(outfile);
  9711. sprintf(rmFileCmd,"rm -f %s",filename);
  9712. system(rmFileCmd);
  9713. resultRename = rename(tempfile, filename);
  9714. if(resultRename == 0)
  9715. {
  9716. DEBUG_INFO("File renamed successfully");
  9717. }
  9718. else
  9719. {
  9720. DEBUG_INFO("Error: unable to rename the file");
  9721. }
  9722. }
  9723. }
  9724. out:
  9725. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9726. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9727. authorizeRetryTimes = 0;
  9728. }
  9729. char * strtrimc( char * s )
  9730. {
  9731. char * p1 = s;
  9732. char * p2 = s;
  9733. while(*p1 != '\0')
  9734. {
  9735. while(*p1 == ' ' || *p1 == '\t' || *p1 == '\"' || *p1 == '\n' || *p1 == '}' || *p1 == '\r')
  9736. {
  9737. if(*p1 != ',')
  9738. {
  9739. p1 ++;
  9740. }
  9741. else
  9742. {
  9743. break;
  9744. }
  9745. }
  9746. if(*p1 != ',')
  9747. {
  9748. * p2 ++ = *p1 ++;
  9749. //printf("p2=%s\n",p2);
  9750. }
  9751. else
  9752. {
  9753. break;
  9754. }
  9755. }
  9756. *p2 = '\0';
  9757. return (s);
  9758. }
  9759. void handleBootNotificationResponse(char *payload, int gun_index)
  9760. {
  9761. mtrace();
  9762. char statusStr[12]={0};
  9763. char currentTimeStr[30]={0};
  9764. int intervalInt = 0;
  9765. struct tm tp;
  9766. char buf[28]={0};
  9767. char timebuf[50]={0};
  9768. DEBUG_INFO("handleBootNotificationResponse...\n");
  9769. json_object *BootNotification;
  9770. BootNotification = json_tokener_parse(payload);
  9771. if(!is_error(BootNotification))
  9772. {
  9773. // Required data
  9774. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  9775. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  9776. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  9777. }
  9778. json_object_put(BootNotification);
  9779. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9780. BootNotificationInterval = intervalInt;
  9781. HeartBeatWaitTime = intervalInt;
  9782. //write back to ShmOCPP16Data->BootNotification
  9783. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9784. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9785. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9786. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  9787. {
  9788. server_sign = TRUE;
  9789. server_pending =FALSE;
  9790. }
  9791. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9792. {
  9793. server_pending = TRUE;
  9794. }
  9795. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9796. tp.tm_isdst = -1;
  9797. //time_t utc = mktime(&tp);
  9798. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9799. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9800. sprintf(timebuf,"date -s '%s'",buf);
  9801. system(timebuf);
  9802. srand(time(NULL));
  9803. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  9804. //==============================================
  9805. // RTC sync
  9806. //==============================================
  9807. system("/sbin/hwclock -w --systohc");
  9808. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  9809. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9810. }
  9811. void handleDataTransferResponse(char *payload, int gun_index)
  9812. {
  9813. char sstr[160]={0};//sstr[200]={ 0 };
  9814. int c = 0;
  9815. char *loc;
  9816. DEBUG_INFO("handleDataTransferResponse ...\n");
  9817. loc = strstr(payload, "status");
  9818. printf("loc=%s\n",loc);
  9819. c = 0;
  9820. while (loc[3+strlen("status")+c] != '\"')
  9821. {
  9822. sstr[c] = loc[3+strlen("status")+c];
  9823. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9824. c++;
  9825. }
  9826. sstr[c] = '\0';
  9827. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  9828. }
  9829. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  9830. {
  9831. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  9832. //struct json_object *obj;
  9833. // obj = json_tokener_parse(payload);
  9834. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  9835. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  9836. //No fields are defined.
  9837. }
  9838. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  9839. {
  9840. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  9841. //struct json_object *obj;
  9842. // obj = json_tokener_parse(payload);
  9843. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  9844. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  9845. //No fields are defined.
  9846. }
  9847. void handleHeartbeatResponse(char *payload, int gun_index)
  9848. {
  9849. mtrace();
  9850. struct tm tp;
  9851. char buf[28]={0};
  9852. char timebuf[50]={0};
  9853. DEBUG_INFO("handleHeartbeatResponse...\n");
  9854. json_object *Heartbeat;
  9855. Heartbeat = json_tokener_parse(payload);
  9856. if(!is_error(Heartbeat))
  9857. {
  9858. // Required data
  9859. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  9860. }
  9861. json_object_put(BootNotification);
  9862. if(FirstHeartBeat == 0)
  9863. {
  9864. FirstHeartBeat = 1;
  9865. DEBUG_INFO("FirstHeartBeat \n");
  9866. }
  9867. HeartBeatWithNOResponse = 0;
  9868. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9869. tp.tm_isdst = -1;
  9870. //time_t utc = mktime(&tp);
  9871. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9872. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9873. sprintf(timebuf,"date -s '%s'",buf);
  9874. system(timebuf);
  9875. //==============================================
  9876. // RTC sync
  9877. //==============================================
  9878. system("/sbin/hwclock -w --systohc");
  9879. //===============================================
  9880. //Print Out HeartBeat log
  9881. //===============================================
  9882. {
  9883. double diff_t;
  9884. struct tm tp,tp1;
  9885. // BootNotification Receive Time
  9886. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9887. tp.tm_isdst = -1;
  9888. time_t BootNotificationReceiveTime = mktime(&tp);
  9889. //HeartBeat Receive Time
  9890. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp1);
  9891. tp1.tm_isdst = -1;
  9892. time_t HeartBeatReceiveTime = mktime(&tp1);
  9893. diff_t = difftime(HeartBeatReceiveTime, BootNotificationReceiveTime);
  9894. printf("handleHeartbeatResponse differnt time=%f..\n",diff_t);
  9895. if(((int)diff_t / 3600) > HeartBeatCountPerHour)
  9896. {
  9897. HeartBeatCountPerHour = (int)diff_t / 3600;
  9898. DEBUG_INFO("handleHeartbeatResponse ...\n");
  9899. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  9900. }
  9901. }
  9902. }
  9903. void handleMeterValuesResponse(char *payload, int gun_index)
  9904. {
  9905. mtrace();
  9906. DEBUG_INFO("handleMeterValuesResponse...\n");
  9907. }
  9908. void handleStartTransactionResponse(char *payload, int gun_index)
  9909. {
  9910. mtrace();
  9911. //int transactionIdInt = 0;
  9912. FILE *outfile;
  9913. char data[100]={0};
  9914. DEBUG_INFO("handleStartTransactionResponse...\n");
  9915. json_object *StartTransaction;
  9916. StartTransaction = json_tokener_parse(payload);
  9917. if(!is_error(StartTransaction))
  9918. {
  9919. // Required data
  9920. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  9921. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  9922. // Optional data
  9923. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  9924. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  9925. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  9926. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  9927. }
  9928. json_object_put(StartTransaction);
  9929. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  9930. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  9931. //-----------Start : write to the Queue TransactionId file -----------------//
  9932. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  9933. {}
  9934. else
  9935. {
  9936. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  9937. if(log == NULL)
  9938. {
  9939. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  9940. return ;
  9941. }
  9942. else
  9943. {
  9944. fclose(log);
  9945. }
  9946. }
  9947. // open file for writing
  9948. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  9949. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  9950. {
  9951. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  9952. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  9953. fputs(data, outfile);
  9954. fclose (outfile);
  9955. }
  9956. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9957. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9958. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  9959. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  9960. }
  9961. void handleStatusNotificationResponse(char *payload, int gun_index)
  9962. {
  9963. mtrace();
  9964. DEBUG_INFO("handleStatusNotificationResponse...\n");
  9965. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  9966. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  9967. }
  9968. void handleStopTransactionnResponse(char *payload, int gun_index)
  9969. {
  9970. mtrace();
  9971. DEBUG_INFO("handleStopTransactionnResponse...\n");
  9972. json_object *StopTransaction;
  9973. StopTransaction = json_tokener_parse(payload);
  9974. if(!is_error(StopTransaction))
  9975. {
  9976. // Optional data
  9977. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  9978. {
  9979. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  9980. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  9981. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  9982. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  9983. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  9984. }
  9985. }
  9986. json_object_put(StopTransaction);
  9987. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  9988. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  9989. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9990. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9991. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  9992. }
  9993. //==========================================
  9994. // Handle Error routine
  9995. //==========================================
  9996. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  9997. {
  9998. mtrace();
  9999. #ifdef SystemLogMessage
  10000. DEBUG_INFO("errorCode: %s\n", errorCode);
  10001. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  10002. DEBUG_INFO("errorDetails: %s\n", payload);
  10003. #endif
  10004. }
  10005. //===============================================
  10006. // Common routine
  10007. //===============================================
  10008. int initialConfigurationTable(void)
  10009. {
  10010. //clock_t start_t, end_t, total_t;
  10011. FILE *fp;
  10012. FILE *outfile;
  10013. char str[200]={0};
  10014. char sstr[100]={0};
  10015. int c = 0;
  10016. char *loc;
  10017. DEBUG_INFO("initialConfigurationTable...\n");
  10018. //start_t = clock();
  10019. //printf("Starting of the program, start_t = %ld\n", start_t);
  10020. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  10021. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  10022. {
  10023. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10024. if(outfile == NULL)
  10025. {
  10026. DEBUG_INFO("Error opening file\n");
  10027. return FALSE;
  10028. }
  10029. /*Core Profile*/
  10030. //AllowOfflineTxForUnknownId
  10031. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10032. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10033. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  10034. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10035. //AuthorizationCacheEnabled
  10036. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10037. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10038. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10039. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10040. //AuthorizeRemoteTxRequests
  10041. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10042. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10043. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  10044. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10045. //BlinkRepeat
  10046. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10047. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10048. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10049. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10050. //ClockAlignedDataInterval
  10051. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10052. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10053. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10054. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10055. //ConnectionTimeOut
  10056. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10057. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10058. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10059. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10060. //GetConfigurationMaxKeys
  10061. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10062. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10063. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "44" );
  10064. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10065. // HeartbeatInterval
  10066. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10067. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10068. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  10069. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10070. // LightIntensity
  10071. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10072. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10073. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10074. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10075. // LocalAuthorizeOffline
  10076. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10077. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10078. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10079. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10080. // LocalPreAuthorize
  10081. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10082. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10084. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10085. // MaxEnergyOnInvalidId
  10086. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10087. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10088. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10089. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10090. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10091. // MeterValuesAlignedData
  10092. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  10093. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10094. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10095. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10096. else
  10097. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10098. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10099. // MeterValuesAlignedDataMaxLength
  10100. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10101. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10102. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10103. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  10104. else
  10105. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10106. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10107. // MeterValuesSampledData
  10108. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  10109. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10110. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10112. else
  10113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10114. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10115. // MeterValuesSampledDataMaxLength
  10116. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10117. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10118. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  10120. else
  10121. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10122. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10123. // MeterValueSampleInterval
  10124. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  10127. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10128. // MinimumStatusDuration
  10129. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10130. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10131. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  10132. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  10133. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10134. // NumberOfConnectors
  10135. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10136. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10137. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10138. {
  10139. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10140. }
  10141. else
  10142. {
  10143. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10144. }
  10145. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10146. // ResetRetries
  10147. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10148. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10149. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10150. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10151. // ConnectorPhaseRotation
  10152. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10153. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10154. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10155. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10156. // ConnectorPhaseRotationMaxLength
  10157. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10158. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10159. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10160. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10161. // StopTransactionOnEVSideDisconnect
  10162. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10163. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10164. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10165. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10166. // StopTransactionOnInvalidId
  10167. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  10168. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10169. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10170. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10171. // StopTxnAlignedData
  10172. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10173. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10174. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10175. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10176. // StopTxnAlignedDataMaxLength
  10177. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10178. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10179. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10180. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10181. // StopTxnSampledData
  10182. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  10183. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10184. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10185. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10186. else
  10187. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10188. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10189. // StopTxnSampledDataMaxLength
  10190. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10191. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10192. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10193. {
  10194. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  10195. }
  10196. else
  10197. {
  10198. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  10199. }
  10200. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10201. // SupportedFeatureProfiles
  10202. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10203. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10204. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10205. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10206. // SupportedFeatureProfilesMaxLength
  10207. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10208. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10209. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10210. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10211. // TransactionMessageAttempts
  10212. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10213. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10214. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10215. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10216. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10217. // TransactionMessageRetryInterval
  10218. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10219. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10220. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10221. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10222. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10223. // UnlockConnectorOnEVSideDisconnect
  10224. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10225. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10226. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10227. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10228. // WebSocketPingInterval
  10229. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10230. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10231. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10232. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10233. // QueueOffLineStartTransactionMessage
  10234. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  10235. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10236. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10237. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10238. //* Local Auth List Management Profile*/
  10239. #if 0
  10240. //For OCTT Test Case
  10241. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10242. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10243. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10244. #endif
  10245. #if 1
  10246. //LocalAuthListEnabled
  10247. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10248. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10249. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10250. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10251. #endif
  10252. //LocalAuthListMaxLength
  10253. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10254. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10255. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10256. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10257. //SendLocalListMaxLength
  10258. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10259. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10260. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  10261. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10262. //ReserveConnectorZeroSupported
  10263. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10264. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10265. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10266. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10267. //* Smart Charging Profile */
  10268. //ChargeProfileMaxStackLevel
  10269. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10270. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10271. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10272. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10273. // ChargingScheduleAllowedChargingRateUnit
  10274. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10275. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10276. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10277. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10278. // ChargingScheduleMaxPeriods
  10279. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10280. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10281. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10282. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10283. // ConnectorSwitch3to1PhaseSupported
  10284. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10285. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10286. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10287. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10288. // MaxChargingProfilesInstalled
  10289. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10290. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10291. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10292. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10293. fclose(outfile);
  10294. }
  10295. else
  10296. {
  10297. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10298. char keystr[60]={0};
  10299. char readonlystr[10]={0};
  10300. char valuestr[100]={0};
  10301. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10302. if(fp == NULL) {
  10303. DEBUG_INFO("Error opening file");
  10304. return FALSE;
  10305. }
  10306. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  10307. {
  10308. //DEBUG_INFO("Get Configuration \n");
  10309. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10310. //*************************key*********************************/
  10311. loc = strstr(str, "key");
  10312. c = 0;
  10313. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10314. while (loc[strlen("key")+3+c] != '\"')
  10315. {
  10316. sstr[c] = loc[strlen("key")+3+c];
  10317. c++;
  10318. }
  10319. sstr[c] = '\0';
  10320. strcpy(keystr,sstr);
  10321. //*************************readonly*********************************/
  10322. loc = strstr(str, "readonly");
  10323. c = 0;
  10324. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10325. while (loc[strlen("readonly")+2+c] != ',')
  10326. {
  10327. sstr[c] = loc[strlen("readonly")+2+c];
  10328. c++;
  10329. }
  10330. sstr[c] = '\0';
  10331. strcpy(readonlystr,sstr);
  10332. //*************************value*********************************/
  10333. loc = strstr(str, "value");
  10334. c = 0;
  10335. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10336. while (loc[strlen("value")+3+c] != '\"')
  10337. {
  10338. sstr[c] = loc[strlen("value")+3+c];
  10339. c++;
  10340. }
  10341. sstr[c] = '\0';
  10342. strcpy(valuestr,sstr);
  10343. // DEBUG_INFO("keystr=%s\n",keystr);
  10344. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10345. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10346. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10347. {
  10348. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10349. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10350. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10351. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10352. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10353. }
  10354. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10355. {
  10356. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10357. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10358. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10359. }
  10360. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10361. {
  10362. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10363. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10364. }
  10365. if(strcmp(keystr, "BlinkRepeat") == 0)
  10366. {
  10367. //Charger.BlinkRepeat = Integer.parseInt(value);
  10368. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10369. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10370. }
  10371. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10372. {
  10373. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10374. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10375. }
  10376. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10377. {
  10378. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10379. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10380. }
  10381. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10382. {
  10383. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10384. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  10385. }
  10386. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10387. {
  10388. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10389. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10390. HeartBeatWaitTime = atoi(valuestr);
  10391. }
  10392. if(strcmp(keystr, "LightIntensity") == 0)
  10393. {
  10394. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10395. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10396. }
  10397. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10398. {
  10399. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10400. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10401. }
  10402. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10403. {
  10404. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10405. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10406. }
  10407. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10408. {
  10409. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10410. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10411. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10412. }
  10413. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10414. {
  10415. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10416. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10417. }
  10418. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10419. {
  10420. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10421. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10422. }
  10423. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10424. {
  10425. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10426. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10427. }
  10428. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10429. {
  10430. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10431. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10432. }
  10433. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10434. {
  10435. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10436. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10437. }
  10438. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10439. {
  10440. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10441. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10442. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10443. }
  10444. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10445. {
  10446. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10447. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10448. }
  10449. if(strcmp(keystr, "ResetRetries") == 0)
  10450. {
  10451. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10452. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10453. }
  10454. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10455. {
  10456. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10457. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10458. }
  10459. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10460. {
  10461. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10462. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10463. }
  10464. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10465. {
  10466. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10467. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10468. }
  10469. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10470. {
  10471. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10472. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10473. }
  10474. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10475. {
  10476. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10477. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10478. }
  10479. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10480. {
  10481. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10482. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10483. }
  10484. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10485. {
  10486. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10487. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10488. }
  10489. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10490. {
  10491. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10492. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10493. }
  10494. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10495. {
  10496. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10497. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10498. }
  10499. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10500. {
  10501. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10502. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10503. }
  10504. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10505. {
  10506. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10507. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10508. TransactionMessageAttemptsValue = atoi(valuestr);
  10509. }
  10510. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10511. {
  10512. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10513. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10514. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10515. }
  10516. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10517. {
  10518. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10519. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10520. }
  10521. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10522. {
  10523. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10524. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10525. }
  10526. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  10527. {
  10528. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10529. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  10530. }
  10531. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10532. {
  10533. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10534. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10535. }
  10536. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10537. {
  10538. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10539. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10540. }
  10541. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10542. {
  10543. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10544. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10545. }
  10546. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10547. {
  10548. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10549. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10550. }
  10551. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10552. {
  10553. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10554. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10555. }
  10556. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10557. {
  10558. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10559. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10560. }
  10561. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10562. {
  10563. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10564. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10565. }
  10566. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10567. {
  10568. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10569. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10570. }
  10571. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10572. {
  10573. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10574. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10575. }
  10576. }
  10577. fclose(fp);
  10578. }
  10579. return 0;
  10580. }
  10581. void StoreConfigurationTable(void)
  10582. {
  10583. FILE *outfile;
  10584. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10585. if(outfile == NULL)
  10586. {
  10587. DEBUG_INFO("Error opening file");
  10588. return ;
  10589. }
  10590. /*Core Profile*/
  10591. //AllowOfflineTxForUnknownId
  10592. /*
  10593. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10594. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10595. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10596. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10597. */
  10598. //DEBUG_INFO("data=%s\n",data);
  10599. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10600. //AuthorizationCacheEnabled
  10601. /*
  10602. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10603. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10604. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10605. */
  10606. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10607. //AuthorizeRemoteTxRequests
  10608. /*
  10609. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10610. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10611. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10612. */
  10613. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10614. //BlinkRepeat
  10615. /*
  10616. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10617. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10618. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10619. */
  10620. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10621. //ClockAlignedDataInterval
  10622. /*
  10623. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10624. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10625. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10626. */
  10627. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10628. //ConnectionTimeOut
  10629. /*
  10630. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10631. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10633. */
  10634. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10635. //GetConfigurationMaxKeys
  10636. /*
  10637. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10638. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10639. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10640. */
  10641. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10642. // HeartbeatInterval
  10643. /*
  10644. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10645. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10646. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10647. */
  10648. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10649. // LightIntensity
  10650. /*
  10651. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10652. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10653. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10654. */
  10655. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10656. // LocalAuthorizeOffline
  10657. /*
  10658. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10659. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10660. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10661. */
  10662. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10663. // LocalPreAuthorize
  10664. /*
  10665. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10666. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10667. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10668. */
  10669. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10670. // MaxEnergyOnInvalidId
  10671. /*
  10672. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10673. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10674. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10675. */
  10676. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10677. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10678. // MeterValuesAlignedData
  10679. /*
  10680. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10681. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10682. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10683. */
  10684. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10685. // MeterValuesAlignedDataMaxLength
  10686. /*
  10687. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10688. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10689. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10690. */
  10691. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10692. // MeterValuesSampledData
  10693. /*
  10694. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10695. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10697. */
  10698. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10699. // MeterValuesSampledDataMaxLength
  10700. /*
  10701. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10702. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10703. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10704. */
  10705. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10706. // MeterValueSampleInterval
  10707. /*
  10708. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10709. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10710. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10711. */
  10712. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10713. // MinimumStatusDuration
  10714. /*
  10715. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10716. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10717. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10718. */
  10719. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10720. // NumberOfConnectors
  10721. /*
  10722. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10723. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10724. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10725. {
  10726. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10727. }
  10728. else
  10729. {
  10730. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10731. }
  10732. */
  10733. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10734. // ResetRetries
  10735. /*
  10736. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10737. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10738. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10739. */
  10740. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10741. // ConnectorPhaseRotation
  10742. /*
  10743. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10744. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10746. */
  10747. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10748. // ConnectorPhaseRotationMaxLength
  10749. /*
  10750. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10751. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10752. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10753. */
  10754. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10755. // StopTransactionOnEVSideDisconnect
  10756. /*
  10757. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10758. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10759. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10760. */
  10761. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10762. // StopTransactionOnInvalidId
  10763. /*
  10764. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  10765. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10766. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10767. */
  10768. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10769. // StopTxnAlignedData
  10770. /*
  10771. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10772. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10774. */
  10775. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10776. // StopTxnAlignedDataMaxLength
  10777. /*
  10778. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10779. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10780. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10781. */
  10782. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10783. // StopTxnSampledData
  10784. /*
  10785. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10786. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10787. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  10788. */
  10789. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10790. // StopTxnSampledDataMaxLength
  10791. /*
  10792. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10794. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10795. */
  10796. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10797. // SupportedFeatureProfiles
  10798. /*
  10799. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10801. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10802. */
  10803. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10804. // SupportedFeatureProfilesMaxLength
  10805. /*
  10806. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10807. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10809. */
  10810. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10811. // TransactionMessageAttempts
  10812. /*
  10813. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10814. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10815. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10816. */
  10817. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10818. // TransactionMessageRetryInterval
  10819. /*
  10820. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10821. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10822. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10823. */
  10824. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10825. // UnlockConnectorOnEVSideDisconnect
  10826. /*
  10827. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10828. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10829. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10830. */
  10831. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10832. // WebSocketPingInterval
  10833. /*
  10834. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10835. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10836. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10837. */
  10838. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10839. // QueueOffLineStartTransactionMessage
  10840. /*
  10841. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  10842. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10843. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10844. */
  10845. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10846. //* Local Auth List Management Profile*/
  10847. //LocalAuthListEnabled
  10848. /*
  10849. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10850. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10852. */
  10853. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10854. //LocalAuthListMaxLength
  10855. /*
  10856. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10857. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10859. */
  10860. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10861. //SendLocalListMaxLength
  10862. /*
  10863. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10864. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10865. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10866. */
  10867. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10868. //ReserveConnectorZeroSupported
  10869. /*
  10870. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10871. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10872. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10873. */
  10874. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10875. //* Smart Charging Profile */
  10876. //ChargeProfileMaxStackLevel
  10877. /*
  10878. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10879. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10880. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10881. */
  10882. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10883. // ChargingScheduleAllowedChargingRateUnit
  10884. /*
  10885. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10886. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10888. */
  10889. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10890. // ChargingScheduleMaxPeriods
  10891. /*
  10892. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10893. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10894. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10895. */
  10896. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10897. // ConnectorSwitch3to1PhaseSupported
  10898. /*
  10899. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10900. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10901. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10902. */
  10903. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10904. // MaxChargingProfilesInstalled
  10905. /*
  10906. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10907. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10908. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10909. */
  10910. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10911. fclose(outfile);
  10912. }
  10913. void getKeyValue(char *keyReq)
  10914. {
  10915. int isEmpty = FALSE;
  10916. int isKnowKey = FALSE;
  10917. DEBUG_INFO("keyReq = %s\n", keyReq);
  10918. if((keyReq == NULL) || (strlen(keyReq) == 0))
  10919. isEmpty = TRUE;
  10920. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  10921. {
  10922. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  10923. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  10924. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  10925. {
  10926. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  10927. }
  10928. else
  10929. {
  10930. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  10931. }
  10932. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  10933. isKnowKey = TRUE;
  10934. }
  10935. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  10936. {
  10937. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  10938. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  10939. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  10940. {
  10941. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  10942. }
  10943. else
  10944. {
  10945. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  10946. }
  10947. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  10948. isKnowKey = TRUE;
  10949. }
  10950. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  10951. {
  10952. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  10953. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  10954. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  10955. {
  10956. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  10957. }
  10958. else
  10959. {
  10960. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  10961. }
  10962. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  10963. isKnowKey = TRUE;
  10964. }
  10965. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  10966. {
  10967. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  10968. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  10969. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  10970. {
  10971. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  10972. }
  10973. else
  10974. {
  10975. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  10976. }
  10977. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  10978. isKnowKey = TRUE;
  10979. }
  10980. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  10981. {
  10982. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  10983. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  10984. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  10985. {
  10986. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  10987. }
  10988. else
  10989. {
  10990. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  10991. }
  10992. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  10993. isKnowKey = TRUE;
  10994. }
  10995. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  10996. {
  10997. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  10998. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  10999. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11000. {
  11001. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  11002. }
  11003. else
  11004. {
  11005. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  11006. }
  11007. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  11008. isKnowKey = TRUE;
  11009. }
  11010. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  11011. {
  11012. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  11013. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  11014. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11015. {
  11016. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  11017. }
  11018. else
  11019. {
  11020. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  11021. }
  11022. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  11023. isKnowKey = TRUE;
  11024. }
  11025. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  11026. {
  11027. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  11028. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  11029. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11030. {
  11031. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  11032. }
  11033. else
  11034. {
  11035. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  11036. }
  11037. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  11038. isKnowKey = TRUE;
  11039. }
  11040. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  11041. {
  11042. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  11043. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  11044. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11045. {
  11046. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  11047. }
  11048. else
  11049. {
  11050. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  11051. }
  11052. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  11053. isKnowKey = TRUE;
  11054. }
  11055. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  11056. {
  11057. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  11058. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  11059. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11060. {
  11061. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  11062. }
  11063. else
  11064. {
  11065. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  11066. }
  11067. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  11068. isKnowKey = TRUE;
  11069. }
  11070. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  11071. {
  11072. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  11073. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  11074. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11075. {
  11076. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  11077. }
  11078. else
  11079. {
  11080. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  11081. }
  11082. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  11083. isKnowKey = TRUE;
  11084. }
  11085. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  11086. {
  11087. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  11088. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  11089. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11090. {
  11091. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11092. }
  11093. else
  11094. {
  11095. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11096. }
  11097. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  11098. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  11099. isKnowKey = TRUE;
  11100. }
  11101. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  11102. {
  11103. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  11104. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11105. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11106. {
  11107. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11108. }
  11109. else
  11110. {
  11111. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11112. }
  11113. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11114. isKnowKey = TRUE;
  11115. }
  11116. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11117. {
  11118. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11119. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11120. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11121. {
  11122. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11123. }
  11124. else
  11125. {
  11126. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11127. }
  11128. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11129. isKnowKey = TRUE;
  11130. }
  11131. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11132. {
  11133. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11134. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11135. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11136. {
  11137. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11138. }
  11139. else
  11140. {
  11141. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11142. }
  11143. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11144. isKnowKey = TRUE;
  11145. }
  11146. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11147. {
  11148. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11149. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11150. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11151. {
  11152. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11153. }
  11154. else
  11155. {
  11156. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11157. }
  11158. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11159. isKnowKey = TRUE;
  11160. }
  11161. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11162. {
  11163. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11165. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11166. {
  11167. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11168. }
  11169. else
  11170. {
  11171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11172. }
  11173. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11174. isKnowKey = TRUE;
  11175. }
  11176. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11177. {
  11178. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11179. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11180. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11181. {
  11182. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11183. }
  11184. else
  11185. {
  11186. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11187. }
  11188. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11189. isKnowKey = TRUE;
  11190. }
  11191. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11192. {
  11193. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11195. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11196. {
  11197. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11198. }
  11199. else
  11200. {
  11201. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11202. }
  11203. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11204. isKnowKey = TRUE;
  11205. }
  11206. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11207. {
  11208. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11210. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11211. {
  11212. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11213. }
  11214. else
  11215. {
  11216. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11217. }
  11218. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11219. isKnowKey = TRUE;
  11220. }
  11221. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11222. {
  11223. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11225. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11226. {
  11227. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11228. }
  11229. else
  11230. {
  11231. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11232. }
  11233. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11234. isKnowKey = TRUE;
  11235. }
  11236. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11237. {
  11238. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11240. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11241. {
  11242. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11243. }
  11244. else
  11245. {
  11246. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11247. }
  11248. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11249. isKnowKey = TRUE;
  11250. }
  11251. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11252. {
  11253. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11254. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11255. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11256. {
  11257. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11258. }
  11259. else
  11260. {
  11261. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11262. }
  11263. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11264. isKnowKey = TRUE;
  11265. }
  11266. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11267. {
  11268. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11269. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11270. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11271. {
  11272. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11273. }
  11274. else
  11275. {
  11276. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11277. }
  11278. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11279. isKnowKey = TRUE;
  11280. }
  11281. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11282. {
  11283. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11284. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11285. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11286. {
  11287. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11288. }
  11289. else
  11290. {
  11291. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11292. }
  11293. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11294. isKnowKey = TRUE;
  11295. }
  11296. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11297. {
  11298. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11299. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11300. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11301. {
  11302. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11303. }
  11304. else
  11305. {
  11306. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11307. }
  11308. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11309. isKnowKey = TRUE;
  11310. }
  11311. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11312. {
  11313. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11314. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11315. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11316. {
  11317. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11318. }
  11319. else
  11320. {
  11321. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11322. }
  11323. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11324. isKnowKey = TRUE;
  11325. }
  11326. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11327. {
  11328. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11329. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11330. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11331. {
  11332. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11333. }
  11334. else
  11335. {
  11336. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11337. }
  11338. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11339. isKnowKey = TRUE;
  11340. }
  11341. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11342. {
  11343. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11344. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11345. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11346. {
  11347. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11348. }
  11349. else
  11350. {
  11351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11352. }
  11353. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11354. isKnowKey = TRUE;
  11355. }
  11356. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11357. {
  11358. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11359. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11360. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11361. {
  11362. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11363. }
  11364. else
  11365. {
  11366. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11367. }
  11368. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11369. isKnowKey = TRUE;
  11370. }
  11371. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11372. {
  11373. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11374. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11375. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11376. {
  11377. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11378. }
  11379. else
  11380. {
  11381. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11382. }
  11383. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11384. isKnowKey = TRUE;
  11385. }
  11386. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11387. {
  11388. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11389. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11390. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11391. {
  11392. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11393. }
  11394. else
  11395. {
  11396. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11397. }
  11398. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11399. isKnowKey = TRUE;
  11400. }
  11401. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11402. {
  11403. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11404. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11405. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11406. {
  11407. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11408. }
  11409. else
  11410. {
  11411. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11412. }
  11413. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11414. isKnowKey = TRUE;
  11415. }
  11416. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11417. {
  11418. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11419. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11420. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11421. {
  11422. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11423. }
  11424. else
  11425. {
  11426. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11427. }
  11428. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11429. isKnowKey = TRUE;
  11430. }
  11431. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  11432. {
  11433. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  11434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  11435. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  11436. {
  11437. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  11438. }
  11439. else
  11440. {
  11441. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  11442. }
  11443. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  11444. isKnowKey = TRUE;
  11445. }
  11446. #if 1
  11447. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11448. {
  11449. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11450. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11451. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11452. {
  11453. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11454. }
  11455. else
  11456. {
  11457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11458. }
  11459. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11460. isKnowKey = TRUE;
  11461. }
  11462. #endif
  11463. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11464. {
  11465. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11466. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11467. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11468. {
  11469. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11470. }
  11471. else
  11472. {
  11473. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11474. }
  11475. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11476. isKnowKey = TRUE;
  11477. }
  11478. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11479. {
  11480. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11481. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11482. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11483. {
  11484. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11485. }
  11486. else
  11487. {
  11488. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11489. }
  11490. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11491. isKnowKey = TRUE;
  11492. }
  11493. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11494. {
  11495. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11496. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11497. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11498. {
  11499. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11500. }
  11501. else
  11502. {
  11503. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11504. }
  11505. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11506. isKnowKey = TRUE;
  11507. }
  11508. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11509. {
  11510. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11511. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11512. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11513. {
  11514. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11515. }
  11516. else
  11517. {
  11518. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11519. }
  11520. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11521. isKnowKey = TRUE;
  11522. }
  11523. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11524. {
  11525. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11526. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11527. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11528. {
  11529. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11530. }
  11531. else
  11532. {
  11533. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11534. }
  11535. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11536. isKnowKey = TRUE;
  11537. }
  11538. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11539. {
  11540. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11541. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11542. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11543. {
  11544. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11545. }
  11546. else
  11547. {
  11548. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11549. }
  11550. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11551. isKnowKey = TRUE;
  11552. }
  11553. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11554. {
  11555. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11556. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11557. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11558. {
  11559. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11560. }
  11561. else
  11562. {
  11563. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11564. }
  11565. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11566. isKnowKey = TRUE;
  11567. }
  11568. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11569. {
  11570. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11571. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11572. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11573. {
  11574. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11575. }
  11576. else
  11577. {
  11578. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11579. }
  11580. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11581. isKnowKey = TRUE;
  11582. }
  11583. //=========================================================
  11584. if(!isEmpty && !isKnowKey)
  11585. {
  11586. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11587. strcpy(unknownkey[UnknownKeynum], keyReq);
  11588. UnknownKeynum = UnknownKeynum + 1;
  11589. }
  11590. }
  11591. void processUnkownKey(void)
  11592. {
  11593. DEBUG_INFO("processUnkownKey...\n");
  11594. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11595. for(int index=0; index < UnknownKeynum; index++)
  11596. {
  11597. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11598. {
  11599. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11600. }
  11601. }
  11602. }
  11603. int setKeyValue(char *key, char *value)
  11604. {
  11605. int isSuccess = NotSupported;
  11606. int check_ascii=0;
  11607. char str[10]={0};
  11608. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  11609. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11610. {
  11611. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11612. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11613. {
  11614. strcpy(str, (const char*)value);
  11615. for(int i = 0; str[i]; i++){
  11616. str[i] = tolower(str[i]);
  11617. }
  11618. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11619. isSuccess = ConfigurationStatus_Accepted;
  11620. }
  11621. else
  11622. {
  11623. isSuccess = ConfigurationStatus_Rejected;
  11624. }
  11625. }
  11626. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11627. {
  11628. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11629. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11630. {
  11631. strcpy(str, (const char*)value);
  11632. for(int i = 0; str[i]; i++){
  11633. str[i] = tolower(str[i]);
  11634. }
  11635. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11636. isSuccess = ConfigurationStatus_Accepted;
  11637. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11638. }
  11639. else
  11640. {
  11641. isSuccess = ConfigurationStatus_Rejected;
  11642. }
  11643. }
  11644. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11645. {
  11646. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11647. {
  11648. strcpy(str, (const char*)value);
  11649. for(int i = 0; str[i]; i++)
  11650. {
  11651. str[i] = tolower(str[i]);
  11652. }
  11653. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11654. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11655. isSuccess = ConfigurationStatus_Accepted;
  11656. }
  11657. else
  11658. {
  11659. isSuccess = ConfigurationStatus_Rejected;
  11660. }
  11661. }
  11662. if(strcmp(key, "BlinkRepeat") == 0)
  11663. {
  11664. //Charger.BlinkRepeat = Integer.parseInt(value);
  11665. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11666. {
  11667. check_ascii = value[0];
  11668. if( (check_ascii < 48) || (check_ascii > 57) )
  11669. {
  11670. isSuccess = ConfigurationStatus_Rejected;
  11671. }
  11672. else
  11673. {
  11674. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11675. isSuccess = ConfigurationStatus_Accepted;
  11676. }
  11677. }
  11678. else
  11679. {
  11680. isSuccess = ConfigurationStatus_Rejected;
  11681. }
  11682. }
  11683. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11684. {
  11685. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11686. {
  11687. check_ascii = value[0];
  11688. if( (check_ascii < 48) || (check_ascii > 57) )
  11689. {
  11690. isSuccess = ConfigurationStatus_Rejected;
  11691. }
  11692. else
  11693. {
  11694. if((atoi(value) == 0) || (atoi(value) >= 10))
  11695. {
  11696. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11697. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11698. isSuccess = ConfigurationStatus_Accepted;
  11699. }
  11700. else
  11701. isSuccess = ConfigurationStatus_Rejected;
  11702. }
  11703. }
  11704. else
  11705. {
  11706. isSuccess = ConfigurationStatus_Rejected;
  11707. }
  11708. }
  11709. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11710. {
  11711. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11712. {
  11713. check_ascii = value[0];
  11714. if( (check_ascii < 48) || (check_ascii > 57) )
  11715. {
  11716. isSuccess = ConfigurationStatus_Rejected;
  11717. }
  11718. else
  11719. {
  11720. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11721. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11722. isSuccess = ConfigurationStatus_Accepted;
  11723. }
  11724. }
  11725. else
  11726. {
  11727. isSuccess = ConfigurationStatus_Rejected;
  11728. }
  11729. }
  11730. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11731. {
  11732. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11733. {
  11734. check_ascii = value[0];
  11735. if( (check_ascii < 48) || (check_ascii > 57) )
  11736. {
  11737. isSuccess = ConfigurationStatus_Rejected;
  11738. }
  11739. else
  11740. {
  11741. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11742. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11743. isSuccess = ConfigurationStatus_Accepted;
  11744. }
  11745. }
  11746. else
  11747. {
  11748. isSuccess = ConfigurationStatus_Rejected;
  11749. }
  11750. }
  11751. if(strcmp(key, "HeartbeatInterval") == 0)
  11752. {
  11753. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11754. {
  11755. check_ascii = value[0];
  11756. if( (check_ascii < 48) || (check_ascii > 57) )
  11757. {
  11758. isSuccess = ConfigurationStatus_Rejected;
  11759. }
  11760. else
  11761. {
  11762. if((atoi(value) == 0) || (atoi(value) >= 10))
  11763. {
  11764. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11765. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11766. HeartBeatWaitTime = atoi(value);
  11767. isSuccess = ConfigurationStatus_Accepted;
  11768. }
  11769. else
  11770. {
  11771. isSuccess = ConfigurationStatus_Rejected;
  11772. }
  11773. }
  11774. }
  11775. else
  11776. {
  11777. isSuccess = ConfigurationStatus_Rejected;
  11778. }
  11779. }
  11780. if(strcmp(key, "LightIntensity") == 0)
  11781. {
  11782. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11783. {
  11784. check_ascii = value[0];
  11785. if( (check_ascii < 48) || (check_ascii > 57) )
  11786. {
  11787. isSuccess = ConfigurationStatus_Rejected;
  11788. }
  11789. else
  11790. {
  11791. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  11792. isSuccess = ConfigurationStatus_Accepted;
  11793. }
  11794. }
  11795. else
  11796. {
  11797. isSuccess = ConfigurationStatus_Rejected;
  11798. }
  11799. }
  11800. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  11801. {
  11802. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11803. {
  11804. strcpy(str, (const char*)value);
  11805. for(int i = 0; str[i]; i++)
  11806. {
  11807. str[i] = tolower(str[i]);
  11808. }
  11809. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11810. isSuccess = ConfigurationStatus_Accepted;
  11811. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11812. }
  11813. else
  11814. {
  11815. isSuccess = ConfigurationStatus_Rejected;
  11816. }
  11817. }
  11818. if(strcmp(key, "LocalPreAuthorize") == 0)
  11819. {
  11820. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11821. {
  11822. strcpy(str, (const char*)value);
  11823. for(int i = 0; str[i]; i++)
  11824. {
  11825. str[i] = tolower(str[i]);
  11826. }
  11827. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11828. isSuccess = ConfigurationStatus_Accepted;
  11829. }
  11830. else
  11831. {
  11832. isSuccess = ConfigurationStatus_Rejected;
  11833. }
  11834. }
  11835. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  11836. {
  11837. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11838. {
  11839. check_ascii = value[0];
  11840. if( (check_ascii < 48) || (check_ascii > 57) )
  11841. {
  11842. isSuccess = ConfigurationStatus_Rejected;
  11843. }
  11844. else
  11845. {
  11846. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  11847. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  11848. isSuccess = ConfigurationStatus_Accepted;
  11849. }
  11850. }
  11851. else
  11852. {
  11853. isSuccess = ConfigurationStatus_Rejected;
  11854. }
  11855. }
  11856. if(strcmp(key, "MeterValuesAlignedData") == 0)
  11857. {
  11858. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11859. {
  11860. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  11861. isSuccess = ConfigurationStatus_Accepted;
  11862. }
  11863. else
  11864. {
  11865. isSuccess = ConfigurationStatus_Rejected;
  11866. }
  11867. }
  11868. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  11869. {
  11870. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11871. {
  11872. check_ascii = value[0];
  11873. if( (check_ascii < 48) || (check_ascii > 57) )
  11874. {
  11875. isSuccess = ConfigurationStatus_Rejected;
  11876. }
  11877. else
  11878. {
  11879. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11880. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  11881. isSuccess = ConfigurationStatus_Accepted;
  11882. }
  11883. }
  11884. else
  11885. {
  11886. isSuccess = ConfigurationStatus_Rejected;
  11887. }
  11888. }
  11889. if(strcmp(key, "MeterValuesSampledData") == 0 )
  11890. {
  11891. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11892. {
  11893. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  11894. isSuccess = ConfigurationStatus_Accepted;
  11895. }
  11896. else
  11897. {
  11898. isSuccess = ConfigurationStatus_Rejected;
  11899. }
  11900. }
  11901. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  11902. {
  11903. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11904. {
  11905. check_ascii = value[0];
  11906. if( (check_ascii < 48) || (check_ascii > 57) )
  11907. {
  11908. isSuccess = ConfigurationStatus_Rejected;
  11909. }
  11910. else
  11911. {
  11912. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11913. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  11914. isSuccess = ConfigurationStatus_Accepted;
  11915. }
  11916. }
  11917. else
  11918. {
  11919. isSuccess = ConfigurationStatus_Rejected;
  11920. }
  11921. }
  11922. if(strcmp(key, "MeterValueSampleInterval") == 0)
  11923. {
  11924. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11925. {
  11926. check_ascii = value[0];
  11927. if( (check_ascii < 48) || (check_ascii > 57) )
  11928. {
  11929. isSuccess = ConfigurationStatus_Rejected;
  11930. }
  11931. else
  11932. {
  11933. if((atoi(value) == 0) || (atoi(value) >= 10))
  11934. {
  11935. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11936. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  11937. isSuccess = ConfigurationStatus_Accepted;
  11938. }
  11939. else
  11940. {
  11941. isSuccess = ConfigurationStatus_Rejected;
  11942. }
  11943. }
  11944. }
  11945. else
  11946. {
  11947. isSuccess = ConfigurationStatus_Rejected;
  11948. }
  11949. }
  11950. if(strcmp(key, "MinimumStatusDuration") == 0)
  11951. {
  11952. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11953. {
  11954. check_ascii = value[0];
  11955. if( (check_ascii < 48) || (check_ascii > 57) )
  11956. {
  11957. isSuccess = ConfigurationStatus_Rejected;
  11958. }
  11959. else
  11960. {
  11961. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  11962. {
  11963. isSuccess = ConfigurationStatus_Rejected;
  11964. }
  11965. else
  11966. {
  11967. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  11968. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  11969. server_cycle_Status = atoi(value); //StatusNotification Cycle
  11970. isSuccess = ConfigurationStatus_Accepted;
  11971. }
  11972. }
  11973. }
  11974. else
  11975. {
  11976. isSuccess = ConfigurationStatus_Rejected;
  11977. }
  11978. }
  11979. if(strcmp(key, "NumberOfConnectors") == 0)
  11980. {
  11981. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11982. {
  11983. check_ascii = value[0];
  11984. if( (check_ascii < 48) || (check_ascii > 57) )
  11985. {
  11986. isSuccess = ConfigurationStatus_Rejected;
  11987. }
  11988. else
  11989. {
  11990. //Charger.ResetRetries = Integer.parseInt(value);
  11991. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  11992. isSuccess = ConfigurationStatus_Accepted;
  11993. }
  11994. }
  11995. else
  11996. {
  11997. isSuccess = ConfigurationStatus_Rejected;
  11998. }
  11999. }
  12000. if(strcmp(key, "ResetRetries") == 0)
  12001. {
  12002. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12003. {
  12004. check_ascii = value[0];
  12005. if( (check_ascii < 48) || (check_ascii > 57) )
  12006. {
  12007. isSuccess = ConfigurationStatus_Rejected;
  12008. }
  12009. else
  12010. {
  12011. //Charger.ResetRetries = Integer.parseInt(value);
  12012. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  12013. isSuccess = ConfigurationStatus_Accepted;
  12014. }
  12015. }
  12016. else
  12017. {
  12018. isSuccess = ConfigurationStatus_Rejected;
  12019. }
  12020. }
  12021. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  12022. {
  12023. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12024. {
  12025. strcpy(str, (const char*)value);
  12026. for(int i = 0; str[i]; i++)
  12027. {
  12028. str[i] = tolower(str[i]);
  12029. }
  12030. if(strcmp(str, "notapplicable")== 0)
  12031. {
  12032. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12033. isSuccess = ConfigurationStatus_Accepted;
  12034. }
  12035. else if(strcmp(str, "unknown")== 0)
  12036. {
  12037. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12038. isSuccess = ConfigurationStatus_Accepted;
  12039. }
  12040. else if(strcmp(str, "rst")== 0)
  12041. {
  12042. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12043. isSuccess = ConfigurationStatus_Accepted;
  12044. }
  12045. else if(strcmp(str, "rts")== 0)
  12046. {
  12047. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12048. isSuccess = ConfigurationStatus_Accepted;
  12049. }
  12050. else if(strcmp(str, "srt")== 0)
  12051. {
  12052. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12053. isSuccess = ConfigurationStatus_Accepted;
  12054. }
  12055. else if(strcmp(str, "str")== 0)
  12056. {
  12057. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12058. isSuccess = ConfigurationStatus_Accepted;
  12059. }
  12060. else if(strcmp(str, "trs")== 0)
  12061. {
  12062. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12063. isSuccess = ConfigurationStatus_Accepted;
  12064. }
  12065. else if(strcmp(str, "tsr")== 0)
  12066. {
  12067. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12068. isSuccess = ConfigurationStatus_Accepted;
  12069. }
  12070. else
  12071. {
  12072. isSuccess = ConfigurationStatus_Rejected;
  12073. }
  12074. }
  12075. else
  12076. {
  12077. isSuccess = ConfigurationStatus_Rejected;
  12078. }
  12079. }
  12080. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12081. {
  12082. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12083. {
  12084. check_ascii = value[0];
  12085. if( (check_ascii < 48) || (check_ascii > 57) )
  12086. {
  12087. isSuccess = ConfigurationStatus_Rejected;
  12088. }
  12089. else
  12090. {
  12091. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12092. isSuccess = ConfigurationStatus_Accepted;
  12093. }
  12094. }
  12095. else
  12096. {
  12097. isSuccess = ConfigurationStatus_Rejected;
  12098. }
  12099. }
  12100. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12101. {
  12102. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].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. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12110. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12111. isSuccess = ConfigurationStatus_Accepted;
  12112. }
  12113. else
  12114. {
  12115. isSuccess = ConfigurationStatus_Rejected;
  12116. }
  12117. }
  12118. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12119. {
  12120. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12121. {
  12122. strcpy(str, (const char*)value);
  12123. for(int i = 0; str[i]; i++)
  12124. {
  12125. str[i] = tolower(str[i]);
  12126. }
  12127. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12128. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12129. isSuccess = ConfigurationStatus_Accepted;
  12130. }
  12131. else
  12132. {
  12133. isSuccess = ConfigurationStatus_Rejected;
  12134. }
  12135. }
  12136. if(strcmp(key, "StopTxnAlignedData") == 0)
  12137. {
  12138. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12139. {
  12140. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12141. isSuccess = ConfigurationStatus_Accepted;
  12142. }
  12143. else
  12144. {
  12145. isSuccess = ConfigurationStatus_Rejected;
  12146. }
  12147. }
  12148. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12149. {
  12150. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12151. {
  12152. check_ascii = value[0];
  12153. if( (check_ascii < 48) || (check_ascii > 57) )
  12154. {
  12155. isSuccess = ConfigurationStatus_Rejected;
  12156. }
  12157. else
  12158. {
  12159. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12160. isSuccess = ConfigurationStatus_Accepted;
  12161. }
  12162. }
  12163. else
  12164. {
  12165. isSuccess = ConfigurationStatus_Rejected;
  12166. }
  12167. }
  12168. if(strcmp(key, "StopTxnSampledData") == 0)
  12169. {
  12170. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12171. {
  12172. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12173. isSuccess = ConfigurationStatus_Accepted;
  12174. }
  12175. else
  12176. {
  12177. isSuccess = ConfigurationStatus_Rejected;
  12178. }
  12179. }
  12180. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12181. {
  12182. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12183. {
  12184. check_ascii = value[0];
  12185. if( (check_ascii < 48) || (check_ascii > 57) )
  12186. {
  12187. isSuccess = ConfigurationStatus_Rejected;
  12188. }
  12189. else
  12190. {
  12191. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12192. isSuccess = ConfigurationStatus_Accepted;
  12193. }
  12194. }
  12195. else
  12196. {
  12197. isSuccess = ConfigurationStatus_Rejected;
  12198. }
  12199. }
  12200. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12201. {
  12202. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12203. {
  12204. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12205. isSuccess = ConfigurationStatus_Accepted;
  12206. }
  12207. else
  12208. {
  12209. isSuccess = ConfigurationStatus_Rejected;
  12210. }
  12211. }
  12212. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12213. {
  12214. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12215. {
  12216. check_ascii = value[0];
  12217. if( (check_ascii < 48) || (check_ascii > 57) )
  12218. {
  12219. isSuccess = ConfigurationStatus_Rejected;
  12220. }
  12221. else
  12222. {
  12223. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12224. isSuccess = ConfigurationStatus_Accepted;
  12225. }
  12226. }
  12227. else
  12228. {
  12229. isSuccess = ConfigurationStatus_Rejected;
  12230. }
  12231. }
  12232. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12233. {
  12234. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12235. {
  12236. check_ascii = value[0];
  12237. if( (check_ascii < 48) || (check_ascii > 57) )
  12238. {
  12239. isSuccess = ConfigurationStatus_Rejected;
  12240. }
  12241. else
  12242. {
  12243. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12244. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12245. TransactionMessageAttemptsValue = atoi(value);
  12246. isSuccess = ConfigurationStatus_Accepted;
  12247. }
  12248. }
  12249. else
  12250. {
  12251. isSuccess = ConfigurationStatus_Rejected;
  12252. }
  12253. }
  12254. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12255. {
  12256. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12257. {
  12258. check_ascii = value[0];
  12259. if( (check_ascii < 48) || (check_ascii > 57) )
  12260. {
  12261. isSuccess = ConfigurationStatus_Rejected;
  12262. }
  12263. else
  12264. {
  12265. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12266. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12267. TransactionMessageRetryIntervalValue = atoi(value);
  12268. isSuccess = ConfigurationStatus_Accepted;
  12269. }
  12270. }
  12271. else
  12272. {
  12273. isSuccess = ConfigurationStatus_Rejected;
  12274. }
  12275. }
  12276. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12277. {
  12278. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12279. {
  12280. strcpy(str, (const char*)value);
  12281. for(int i = 0; str[i]; i++)
  12282. {
  12283. str[i] = tolower(str[i]);
  12284. }
  12285. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12286. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12287. isSuccess = ConfigurationStatus_Accepted;
  12288. }
  12289. else
  12290. {
  12291. isSuccess = ConfigurationStatus_Rejected;
  12292. }
  12293. }
  12294. if(strcmp(key, "WebSocketPingInterval") == 0)
  12295. {
  12296. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12297. {
  12298. check_ascii = value[0];
  12299. if( (check_ascii < 48) || (check_ascii > 57) )
  12300. {
  12301. isSuccess = ConfigurationStatus_Rejected;
  12302. }
  12303. else
  12304. {
  12305. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12306. isSuccess = ConfigurationStatus_Accepted;
  12307. }
  12308. }
  12309. else
  12310. {
  12311. isSuccess = ConfigurationStatus_Rejected;
  12312. }
  12313. }
  12314. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  12315. {
  12316. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12317. {
  12318. strcpy(str, (const char*)value);
  12319. for(int i = 0; str[i]; i++)
  12320. {
  12321. str[i] = tolower(str[i]);
  12322. }
  12323. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12324. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12325. isSuccess = ConfigurationStatus_Accepted;
  12326. }
  12327. else
  12328. {
  12329. isSuccess = ConfigurationStatus_Rejected;
  12330. }
  12331. }
  12332. #if 0
  12333. //For OCPP Test Case
  12334. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12335. {
  12336. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12337. {
  12338. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12339. isSuccess = ConfigurationStatus_Accepted;
  12340. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12341. }
  12342. else
  12343. {
  12344. isSuccess = ConfigurationStatus_Rejected;
  12345. }
  12346. }
  12347. #endif
  12348. #if 1
  12349. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12350. {
  12351. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12352. {
  12353. strcpy(str, (const char*)value);
  12354. for(int i = 0; str[i]; i++)
  12355. {
  12356. str[i] = tolower(str[i]);
  12357. }
  12358. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12359. isSuccess = ConfigurationStatus_Accepted;
  12360. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12361. }
  12362. else
  12363. {
  12364. isSuccess = ConfigurationStatus_Rejected;
  12365. }
  12366. }
  12367. #endif
  12368. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12369. {
  12370. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12371. {
  12372. check_ascii = value[0];
  12373. if( (check_ascii < 48) || (check_ascii > 57) )
  12374. {
  12375. isSuccess = ConfigurationStatus_Rejected;
  12376. }
  12377. else
  12378. {
  12379. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12380. isSuccess = ConfigurationStatus_Accepted;
  12381. }
  12382. }
  12383. else
  12384. {
  12385. isSuccess = ConfigurationStatus_Rejected;
  12386. }
  12387. }
  12388. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12389. {
  12390. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12391. {
  12392. check_ascii = value[0];
  12393. if( (check_ascii < 48) || (check_ascii > 57) )
  12394. {
  12395. isSuccess = ConfigurationStatus_Rejected;
  12396. }
  12397. else
  12398. {
  12399. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12400. isSuccess = ConfigurationStatus_Accepted;
  12401. }
  12402. }
  12403. else
  12404. {
  12405. isSuccess = ConfigurationStatus_Rejected;
  12406. }
  12407. }
  12408. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12409. {
  12410. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12411. {
  12412. strcpy(str, (const char*)value);
  12413. for(int i = 0; str[i]; i++)
  12414. {
  12415. str[i] = tolower(str[i]);
  12416. }
  12417. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12418. isSuccess = ConfigurationStatus_Accepted;
  12419. }
  12420. else
  12421. {
  12422. isSuccess = ConfigurationStatus_Rejected;
  12423. }
  12424. }
  12425. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12426. {
  12427. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12428. {
  12429. check_ascii = value[0];
  12430. if( (check_ascii < 48) || (check_ascii > 57) )
  12431. {
  12432. isSuccess = ConfigurationStatus_Rejected;
  12433. }
  12434. else
  12435. {
  12436. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12437. isSuccess = ConfigurationStatus_Accepted;
  12438. }
  12439. }
  12440. else
  12441. {
  12442. isSuccess = ConfigurationStatus_Rejected;
  12443. }
  12444. }
  12445. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12446. {
  12447. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12448. {
  12449. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12450. isSuccess = ConfigurationStatus_Accepted;
  12451. }
  12452. else
  12453. {
  12454. isSuccess = ConfigurationStatus_Rejected;
  12455. }
  12456. }
  12457. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12458. {
  12459. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12460. {
  12461. check_ascii = value[0];
  12462. if( (check_ascii < 48) || (check_ascii > 57) )
  12463. {
  12464. isSuccess = ConfigurationStatus_Rejected;
  12465. }
  12466. else
  12467. {
  12468. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12469. isSuccess = ConfigurationStatus_Accepted;
  12470. }
  12471. }
  12472. else
  12473. {
  12474. isSuccess = ConfigurationStatus_Rejected;
  12475. }
  12476. }
  12477. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12478. {
  12479. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12480. {
  12481. strcpy(str, (const char*)value);
  12482. for(int i = 0; str[i]; i++)
  12483. {
  12484. str[i] = tolower(str[i]);
  12485. }
  12486. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12487. isSuccess = ConfigurationStatus_Accepted;
  12488. }
  12489. else
  12490. {
  12491. isSuccess = ConfigurationStatus_Rejected;
  12492. }
  12493. }
  12494. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12495. {
  12496. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12497. {
  12498. check_ascii = value[0];
  12499. if( (check_ascii < 48) || (check_ascii > 57) )
  12500. {
  12501. isSuccess = ConfigurationStatus_Rejected;
  12502. }
  12503. else
  12504. {
  12505. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12506. isSuccess = ConfigurationStatus_Accepted;
  12507. }
  12508. }
  12509. else
  12510. {
  12511. isSuccess = ConfigurationStatus_Rejected;
  12512. }
  12513. }
  12514. return isSuccess;
  12515. }
  12516. int TransactionMessageAttemptsGet(void)
  12517. {
  12518. return TransactionMessageAttemptsValue;
  12519. }
  12520. int FirstHeartBeatResponse(void)
  12521. {
  12522. return FirstHeartBeat;
  12523. }
  12524. int TransactionMessageRetryIntervalGet(void)
  12525. {
  12526. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12527. }
  12528. int ReadHttpStatus(int sock)
  12529. {
  12530. //char c;
  12531. char buff[1024]="",*ptr=buff+1;
  12532. int bytes_received, status;
  12533. DEBUG_INFO("Begin Response ..\n");
  12534. while((bytes_received = recv(sock, ptr, 1, 0))){
  12535. if(bytes_received==-1){
  12536. perror("ReadHttpStatus");
  12537. exit(1);
  12538. }
  12539. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12540. ptr++;
  12541. }
  12542. *ptr=0;
  12543. ptr=buff+1;
  12544. sscanf(ptr,"%*s %d ", &status);
  12545. DEBUG_INFO("%s\n",ptr);
  12546. DEBUG_INFO("status=%d\n",status);
  12547. DEBUG_INFO("End Response ..\n");
  12548. return (bytes_received>0)?status:0;
  12549. }
  12550. //the only filed that it parsed is 'Content-Length'
  12551. int ParseHeader(int sock)
  12552. {
  12553. //char c;
  12554. char buff[1024]="",*ptr=buff+4;
  12555. int bytes_received;
  12556. DEBUG_INFO("Begin HEADER ..\n");
  12557. while((bytes_received = recv(sock, ptr, 1, 0))){
  12558. if(bytes_received==-1){
  12559. perror("Parse Header");
  12560. exit(1);
  12561. }
  12562. if(
  12563. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12564. (ptr[-1]=='\r') && (*ptr=='\n' )
  12565. ) break;
  12566. ptr++;
  12567. }
  12568. *ptr=0;
  12569. ptr=buff+4;
  12570. //printf("%s",ptr);
  12571. if(bytes_received){
  12572. ptr=strstr(ptr,"Content-Length:");
  12573. if(ptr){
  12574. sscanf(ptr,"%*s %d",&bytes_received);
  12575. }else
  12576. bytes_received=-1; //unknown size
  12577. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12578. }
  12579. DEBUG_INFO("End HEADER ..\n");
  12580. return bytes_received ;
  12581. }
  12582. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12583. {
  12584. char rmFileCmd[100]={0};
  12585. char FilePath[100]={0};
  12586. char ftpbuf[200];
  12587. int systemresult;
  12588. //DEBUG_INFO("filename=%s\n",filename);
  12589. //DEBUG_INFO("url=%s\n",url);
  12590. sprintf(FilePath,"/mnt/%s",filename);
  12591. if((access(FilePath,F_OK))!=-1)
  12592. {
  12593. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12594. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12595. system(rmFileCmd);
  12596. }
  12597. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12598. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12599. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12600. systemresult = system(ftpbuf);
  12601. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12602. if(systemresult != 0)
  12603. {
  12604. DEBUG_INFO("http DownLoad error!\n");
  12605. return FALSE;
  12606. }
  12607. return TRUE;
  12608. }
  12609. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12610. {
  12611. char rmFileCmd[100]={0};
  12612. char FilePath[100]={0};
  12613. char ftpbuf[200];
  12614. int systemresult;
  12615. //char temp[100];
  12616. sprintf(FilePath,"/mnt/%s",filename);
  12617. if((access(FilePath,F_OK))!=-1)
  12618. {
  12619. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12620. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12621. system(rmFileCmd);
  12622. }
  12623. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12624. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12625. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12626. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12627. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12628. systemresult = system(ftpbuf);
  12629. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12630. if(systemresult != 0)
  12631. {
  12632. printf("wget error!\n");
  12633. return FALSE;
  12634. }
  12635. return TRUE;
  12636. }
  12637. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12638. {
  12639. char rmFileCmd[100]={0};
  12640. char FilePath[100]={0};
  12641. char ftpbuf[200];
  12642. int systemresult;
  12643. //DEBUG_INFO("filename=%s\n",filename);
  12644. //DEBUG_INFO("url=%s\n",url);
  12645. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12646. if((access(FilePath,F_OK))!=-1)
  12647. {
  12648. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12649. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12650. system(rmFileCmd);
  12651. }
  12652. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12653. if(fp == NULL)
  12654. {
  12655. DEBUG_INFO("log is NULL\n");
  12656. return FALSE;
  12657. }
  12658. else
  12659. {
  12660. fprintf(fp, "%s\n", url);
  12661. fprintf(fp, "%s\n", filename);
  12662. fclose(fp);
  12663. }
  12664. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12665. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12666. systemresult = system(ftpbuf);
  12667. DEBUG_INFO("systemresult = %d\n",systemresult);
  12668. if(systemresult != 0)
  12669. {
  12670. DEBUG_INFO("http upload error!\n");
  12671. return FALSE;
  12672. }
  12673. return TRUE;
  12674. }
  12675. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12676. {
  12677. struct hostent* server;
  12678. char *IPbuffer;
  12679. char ftpbuf[200];
  12680. int systemresult;
  12681. // To retrieve host information
  12682. server = gethostbyname(location);
  12683. // To convert an Internet network
  12684. // address into ASCII string
  12685. IPbuffer = inet_ntoa(*((struct in_addr*)
  12686. server->h_addr_list[0]));
  12687. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12688. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12689. /* format : ftpput -u username -p passwd IP target source*/
  12690. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12691. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12692. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12693. systemresult = system(ftpbuf);
  12694. DEBUG_INFO("systemresult=%d\n",systemresult);
  12695. if(systemresult != 0)
  12696. {
  12697. DEBUG_INFO("ftpput error!\n");
  12698. return FALSE;
  12699. }
  12700. return TRUE;
  12701. }
  12702. /**
  12703. * Place the contents of the specified file into a memory buffer
  12704. *
  12705. * @param[in] filename The path and name of the file to read
  12706. * @param[out] filebuffer A pointer to the contents in memory
  12707. * @return status 0 success, 1 on failure
  12708. */
  12709. int get_file_contents(const char* filename, char** outbuffer) {
  12710. FILE* file = NULL;
  12711. long filesize;
  12712. const int blocksize = 1;
  12713. size_t readsize;
  12714. char* filebuffer;
  12715. // Open the file
  12716. file = fopen(filename, "r");
  12717. if (NULL == file)
  12718. {
  12719. printf("'%s' not opened\n", filename);
  12720. exit(EXIT_FAILURE);
  12721. }
  12722. // Determine the file size
  12723. fseek(file, 0, SEEK_END);
  12724. filesize = ftell(file);
  12725. rewind (file);
  12726. // Allocate memory for the file contents
  12727. filebuffer = (char*) malloc(sizeof(char) * filesize);
  12728. *outbuffer = filebuffer;
  12729. if (filebuffer == NULL)
  12730. {
  12731. fputs ("malloc out-of-memory", stderr);
  12732. exit(EXIT_FAILURE);
  12733. }
  12734. // Read in the file
  12735. readsize = fread(filebuffer, blocksize, filesize, file);
  12736. if (readsize != filesize)
  12737. {
  12738. fputs ("didn't read file completely",stderr);
  12739. exit(EXIT_FAILURE);
  12740. }
  12741. // Clean exit
  12742. fclose(file);
  12743. return EXIT_SUCCESS;
  12744. }
  12745. static int selectSqlCount = 0;
  12746. static int callback(void *data, int argc, char **argv, char **azColName){
  12747. int i;
  12748. //printf("%s: ", (const char*)data);
  12749. selectSqlCount = argc;
  12750. for(i = 0; i<argc; i++){
  12751. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  12752. }
  12753. //printf("\n");
  12754. return 0;
  12755. }
  12756. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  12757. //int i;
  12758. //printf("%s:\n", (const char*)data);
  12759. localversion = argv[5] ? atoi(argv[5]) : 0;
  12760. //printf("localversion=%d\n", localversion);
  12761. return 0;
  12762. }
  12763. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  12764. //int i;
  12765. //printf("%s:\n", (const char*)data);
  12766. //idTag
  12767. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  12768. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  12769. //parentIdTag
  12770. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  12771. //expir_date
  12772. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  12773. //status
  12774. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  12775. //version
  12776. idTagQuery.listVersionInt = atoi(argv[5]);
  12777. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  12778. return 0;
  12779. }
  12780. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  12781. {
  12782. // localversion = argv[5] ? atoi(argv[5]) : 0;
  12783. // printf("localversion=%d\n", localversion);
  12784. return 0;
  12785. }
  12786. //=========================================
  12787. // Sqlite3 related function
  12788. //=========================================
  12789. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  12790. {
  12791. for (int i = 0; i < n_columns; i++)
  12792. {
  12793. DEBUG_INFO("%s\t", col_values[i]);
  12794. }
  12795. DEBUG_INFO("\n");
  12796. return 0;
  12797. }
  12798. void OCPP_getListVerion()
  12799. {
  12800. int rc = 0;
  12801. // const char* data = "Callback function called";
  12802. char sql[100];
  12803. char zErrMsg[100];
  12804. memset(sql, 0, 100);
  12805. memset(zErrMsg, 0, 100);
  12806. strcpy(sql, "select * from ocpp_auth_local order by idx");
  12807. /* Execute SQL statement */
  12808. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  12809. if( rc != SQLITE_OK )
  12810. {
  12811. DEBUG_INFO("SQL error: %s", zErrMsg);
  12812. }
  12813. }
  12814. void OCPP_getIdTag(char idTag[])
  12815. {
  12816. int rc = 0;
  12817. // const char* data = "Callback function called";
  12818. char sql[100];
  12819. char zErrMsg[100];
  12820. memset(sql, 0, 100);
  12821. memset(zErrMsg, 0, 100);
  12822. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  12823. memset(&idTagQuery, 0, sizeof(idTagQuery));
  12824. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  12825. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12826. /* Execute SQL statement */
  12827. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  12828. if( rc != SQLITE_OK )
  12829. {
  12830. DEBUG_INFO("SQL error: %s", zErrMsg);
  12831. }
  12832. //return ver;
  12833. }
  12834. void OCPP_get_TableAuthlocalAllData(void)
  12835. {
  12836. int rc = 0;
  12837. char sql[100];
  12838. char zErrMsg[100];
  12839. memset(sql, 0, 100);
  12840. memset(zErrMsg, 0, 100);
  12841. sprintf(sql,"select * from ocpp_auth_local ");
  12842. /* Execute SQL statement */
  12843. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  12844. if( rc != SQLITE_OK )
  12845. {
  12846. DEBUG_INFO("SQL error: %s", zErrMsg);
  12847. }
  12848. //return ver;
  12849. }
  12850. int OCPP_cleanLocalList()
  12851. {
  12852. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  12853. char *errMsg = 0;
  12854. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  12855. if (SQLITE_OK != rc)
  12856. {
  12857. DEBUG_INFO("%s\n",errMsg);
  12858. return FALSE;
  12859. }
  12860. return TRUE;
  12861. }
  12862. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12863. {
  12864. int isSuccess = FALSE;
  12865. int ret = 0;
  12866. //const char* data = "Callback function called";
  12867. char sql[300];
  12868. char zErrMsg[200];
  12869. memset(sql, 0, 300);
  12870. memset(zErrMsg, 0, 200);
  12871. 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);
  12872. //* Execute SQL statement */
  12873. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  12874. if( ret != SQLITE_OK )
  12875. {
  12876. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12877. return isSuccess;
  12878. }
  12879. memset(sql, 0, 300);
  12880. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  12881. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  12882. if( ret != SQLITE_OK )
  12883. {
  12884. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12885. return isSuccess;
  12886. }
  12887. isSuccess = TRUE;
  12888. return isSuccess;
  12889. }
  12890. void OCPP_deleteIdTag(char idTag[])
  12891. {
  12892. //int ver = 0;
  12893. //int isSuccess = FALSE;
  12894. int rc = 0;
  12895. char sql[100];
  12896. char zErrMsg[100];
  12897. memset(sql, 0, 100);
  12898. memset(zErrMsg, 0, 100);
  12899. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  12900. //* Execute SQL statement */
  12901. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  12902. if( rc != SQLITE_OK )
  12903. {
  12904. DEBUG_INFO("SQL error: %s", zErrMsg);
  12905. }
  12906. }
  12907. int GetOcppServerURL()
  12908. {
  12909. int result = FALSE;
  12910. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  12911. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  12912. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  12913. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  12914. {
  12915. #if 1
  12916. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  12917. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12918. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12919. #endif
  12920. result = TRUE;
  12921. goto End;
  12922. }
  12923. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  12924. {
  12925. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  12926. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12927. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12928. result = TRUE;
  12929. goto End;
  12930. }
  12931. else
  12932. {
  12933. strcpy(OcppHost,"");
  12934. }
  12935. End:
  12936. return result;
  12937. }
  12938. int GetOcppPath()
  12939. {
  12940. int result = FALSE;
  12941. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  12942. {
  12943. if(OcppTempPath == NULL)
  12944. {
  12945. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12946. }
  12947. else
  12948. {
  12949. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12950. }
  12951. result = TRUE;
  12952. goto End;
  12953. }
  12954. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  12955. {
  12956. if(OcppTempPath == NULL)
  12957. {
  12958. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  12959. }
  12960. else
  12961. {
  12962. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  12963. }
  12964. result = TRUE;
  12965. goto End;
  12966. }
  12967. else
  12968. {
  12969. strcpy(OcppPath,"");
  12970. }
  12971. End:
  12972. return result;
  12973. }
  12974. int GetOcppPort()
  12975. {
  12976. return OcppPort;
  12977. }
  12978. int GetOcppConnStatus(void)
  12979. {
  12980. return ShmOCPP16Data->OcppConnStatus;
  12981. }
  12982. void SetOcppConnStatus(uint8_t status)
  12983. {
  12984. ShmOCPP16Data->OcppConnStatus = status;
  12985. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  12986. }
  12987. int GetHeartBeatWithNOResponse(void)
  12988. {
  12989. return HeartBeatWithNOResponse;
  12990. }
  12991. void SetHeartBeatWithNOResponse(void)
  12992. {
  12993. HeartBeatWithNOResponse = 0;
  12994. }
  12995. void GetStartTransactionIdTag(int gun_index)
  12996. {
  12997. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  12998. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  12999. }
  13000. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  13001. {
  13002. char ch;
  13003. FILE *fptr1;
  13004. int temptransactionId;
  13005. char str[100]={0};
  13006. temptransactionId = 0;
  13007. if((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0'))
  13008. {
  13009. DEBUG_INFO("IdTag is empty.\n");
  13010. return temptransactionId;
  13011. }
  13012. /*------ Read the file ----------------*/
  13013. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  13014. if (!fptr1)
  13015. {
  13016. DEBUG_INFO("QueueTransactionId file open error.\n");
  13017. //printf(" File not found or unable to open the input file!!\n");
  13018. return temptransactionId;
  13019. }
  13020. ch=fgetc(fptr1);
  13021. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13022. rewind(fptr1);
  13023. if(ch!=EOF)
  13024. {
  13025. // printf("%c",ch);
  13026. while (fgets(str, 100, fptr1) != NULL)
  13027. {
  13028. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13029. if(str[0]=='\0')
  13030. {
  13031. break;
  13032. }
  13033. char *revbuf[8] = {0}; //存放分割後的子字串
  13034. int num = 0;//分割後子字串的個數
  13035. DEBUG_INFO("str: %s\n", str);
  13036. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  13037. DEBUG_INFO("revbuf[0]: %s\n", revbuf[0]);
  13038. DEBUG_INFO("revbuf[1]: %s\n", revbuf[1]);
  13039. DEBUG_INFO("revbuf[2]: %s\n", revbuf[2]);
  13040. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13041. {
  13042. if(isStopTransaction)
  13043. {
  13044. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  13045. {
  13046. temptransactionId = atoi(revbuf[2]);
  13047. break;
  13048. }
  13049. }
  13050. else
  13051. {
  13052. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13053. {
  13054. temptransactionId = atoi(revbuf[2]);
  13055. break;
  13056. }
  13057. }
  13058. }
  13059. }
  13060. }
  13061. else
  13062. DEBUG_INFO("EOF\n");
  13063. fclose(fptr1);
  13064. /*------- End of reading ---------------*/
  13065. return temptransactionId;
  13066. }
  13067. void SetTransactionIdZero(int transactionId)
  13068. {
  13069. char ch;
  13070. FILE *fptr1, *fptr2;
  13071. int temptransactionId = 0;
  13072. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13073. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13074. if (!fptr1)
  13075. {
  13076. //printf(" File not found or unable to open the input file!!\n");
  13077. return ;
  13078. }
  13079. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13080. if (!fptr2)
  13081. {
  13082. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  13083. fclose(fptr1);
  13084. return ;
  13085. }
  13086. ch=fgetc(fptr1);
  13087. rewind(fptr1);
  13088. if(ch!=EOF)
  13089. {
  13090. // copy all contents to the temporary file except the specific line
  13091. while (fgets(str, 100, fptr1) != NULL)
  13092. {
  13093. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13094. if(str[0]=='\0')
  13095. {
  13096. break;
  13097. }
  13098. char *revbuf[8] = {0};
  13099. int num = 0;
  13100. strcpy(strtemp, str);
  13101. splitstring(str,",",revbuf,&num);
  13102. if(revbuf[2][0] != '\0')
  13103. {
  13104. temptransactionId = atoi(revbuf[2]);
  13105. if(transactionId != temptransactionId)
  13106. {
  13107. fprintf(fptr2, "%s\n", strtemp);
  13108. }
  13109. }
  13110. }
  13111. }
  13112. fclose(fptr1);
  13113. fclose(fptr2);
  13114. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13115. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13116. /*------ Read the file ----------------*/
  13117. }
  13118. int InternetDisconnect(void)
  13119. {
  13120. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13121. }
  13122. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  13123. void storeTempStopTransaction(int gun_index)
  13124. {
  13125. char guid[37]={0};
  13126. int tempIndex = 0;
  13127. DEBUG_INFO("storeTempStopTransaction...\n");
  13128. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  13129. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  13130. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13131. if(gunType[gun_index] == 'J')
  13132. {
  13133. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13134. {
  13135. tempIndex = ((gun_index==2) ? 1: 0);
  13136. }
  13137. else
  13138. {
  13139. tempIndex = gun_index;
  13140. }
  13141. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13142. {
  13143. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13144. {
  13145. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  13146. }
  13147. }// END OF CHAdeMO_QUANTITY
  13148. }
  13149. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13150. {
  13151. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13152. {
  13153. tempIndex = ((gun_index==2) ? 1: 0);
  13154. }
  13155. else
  13156. {
  13157. tempIndex = gun_index;
  13158. }
  13159. for (int index = 0; index < CCS_QUANTITY; index++)
  13160. {
  13161. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13162. {
  13163. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  13164. }
  13165. }// END OF CCS_QUANTITY
  13166. }
  13167. else if(gunType[gun_index] == 'G')
  13168. {
  13169. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13170. {
  13171. tempIndex = ((gun_index==2) ? 1: 0);
  13172. }
  13173. else
  13174. {
  13175. tempIndex = gun_index;
  13176. }
  13177. for (int index = 0; index < GB_QUANTITY; index++)
  13178. {
  13179. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13180. {
  13181. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  13182. }
  13183. }// END OF GB_QUANTITY
  13184. }
  13185. else
  13186. {
  13187. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13188. {
  13189. tempIndex = 2;
  13190. }
  13191. else
  13192. {
  13193. tempIndex = gun_index;
  13194. }
  13195. for (int index = 0; index < AC_QUANTITY; index++)
  13196. {
  13197. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13198. {
  13199. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  13200. }
  13201. }// END OF AC_QUANTITY
  13202. }
  13203. //Stop Transaction Time
  13204. struct timeval tmnow;
  13205. struct tm *tm;
  13206. char buf[28];//, usec_buf[6];
  13207. gettimeofday(&tmnow, NULL);
  13208. time_t t;
  13209. t = time(NULL);
  13210. /*UTC time and date*/
  13211. tm = gmtime(&t);
  13212. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  13213. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  13214. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  13215. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13216. random_uuid(guid);
  13217. /***********************************transactionData******************************************************/
  13218. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  13219. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  13220. //=================================
  13221. //1. Transaction_Begin
  13222. //=================================
  13223. //============================== Energy.Active.Import.Interval ===========================================
  13224. //idx_sample=0;
  13225. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  13226. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  13227. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  13228. 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*/]);
  13229. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13230. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13231. {
  13232. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  13233. }
  13234. else
  13235. {
  13236. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  13237. }
  13238. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  13239. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13240. //=================================
  13241. //2. Transaction_End
  13242. //=================================
  13243. //2.1====================================== Current.Import L1 ==============================================
  13244. //idx_sample=1;
  13245. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  13246. if(gunType[gun_index] == 'J')
  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 < CHAdeMO_QUANTITY; index++)
  13257. {
  13258. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13259. {
  13260. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13261. }
  13262. }// End of for CHAdeMO_QUANTITY
  13263. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13264. }
  13265. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13266. {
  13267. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13268. {
  13269. tempIndex = ((gun_index==2) ? 1: 0);
  13270. }
  13271. else
  13272. {
  13273. tempIndex = gun_index;
  13274. }
  13275. for (int index = 0; index < CCS_QUANTITY; index++)
  13276. {
  13277. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13278. {
  13279. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13280. }
  13281. }// End of for CCS_QUANTITY
  13282. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13283. }
  13284. else if(gunType[gun_index] == 'G')
  13285. {
  13286. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13287. {
  13288. tempIndex = ((gun_index==2) ? 1: 0);
  13289. }
  13290. else
  13291. {
  13292. tempIndex = gun_index;
  13293. }
  13294. for (int index = 0; index < GB_QUANTITY; index++)
  13295. {
  13296. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13297. {
  13298. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13299. }
  13300. }// End of for GB_QUANTITY
  13301. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13302. }
  13303. else
  13304. {
  13305. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13306. {
  13307. tempIndex = 2;
  13308. }
  13309. else
  13310. {
  13311. tempIndex = gun_index;
  13312. }
  13313. for (int index = 0; index < AC_QUANTITY; index++)
  13314. {
  13315. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13316. {
  13317. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  13318. }
  13319. }// End of for AC_QUANTITY
  13320. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13321. }
  13322. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13323. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  13324. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  13325. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13326. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  13327. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13328. //2.2===================================== Energy.Active.Import.Interval ==========================================
  13329. //idx_sample=2;
  13330. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13331. if(gunType[gun_index] == 'J')
  13332. {
  13333. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13334. {
  13335. tempIndex = ((gun_index==2) ? 1: 0);
  13336. }
  13337. else
  13338. {
  13339. tempIndex = gun_index;
  13340. }
  13341. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13342. {
  13343. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13344. {
  13345. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13346. }
  13347. }// END OF CHAdeMO_QUANTITY
  13348. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13349. }
  13350. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13351. {
  13352. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13353. {
  13354. tempIndex = ((gun_index==2) ? 1: 0);
  13355. }
  13356. else
  13357. {
  13358. tempIndex = gun_index;
  13359. }
  13360. for (int index = 0; index < CCS_QUANTITY; index++)
  13361. {
  13362. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13363. {
  13364. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13365. }
  13366. }// END OF CCS_QUANTITY
  13367. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13368. }
  13369. else if(gunType[gun_index] == 'G')
  13370. {
  13371. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13372. {
  13373. tempIndex = ((gun_index==2) ? 1: 0);
  13374. }
  13375. else
  13376. {
  13377. tempIndex = gun_index;
  13378. }
  13379. for (int index = 0; index < GB_QUANTITY; index++)
  13380. {
  13381. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13382. {
  13383. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13384. }
  13385. }// END OF GB_QUANTITY
  13386. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13387. }
  13388. else
  13389. {
  13390. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13391. {
  13392. tempIndex = 2;
  13393. }
  13394. else
  13395. {
  13396. tempIndex = gun_index;
  13397. }
  13398. for (int index = 0; index < AC_QUANTITY; index++)
  13399. {
  13400. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13401. {
  13402. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13403. }
  13404. }// END OF AC_QUANTITY
  13405. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13406. }
  13407. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13408. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  13409. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  13410. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13411. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  13412. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13413. //2.3====================================== Power.Active.Import =========================================
  13414. //idx_sample=3;
  13415. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13416. if(gunType[gun_index] == 'J')
  13417. {
  13418. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13419. {
  13420. tempIndex = ((gun_index==2) ? 1: 0);
  13421. }
  13422. else
  13423. {
  13424. tempIndex = gun_index;
  13425. }
  13426. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13427. {
  13428. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13429. {
  13430. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13431. }
  13432. } // End for CHAdeMO_QUANTITY
  13433. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13434. }
  13435. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13436. {
  13437. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13438. {
  13439. tempIndex = ((gun_index==2) ? 1: 0);
  13440. }
  13441. else
  13442. {
  13443. tempIndex = gun_index;
  13444. }
  13445. for (int index = 0; index < CCS_QUANTITY; index++)
  13446. {
  13447. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13448. {
  13449. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13450. }
  13451. } // END for CCS_QUANTITY
  13452. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13453. }
  13454. else if(gunType[gun_index] == 'G')
  13455. {
  13456. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13457. {
  13458. tempIndex = ((gun_index==2) ? 1: 0);
  13459. }
  13460. else
  13461. {
  13462. tempIndex = gun_index;
  13463. }
  13464. for (int index = 0; index < GB_QUANTITY; index++)
  13465. {
  13466. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13467. {
  13468. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13469. }
  13470. }// END for GB_QUANTITY
  13471. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13472. }
  13473. else
  13474. {
  13475. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13476. {
  13477. tempIndex = 2;
  13478. }
  13479. else
  13480. {
  13481. tempIndex = gun_index;
  13482. }
  13483. for (int index = 0; index < AC_QUANTITY; index++)
  13484. {
  13485. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13486. {
  13487. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13488. }
  13489. } // END for AC_QUANTITY
  13490. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13491. }
  13492. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13493. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  13494. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  13495. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13496. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  13497. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  13498. //2.4====================================== Voltage L1 ====================================================
  13499. //idx_sample=4;
  13500. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13501. if(gunType[gun_index] == 'J')
  13502. {
  13503. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13504. {
  13505. tempIndex = ((gun_index==2) ? 1: 0);
  13506. }
  13507. else
  13508. {
  13509. tempIndex = gun_index;
  13510. }
  13511. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13512. {
  13513. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13514. {
  13515. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13516. }
  13517. } // END OF FOR CHAdeMO_QUANTITY
  13518. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13519. }
  13520. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13521. {
  13522. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13523. {
  13524. tempIndex = ((gun_index==2) ? 1: 0);
  13525. }
  13526. else
  13527. {
  13528. tempIndex = gun_index;
  13529. }
  13530. for (int index = 0; index < CCS_QUANTITY; index++)
  13531. {
  13532. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13533. {
  13534. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13535. }
  13536. } // END OF FOR CCS_QUANTITY
  13537. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13538. }
  13539. else if(gunType[gun_index] == 'G')
  13540. {
  13541. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13542. {
  13543. tempIndex = ((gun_index==2) ? 1: 0);
  13544. }
  13545. else
  13546. {
  13547. tempIndex = gun_index;
  13548. }
  13549. for (int index = 0; index < GB_QUANTITY; index++)
  13550. {
  13551. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13552. {
  13553. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13554. }
  13555. } // END OF FOR GB_QUANTITY
  13556. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13557. }
  13558. else
  13559. {
  13560. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13561. {
  13562. tempIndex = 2;
  13563. }
  13564. else
  13565. {
  13566. tempIndex = gun_index;
  13567. }
  13568. for (int index = 0; index < AC_QUANTITY; index++)
  13569. {
  13570. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13571. {
  13572. 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
  13573. }
  13574. } // END OF FOR AC_QUANTITY
  13575. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13576. }
  13577. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13578. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  13579. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  13580. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13581. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  13582. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13583. //2.5============================================== SoC =========================================================
  13584. //idx_sample=5;
  13585. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13586. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13587. {
  13588. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13589. {
  13590. tempIndex = ((gun_index==2) ? 1: 0);
  13591. }
  13592. else
  13593. {
  13594. tempIndex = gun_index;
  13595. }
  13596. if(gunType[gun_index] == 'J')
  13597. {
  13598. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13599. {
  13600. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13601. {
  13602. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  13603. }
  13604. }
  13605. }
  13606. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13607. {
  13608. for (int index = 0; index < CCS_QUANTITY; index++)
  13609. {
  13610. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13611. {
  13612. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  13613. }
  13614. }
  13615. }
  13616. else if(gunType[gun_index] == 'G')
  13617. {
  13618. for (int index = 0; index < GB_QUANTITY; index++)
  13619. {
  13620. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13621. {
  13622. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  13623. }
  13624. }
  13625. }
  13626. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13627. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  13628. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  13629. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  13630. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  13631. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  13632. } // END FOR DC CASE
  13633. //2.6====================================== Current.Import L2 ==============================================
  13634. // idx_sample=6;
  13635. // AC 3 phase L2 current
  13636. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13637. {
  13638. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13639. {
  13640. tempIndex = 2;
  13641. }
  13642. else
  13643. {
  13644. tempIndex = gun_index;
  13645. }
  13646. for (int index = 0; index < AC_QUANTITY; index++)
  13647. {
  13648. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13649. {
  13650. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  13651. }
  13652. }// End of for AC_QUANTITY
  13653. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  13654. }
  13655. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13656. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  13657. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  13658. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  13659. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13660. //2.7====================================== Current.Import L3 ==============================================
  13661. // idx_sample=7;
  13662. // AC 3 phase L3 current
  13663. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13664. {
  13665. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13666. {
  13667. tempIndex = 2;
  13668. }
  13669. else
  13670. {
  13671. tempIndex = gun_index;
  13672. }
  13673. for (int index = 0; index < AC_QUANTITY; index++)
  13674. {
  13675. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13676. {
  13677. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  13678. }
  13679. }// End of for AC_QUANTITY
  13680. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  13681. }
  13682. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13683. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  13684. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  13685. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  13686. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13687. //2.9====================================== Voltage L2 ====================================================
  13688. //idx_sample=8;
  13689. // AC 3 phase L2 volatge
  13690. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13691. {
  13692. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13693. {
  13694. tempIndex = 2;
  13695. }
  13696. else
  13697. {
  13698. tempIndex = gun_index;
  13699. }
  13700. for (int index = 0; index < AC_QUANTITY; index++)
  13701. {
  13702. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13703. {
  13704. 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
  13705. }
  13706. } // END OF FOR AC_QUANTITY
  13707. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  13708. }
  13709. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13710. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  13711. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  13712. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  13713. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13714. //2.10====================================== Voltage L3 ====================================================
  13715. //idx_sample=9;
  13716. // AC 3 phase L3 volatge
  13717. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13718. {
  13719. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13720. {
  13721. tempIndex = 2;
  13722. }
  13723. else
  13724. {
  13725. tempIndex = gun_index;
  13726. }
  13727. for (int index = 0; index < AC_QUANTITY; index++)
  13728. {
  13729. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13730. {
  13731. 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
  13732. }
  13733. } // END OF FOR AC_QUANTITY
  13734. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  13735. }
  13736. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13737. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  13738. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  13739. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  13740. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13741. //======================================== Message create ==============================================
  13742. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13743. {
  13744. 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\"}]}]}]"
  13745. ,gun_index+1
  13746. ,MESSAGE_TYPE_CALL
  13747. ,guid
  13748. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13749. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13750. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13751. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13752. ,"PowerLoss"
  13753. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13754. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13755. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13756. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13757. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13758. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13759. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13760. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13761. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13762. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13763. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13764. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13765. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13766. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13767. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13768. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13769. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13770. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13771. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13772. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13773. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13774. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13775. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13776. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13777. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13778. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13779. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13780. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13781. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13782. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13783. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13784. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13785. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13786. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13787. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13788. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13789. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  13790. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  13791. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  13792. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  13793. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  13794. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  13795. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  13796. );
  13797. }
  13798. else
  13799. {
  13800. if(((ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'W')))
  13801. {
  13802. 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\"}]}]}]"
  13803. ,gun_index+1
  13804. ,MESSAGE_TYPE_CALL
  13805. ,guid
  13806. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13807. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13808. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13809. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13810. ,"PowerLoss"
  13811. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13812. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13813. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13814. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13815. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13816. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13817. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13818. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13819. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13820. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13821. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13822. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13823. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13824. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13825. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13826. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13827. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13828. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13829. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13830. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13831. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13832. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13833. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13834. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13835. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13836. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13837. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13838. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13839. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13840. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13841. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13842. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13843. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13844. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13845. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13846. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13847. );
  13848. }
  13849. else
  13850. {
  13851. 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\"}]}]}]"
  13852. ,gun_index+1
  13853. ,MESSAGE_TYPE_CALL
  13854. ,guid
  13855. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13856. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13857. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13858. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13859. ,"PowerLoss"
  13860. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13861. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13862. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13863. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13864. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13865. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13866. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13867. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13868. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13869. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13870. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13871. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13872. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13873. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13874. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13875. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13876. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13877. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13878. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13879. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13880. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13881. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13882. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13883. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13884. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13885. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13886. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13887. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13888. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13889. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13890. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13891. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13892. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13893. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13894. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13895. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13896. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value
  13897. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context
  13898. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format
  13899. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand
  13900. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase
  13901. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location
  13902. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit
  13903. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value
  13904. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context
  13905. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format
  13906. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand
  13907. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase
  13908. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location
  13909. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit
  13910. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value
  13911. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context
  13912. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format
  13913. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand
  13914. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase
  13915. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location
  13916. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit
  13917. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value
  13918. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context
  13919. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format
  13920. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand
  13921. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase
  13922. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location
  13923. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit
  13924. );
  13925. }
  13926. }
  13927. // Check File "TempStopTransaction" Exist
  13928. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  13929. {
  13930. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  13931. fclose(fopen("/Storage/OCPP/TempStopTransaction", "w"));
  13932. }
  13933. else
  13934. {
  13935. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  13936. FILE *log = fopen("/Storage/OCPP/TempStopTransaction", "w+");
  13937. if(log == NULL)
  13938. {
  13939. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  13940. return ;
  13941. }
  13942. else
  13943. {
  13944. fclose(log);
  13945. }
  13946. }
  13947. //Add TempStopTransaction | Update TempStopTransaction
  13948. // open file for writing
  13949. FILE *outfile;
  13950. outfile = fopen ("/Storage/OCPP/TempStopTransaction", "a");
  13951. //DEBUG_INFO("data = %s\n", queuedata);
  13952. fputs(queuedata, outfile);
  13953. fputs("\n", outfile);
  13954. fclose (outfile);
  13955. }
  13956. void checkTempStopTransaction(int gun_index)
  13957. {
  13958. FILE *fptr1;
  13959. char ch;
  13960. char str[QUEUE_MESSAGE_LENGTH]={0};
  13961. char guid[37]={0};
  13962. char tempdata[65]={0};
  13963. char connectorStr[2]={0};
  13964. fptr1 = fopen("/Storage/OCPP/TempStopTransaction", "r");
  13965. //TempStopTransaction格式: 槍號,StopTransaction封包
  13966. if (!fptr1)
  13967. {
  13968. //printf(" File not found or unable to open the input file!!\n");
  13969. return ;
  13970. }
  13971. ch=fgetc(fptr1);
  13972. //printf(" Now the content of the file %s is : \n",fname);
  13973. rewind(fptr1);
  13974. if(ch!=EOF)
  13975. {
  13976. // copy all contents to the temporary file except the specific line
  13977. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  13978. {
  13979. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13980. if(str[0]=='\0')
  13981. {
  13982. break;
  13983. }
  13984. //TempStopTransaction格式: 槍號,StopTransaction封包
  13985. strncpy(connectorStr, str, 1);
  13986. if(atoi(connectorStr) != (gun_index+1))
  13987. {
  13988. DEBUG_INFO("atoi(connectorStr) = %d\n", atoi(connectorStr));
  13989. return ;
  13990. }
  13991. //random_uuid(guid);
  13992. strncpy(guid, str+6, 36); //copy guid
  13993. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  13994. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  13995. {
  13996. DEBUG_INFO("StopTransaction mapitem pass\n");
  13997. }
  13998. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  13999. memset(str,0,ARRAY_SIZE(str));
  14000. }
  14001. }
  14002. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  14003. fclose(fptr1);
  14004. remove("/Storage/OCPP/TempStopTransaction"); // remove the original file
  14005. }
  14006. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  14007. {
  14008. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  14009. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  14010. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  14011. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  14012. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14013. }
  14014. int GetWebSocketPingInterval(void)
  14015. {
  14016. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14017. }
  14018. int GetServerSign(void)
  14019. {
  14020. return server_sign;
  14021. }
  14022. void SetServerSign(int value)
  14023. {
  14024. server_sign = value;
  14025. }
  14026. int GetBootNotificationInterval(void)
  14027. {
  14028. return BootNotificationInterval;
  14029. }
  14030. int GetInternetConn(void)
  14031. {
  14032. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  14033. }
  14034. void InitialSystemValue(void)
  14035. {
  14036. int connectorIndex = 0;
  14037. //int valueASCII = 0;
  14038. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14039. gunTotalNumber=0;
  14040. SystemInitial = 0;
  14041. localversion=0;
  14042. BootNotificationInterval = 0;
  14043. authorizeRetryTimes = 0;
  14044. GunStatusInterval = 10;
  14045. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14046. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14047. //Hear Beat
  14048. HeartBeatWithNOResponse = 0;
  14049. HeartBeatCountPerHour = 0;
  14050. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  14051. FirstHeartBeat = 0;
  14052. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  14053. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  14054. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  14055. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  14056. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  14057. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  14058. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  14059. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  14060. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  14061. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  14062. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  14063. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  14064. memset(gunType, 0, ARRAY_SIZE(gunType));
  14065. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14066. {
  14067. //check connector / socket type (index: 8, 9, 10)
  14068. for(int index=7; index <10 ; index++)
  14069. {
  14070. if(index != 8)
  14071. {
  14072. // DC Connector
  14073. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] >= 'A') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= 'Z'))
  14074. {
  14075. SystemInitial = SystemInitial + 1;
  14076. gunTotalNumber = gunTotalNumber + 1;
  14077. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14078. connectorIndex = connectorIndex + 1;
  14079. }
  14080. }
  14081. else
  14082. {
  14083. // AC Connector
  14084. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14085. {
  14086. SystemInitial = SystemInitial + 1;
  14087. gunTotalNumber = gunTotalNumber + 1;
  14088. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14089. connectorIndex = connectorIndex + 1;
  14090. }
  14091. }
  14092. }
  14093. //DEBUG_INFO("DC ...\n");
  14094. }
  14095. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  14096. {
  14097. //check connector / socket type (index: 8, 9, 10)
  14098. for(int index=7; index <10 ; index++)
  14099. {
  14100. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14101. {
  14102. SystemInitial = SystemInitial + 1;
  14103. gunTotalNumber = gunTotalNumber + 1;
  14104. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14105. connectorIndex = connectorIndex + 1;
  14106. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  14107. }
  14108. }
  14109. }
  14110. //Status && ConnectorPlugIn Setting
  14111. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14112. {
  14113. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  14114. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  14115. }
  14116. for (int index = 0; index < CCS_QUANTITY; index++)
  14117. {
  14118. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  14119. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  14120. }
  14121. for (int index = 0; index < GB_QUANTITY; index++)
  14122. {
  14123. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  14124. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  14125. }
  14126. for (int index = 0; index < AC_QUANTITY; index++)
  14127. {
  14128. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  14129. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  14130. }
  14131. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  14132. {
  14133. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14134. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  14135. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  14136. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  14137. }
  14138. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  14139. clientTime.Heartbeat=time((time_t*)NULL);
  14140. sleep(1);
  14141. }
  14142. void LWS_Send(char * str)
  14143. {
  14144. //=====================================================
  14145. // Check InternetConn 0: disconnected, 1: connected
  14146. //====================================================
  14147. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14148. {
  14149. DEBUG_INFO("offline now !!!\n");
  14150. return;
  14151. }
  14152. pthread_mutex_lock(&lock_send);
  14153. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14154. sprintf((char *)SendBuffer, "%s", str);
  14155. SendBufLen = strlen(str);
  14156. pthread_mutex_unlock(&lock_send);
  14157. lws_callback_on_writable(wsi_client);
  14158. //lws_service(context, 0);
  14159. //sleep(1);
  14160. }