MessageHandler.c 676 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250
  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. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  425. //DEBUG_INFO("Stop: %d-%d-%d %d:%d:%d\n", tmStop.tm_year, tmStop.tm_mon, tmStop.tm_mday, tmStop.tm_hour, tmStop.tm_min, tmStop.tm_sec);
  426. tmStart.tm_year -= 1900;
  427. tmStart.tm_mon -= 1;
  428. tbStart.time = mktime(&tmStart);
  429. tbStart.millitm = 0;
  430. tmStop.tm_year -= 1900;
  431. tmStop.tm_mon -= 1;
  432. tbStop.time = mktime(&tmStop);
  433. tbStop.millitm = 0;
  434. result = DiffTimebSec(tbStart, tbStop);
  435. //DEBUG_INFO("getStartStop(): %d\n", result);
  436. }
  437. else
  438. {
  439. DEBUG_WARN("Start or stop date parsing error.\r\n");
  440. }
  441. return result;
  442. }
  443. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  444. {
  445. int result = -1;
  446. struct tm tmStart;
  447. struct timeb tbStart;
  448. struct tm tmStop;
  449. struct timeb tbStop;
  450. 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) &&
  451. (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))
  452. {
  453. tmStart.tm_year -= 1900;
  454. tmStart.tm_mon -= 1;
  455. tbStart.time = mktime(&tmStart);
  456. tbStart.millitm = 0;
  457. tmStop.tm_year -= 1900;
  458. tmStop.tm_mon -= 1;
  459. tbStop.time = mktime(&tmStop);
  460. tbStop.millitm = 0;
  461. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  462. }
  463. return result;
  464. }
  465. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile)
  466. {
  467. FILE *fp;
  468. char profileFileName[128];
  469. char *line = NULL;
  470. size_t len = 0;
  471. time_t CurrentTime;
  472. struct tm *tmComposite;
  473. struct StructChargingProfile maxProfile;
  474. struct StructChargingProfile defaultTxProfile;
  475. struct StructChargingProfile txProfile;
  476. struct StructChargingSchedulePeriod tmpPeriod;
  477. uint8_t limitMax=0;
  478. uint8_t limitDef=0;
  479. uint8_t limitTx=0;
  480. int compositePeriodIdx = 0;
  481. CurrentTime = time(NULL);
  482. tmComposite=localtime(&CurrentTime);
  483. 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);
  484. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  485. compositeProfile->ChargingSchedule.Duration = durationReq;
  486. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  487. {
  488. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  489. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  490. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  491. }
  492. compositeProfile->ChargingProfileId = 0;
  493. compositeProfile->StackLevel = 99 ;
  494. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  495. maxProfile.ChargingProfileId = -1;
  496. defaultTxProfile.ChargingProfileId = -1;
  497. txProfile.ChargingProfileId = -1;
  498. maxProfile.ChargingSchedule.Duration = -1;
  499. defaultTxProfile.ChargingSchedule.Duration = -1;
  500. txProfile.ChargingSchedule.Duration = -1;
  501. system("yes|rm /tmp/*.json");
  502. system("cp /Storage/OCPP/*.json /tmp");
  503. /*
  504. * Search valid charging profile
  505. */
  506. //DEBUG_INFO("====================================\n");
  507. // Search tx profile
  508. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  509. if((access(profileFileName, F_OK))!=-1)
  510. {
  511. fp = fopen(profileFileName, "r");
  512. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  513. {
  514. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  515. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  516. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  517. }
  518. txProfile.ChargingProfileId = -1;
  519. txProfile.StackLevel = -1;
  520. while(getline(&line, &len, fp) != -1)
  521. {
  522. json_object *obj = NULL;
  523. obj = json_tokener_parse(line);
  524. if(is_error(obj))
  525. {
  526. DEBUG_ERROR("Parse txProfile from file error.\n");
  527. }
  528. else
  529. {
  530. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  531. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  532. )
  533. {
  534. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  535. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  536. )
  537. {
  538. struct tm tmFrom, tmTo;
  539. struct timeb tbFrom, tbTo;
  540. 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) &&
  541. (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))
  542. {
  543. tmFrom.tm_year -= 1900;
  544. tmFrom.tm_mon -= 1;
  545. tbFrom.time = mktime(&tmFrom);
  546. tmTo.tm_year -= 1900;
  547. tmTo.tm_mon -= 1;
  548. tbTo.time = mktime(&tmTo);
  549. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  550. {
  551. if(txProfile.ChargingProfileId == -1)
  552. DEBUG_INFO("TxProfile found.\n");
  553. else
  554. DEBUG_INFO("TxProfile updated.\n");
  555. // Required item
  556. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  557. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  558. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  559. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  560. 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++)
  561. {
  562. 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"));
  563. 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")));
  564. 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?
  565. 3:
  566. 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")));
  567. }
  568. // Optional item
  569. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  570. {
  571. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  572. }
  573. else
  574. {
  575. sprintf((char*)txProfile.ValidFrom, " ");
  576. }
  577. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  578. {
  579. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  580. }
  581. else
  582. {
  583. sprintf((char*)txProfile.ValidTo, " ");
  584. }
  585. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  586. {
  587. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  588. }
  589. else
  590. {
  591. sprintf((char*)txProfile.RecurrencyKind, " ");
  592. }
  593. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  594. {
  595. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  596. }
  597. else
  598. {
  599. txProfile.TransactionId = -1;
  600. }
  601. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  602. {
  603. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  604. }
  605. else
  606. {
  607. txProfile.ChargingSchedule.Duration = 86400;
  608. }
  609. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  610. {
  611. 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")));
  612. }
  613. else
  614. {
  615. 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));
  616. }
  617. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  618. {
  619. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  620. }
  621. else
  622. {
  623. txProfile.ChargingSchedule.MinChargingRate = -1;
  624. }
  625. }
  626. }
  627. }
  628. else
  629. {
  630. if(txProfile.ChargingProfileId == -1)
  631. DEBUG_INFO("TxProfile found.\n");
  632. else
  633. DEBUG_INFO("TxProfile updated.\n");
  634. // Required item
  635. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  636. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  637. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  638. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  639. 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++)
  640. {
  641. 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"));
  642. 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")));
  643. 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?
  644. 3:
  645. 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")));
  646. }
  647. // Optional item
  648. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  649. {
  650. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  651. }
  652. else
  653. {
  654. sprintf((char*)txProfile.ValidFrom, " ");
  655. }
  656. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  657. {
  658. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  659. }
  660. else
  661. {
  662. sprintf((char*)txProfile.ValidTo, " ");
  663. }
  664. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  665. {
  666. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  667. }
  668. else
  669. {
  670. sprintf((char*)txProfile.RecurrencyKind, " ");
  671. }
  672. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  673. {
  674. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  675. }
  676. else
  677. {
  678. txProfile.TransactionId = -1;
  679. }
  680. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  681. {
  682. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  683. }
  684. else
  685. {
  686. txProfile.ChargingSchedule.Duration = 86400;
  687. }
  688. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  689. {
  690. 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")));
  691. }
  692. else
  693. {
  694. 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));
  695. }
  696. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  697. {
  698. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  699. }
  700. else
  701. {
  702. txProfile.ChargingSchedule.MinChargingRate = -1;
  703. }
  704. }
  705. }
  706. }
  707. json_object_put(obj);
  708. }
  709. fclose(fp);
  710. /*
  711. if(txProfile.ChargingProfileId != -1)
  712. {
  713. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  714. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  715. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  716. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  717. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  718. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  719. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  720. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  721. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  722. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  723. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  724. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  725. {
  726. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  727. {
  728. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  729. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  730. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  731. }
  732. }
  733. }
  734. else
  735. DEBUG_INFO("TxProfile not found.\n");*/
  736. }
  737. // Search default tx profile
  738. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  739. if((access(profileFileName, F_OK))==-1)
  740. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  741. if((access(profileFileName, F_OK))!=-1)
  742. {
  743. fp = fopen(profileFileName, "r");
  744. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  745. {
  746. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  747. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  748. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  749. }
  750. defaultTxProfile.ChargingProfileId = -1;
  751. defaultTxProfile.StackLevel = -1;
  752. while(getline(&line, &len, fp) != -1)
  753. {
  754. json_object *obj = NULL;
  755. obj = json_tokener_parse(line);
  756. if(is_error(obj))
  757. {
  758. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  759. }
  760. else
  761. {
  762. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  763. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  764. )
  765. {
  766. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  767. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  768. )
  769. {
  770. struct tm tmFrom, tmTo;
  771. struct timeb tbFrom, tbTo;
  772. 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) &&
  773. (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))
  774. {
  775. tmFrom.tm_year -= 1900;
  776. tmFrom.tm_mon -= 1;
  777. tbFrom.time = mktime(&tmFrom);
  778. tmTo.tm_year -= 1900;
  779. tmTo.tm_mon -= 1;
  780. tbTo.time = mktime(&tmTo);
  781. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  782. {
  783. if(defaultTxProfile.ChargingProfileId == -1)
  784. DEBUG_INFO("TxDefaultProfile found.\n");
  785. else
  786. DEBUG_INFO("TxDefaultProfile updated.\n");
  787. // Required item
  788. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  789. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  790. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  791. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  792. 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++)
  793. {
  794. 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"));
  795. 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")));
  796. 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?
  797. 3:
  798. 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")));
  799. }
  800. // Optional item
  801. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  802. {
  803. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  804. }
  805. else
  806. {
  807. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  808. }
  809. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  810. {
  811. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  812. }
  813. else
  814. {
  815. sprintf((char*)defaultTxProfile.ValidTo, " ");
  816. }
  817. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  818. {
  819. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  820. }
  821. else
  822. {
  823. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  824. }
  825. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  826. {
  827. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  828. }
  829. else
  830. {
  831. defaultTxProfile.TransactionId = -1;
  832. }
  833. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  834. {
  835. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  836. }
  837. else
  838. {
  839. defaultTxProfile.ChargingSchedule.Duration = 86400;
  840. }
  841. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  842. {
  843. 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")));
  844. }
  845. else
  846. {
  847. 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));
  848. }
  849. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  850. {
  851. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  852. }
  853. else
  854. {
  855. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  856. }
  857. }
  858. }
  859. }
  860. else
  861. {
  862. if(defaultTxProfile.ChargingProfileId == -1)
  863. DEBUG_INFO("TxDefaultProfile found.\n");
  864. else
  865. DEBUG_INFO("TxDefaultProfile updated.\n");
  866. // Required item
  867. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  868. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  869. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  870. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  871. 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++)
  872. {
  873. 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"));
  874. 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")));
  875. 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?
  876. 3:
  877. 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")));
  878. }
  879. // Optional item
  880. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  881. {
  882. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  883. }
  884. else
  885. {
  886. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  887. }
  888. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  889. {
  890. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  891. }
  892. else
  893. {
  894. sprintf((char*)defaultTxProfile.ValidTo, " ");
  895. }
  896. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  897. {
  898. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  899. }
  900. else
  901. {
  902. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  903. }
  904. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  905. {
  906. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  907. }
  908. else
  909. {
  910. defaultTxProfile.TransactionId = -1;
  911. }
  912. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  913. {
  914. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  915. }
  916. else
  917. {
  918. defaultTxProfile.ChargingSchedule.Duration = 86400;
  919. }
  920. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  921. {
  922. 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")));
  923. }
  924. else
  925. {
  926. 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));
  927. }
  928. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  929. {
  930. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  931. }
  932. else
  933. {
  934. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  935. }
  936. }
  937. }
  938. }
  939. json_object_put(obj);
  940. }
  941. fclose(fp);
  942. /*
  943. if(defaultTxProfile.ChargingProfileId != -1)
  944. {
  945. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  946. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  947. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  948. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  949. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  950. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  951. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  952. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  953. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  954. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  955. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  956. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  957. {
  958. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  959. {
  960. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  961. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  962. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  963. }
  964. }
  965. }
  966. else
  967. DEBUG_INFO("TxDefaultProfile not found.\n");
  968. DEBUG_INFO("------------------------------------\n");*/
  969. }
  970. // Search max profile
  971. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  972. if((access(profileFileName, F_OK))!=-1)
  973. {
  974. fp = fopen(profileFileName, "r");
  975. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  976. {
  977. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  978. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  979. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  980. }
  981. maxProfile.ChargingProfileId = -1;
  982. maxProfile.StackLevel = -1;
  983. while(getline(&line, &len, fp) != -1)
  984. {
  985. json_object *obj = NULL;
  986. obj = json_tokener_parse(line);
  987. if(is_error(obj))
  988. {
  989. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  990. }
  991. else
  992. {
  993. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  994. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  995. )
  996. {
  997. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  998. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  999. )
  1000. {
  1001. struct tm tmFrom, tmTo;
  1002. struct timeb tbFrom, tbTo;
  1003. 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) &&
  1004. (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))
  1005. {
  1006. tmFrom.tm_year -= 1900;
  1007. tmFrom.tm_mon -= 1;
  1008. tbFrom.time = mktime(&tmFrom);
  1009. tmTo.tm_year -= 1900;
  1010. tmTo.tm_mon -= 1;
  1011. tbTo.time = mktime(&tmTo);
  1012. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1013. {
  1014. if(maxProfile.ChargingProfileId == -1)
  1015. DEBUG_INFO("MaxProfile found.\n");
  1016. else
  1017. DEBUG_INFO("MaxProfile updated.\n");
  1018. // Required item
  1019. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1020. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1021. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1022. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1023. 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++)
  1024. {
  1025. 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"));
  1026. 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")));
  1027. 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?
  1028. 3:
  1029. 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")));
  1030. }
  1031. // Optional item
  1032. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1033. {
  1034. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1035. }
  1036. else
  1037. {
  1038. sprintf((char*)maxProfile.ValidFrom, " ");
  1039. }
  1040. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1041. {
  1042. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1043. }
  1044. else
  1045. {
  1046. sprintf((char*)maxProfile.ValidTo, " ");
  1047. }
  1048. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1049. {
  1050. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1051. }
  1052. else
  1053. {
  1054. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1055. }
  1056. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1057. {
  1058. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1059. }
  1060. else
  1061. {
  1062. maxProfile.TransactionId = -1;
  1063. }
  1064. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1065. {
  1066. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1067. }
  1068. else
  1069. {
  1070. maxProfile.ChargingSchedule.Duration = 86400;
  1071. }
  1072. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1073. {
  1074. 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")));
  1075. }
  1076. else
  1077. {
  1078. 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));
  1079. }
  1080. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1081. {
  1082. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1083. }
  1084. else
  1085. {
  1086. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1087. }
  1088. }
  1089. }
  1090. }
  1091. else
  1092. {
  1093. if(maxProfile.ChargingProfileId == -1)
  1094. DEBUG_INFO("MaxProfile found.\n");
  1095. else
  1096. DEBUG_INFO("MaxProfile updated.\n");
  1097. // Required item
  1098. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1099. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1100. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1101. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1102. 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++)
  1103. {
  1104. 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"));
  1105. 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")));
  1106. 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?
  1107. 3:
  1108. 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")));
  1109. }
  1110. // Optional item
  1111. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1112. {
  1113. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1114. }
  1115. else
  1116. {
  1117. sprintf((char*)maxProfile.ValidFrom, " ");
  1118. }
  1119. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1120. {
  1121. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1122. }
  1123. else
  1124. {
  1125. sprintf((char*)maxProfile.ValidTo, " ");
  1126. }
  1127. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1128. {
  1129. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1130. }
  1131. else
  1132. {
  1133. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1134. }
  1135. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1136. {
  1137. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1138. }
  1139. else
  1140. {
  1141. maxProfile.TransactionId = -1;
  1142. }
  1143. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1144. {
  1145. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1146. }
  1147. else
  1148. {
  1149. maxProfile.ChargingSchedule.Duration = 86400;
  1150. }
  1151. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1152. {
  1153. 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")));
  1154. }
  1155. else
  1156. {
  1157. 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));
  1158. }
  1159. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1160. {
  1161. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1162. }
  1163. else
  1164. {
  1165. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1166. }
  1167. }
  1168. }
  1169. }
  1170. json_object_put(obj);
  1171. }
  1172. fclose(fp);
  1173. /*
  1174. if(maxProfile.ChargingProfileId !=-1)
  1175. {
  1176. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1177. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1178. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1179. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1180. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1181. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1182. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1183. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1184. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1185. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1186. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1187. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1188. {
  1189. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1190. {
  1191. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1192. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1193. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1194. }
  1195. }
  1196. }
  1197. else
  1198. DEBUG_INFO("MaxProfile not found.\n");
  1199. DEBUG_INFO("------------------------------------\n");*/
  1200. }
  1201. /*
  1202. * Align found profile start schedule & periods
  1203. */
  1204. //DEBUG_INFO("====================================\n");
  1205. /*
  1206. // For local test usage, force modify found profile start schedule info
  1207. 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);
  1208. 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);
  1209. 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);
  1210. */
  1211. if(txProfile.ChargingProfileId != -1)
  1212. {
  1213. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1214. {
  1215. if(txProfile.ChargingSchedule.Duration != -1)
  1216. {
  1217. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1218. 0:
  1219. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1220. }
  1221. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1222. {
  1223. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1224. {
  1225. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1226. 0:
  1227. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1228. if(idxPeriod > 0)
  1229. {
  1230. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1231. {
  1232. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1233. }
  1234. }
  1235. }
  1236. }
  1237. }
  1238. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1239. {
  1240. if(txProfile.ChargingSchedule.Duration != -1)
  1241. {
  1242. 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?
  1243. 0:
  1244. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1245. }
  1246. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1247. {
  1248. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1249. {
  1250. 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?
  1251. 0:
  1252. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1253. if(idxPeriod > 0)
  1254. {
  1255. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1256. {
  1257. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1258. }
  1259. }
  1260. }
  1261. }
  1262. }
  1263. else
  1264. {
  1265. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1266. {
  1267. if(txProfile.ChargingSchedule.Duration != -1)
  1268. {
  1269. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1270. 0:
  1271. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1272. }
  1273. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1274. {
  1275. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1276. {
  1277. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1278. 0:
  1279. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1280. if(idxPeriod > 0)
  1281. {
  1282. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1283. {
  1284. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1285. }
  1286. }
  1287. }
  1288. }
  1289. }
  1290. else
  1291. {
  1292. if(txProfile.ChargingSchedule.Duration != -1)
  1293. {
  1294. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1295. 0:
  1296. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1297. }
  1298. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1299. {
  1300. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1301. {
  1302. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1303. 0:
  1304. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1305. if(idxPeriod > 0)
  1306. {
  1307. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1308. {
  1309. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1310. }
  1311. }
  1312. }
  1313. }
  1314. }
  1315. }
  1316. /*
  1317. DEBUG_INFO("txProfile after align.\n");
  1318. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1319. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1320. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1321. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1322. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1323. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1324. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1325. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1326. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1327. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1328. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1329. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1330. {
  1331. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1332. {
  1333. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1334. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1335. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1336. }
  1337. }*/
  1338. }
  1339. if(defaultTxProfile.ChargingProfileId != -1)
  1340. {
  1341. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1342. {
  1343. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1344. {
  1345. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1346. 0:
  1347. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1348. }
  1349. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1350. {
  1351. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1352. {
  1353. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1354. 0:
  1355. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1356. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1357. {
  1358. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1359. }
  1360. if(idxPeriod > 0)
  1361. {
  1362. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1363. {
  1364. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1365. }
  1366. }
  1367. }
  1368. }
  1369. }
  1370. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1371. {
  1372. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1373. {
  1374. 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?
  1375. 0:
  1376. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1377. }
  1378. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1379. {
  1380. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1381. {
  1382. 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?
  1383. 0:
  1384. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1385. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1386. {
  1387. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1388. }
  1389. if(idxPeriod > 0)
  1390. {
  1391. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1392. {
  1393. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1394. }
  1395. }
  1396. }
  1397. }
  1398. }
  1399. else
  1400. {
  1401. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1402. {
  1403. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1404. {
  1405. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1406. 0:
  1407. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1408. }
  1409. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1410. {
  1411. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1412. {
  1413. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1414. 0:
  1415. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1416. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1417. {
  1418. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1419. }
  1420. if(idxPeriod > 0)
  1421. {
  1422. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1423. {
  1424. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1425. }
  1426. }
  1427. }
  1428. }
  1429. }
  1430. else
  1431. {
  1432. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1433. {
  1434. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1435. 0:
  1436. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1437. }
  1438. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1439. {
  1440. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1441. {
  1442. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1443. 0:
  1444. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1445. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1446. {
  1447. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1448. }
  1449. if(idxPeriod > 0)
  1450. {
  1451. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1452. {
  1453. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1454. }
  1455. }
  1456. }
  1457. }
  1458. }
  1459. }
  1460. /*
  1461. DEBUG_INFO("defaultTxProfile after align.\n");
  1462. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1463. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1464. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1465. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1466. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1467. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1468. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1469. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1470. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1471. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1472. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1473. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1474. {
  1475. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1476. {
  1477. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1478. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1479. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1480. }
  1481. }
  1482. DEBUG_INFO("------------------------------------\n");*/
  1483. }
  1484. if(maxProfile.ChargingProfileId != -1)
  1485. {
  1486. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1487. {
  1488. if(maxProfile.ChargingSchedule.Duration != -1)
  1489. {
  1490. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1491. 0:
  1492. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1493. }
  1494. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1495. {
  1496. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1497. {
  1498. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1499. 0:
  1500. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1501. if(idxPeriod > 0)
  1502. {
  1503. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1504. {
  1505. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1506. }
  1507. }
  1508. }
  1509. }
  1510. }
  1511. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1512. {
  1513. if(maxProfile.ChargingSchedule.Duration != -1)
  1514. {
  1515. 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?
  1516. 0:
  1517. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1518. }
  1519. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1520. {
  1521. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1522. {
  1523. 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?
  1524. 0:
  1525. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1526. if(idxPeriod > 0)
  1527. {
  1528. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1529. {
  1530. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1531. }
  1532. }
  1533. }
  1534. }
  1535. }
  1536. else
  1537. {
  1538. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1539. {
  1540. if(maxProfile.ChargingSchedule.Duration != -1)
  1541. {
  1542. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1543. 0:
  1544. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1545. }
  1546. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1547. {
  1548. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1549. {
  1550. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1551. 0:
  1552. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1553. if(idxPeriod > 0)
  1554. {
  1555. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1556. {
  1557. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1558. }
  1559. }
  1560. }
  1561. }
  1562. }
  1563. else
  1564. {
  1565. if(maxProfile.ChargingSchedule.Duration != -1)
  1566. {
  1567. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1568. 0:
  1569. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1570. }
  1571. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1572. {
  1573. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1574. {
  1575. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1576. 0:
  1577. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1578. if(idxPeriod > 0)
  1579. {
  1580. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1581. {
  1582. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1583. }
  1584. }
  1585. }
  1586. }
  1587. }
  1588. }
  1589. /*
  1590. DEBUG_INFO("MaxProfile after align.\n");
  1591. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1592. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1593. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1594. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1595. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1596. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1597. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1598. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1599. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1600. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1601. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1602. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1603. {
  1604. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1605. {
  1606. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1607. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1608. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1609. }
  1610. }
  1611. DEBUG_INFO("------------------------------------\n");*/
  1612. }
  1613. /*
  1614. * Merge to conposite schedule
  1615. */
  1616. //DEBUG_INFO("====================================\n");
  1617. // Find each profile period quantity
  1618. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1619. {
  1620. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1621. limitMax = idx+1;
  1622. }
  1623. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1624. {
  1625. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1626. limitDef = idx+1;
  1627. }
  1628. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1629. {
  1630. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1631. limitTx = idx+1;
  1632. }
  1633. // TxProfile found, composite schedule based on it
  1634. if(txProfile.ChargingProfileId != -1)
  1635. {
  1636. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  1637. {
  1638. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  1639. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  1640. (txProfile.ChargingSchedule.Duration > 0))
  1641. {
  1642. if(maxProfile.ChargingProfileId != -1)
  1643. {
  1644. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1645. {
  1646. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  1647. {
  1648. if((maxProfile.ChargingSchedule.Duration > 0))
  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>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1653. }
  1654. else
  1655. {
  1656. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1657. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1658. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  1659. }
  1660. }
  1661. if(idxMaxPeriod == (limitMax-1))
  1662. {
  1663. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1664. {
  1665. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1666. {
  1667. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1668. compositePeriodIdx++;
  1669. }
  1670. else
  1671. {
  1672. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1673. }
  1674. }
  1675. }
  1676. }
  1677. }
  1678. else
  1679. {
  1680. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1681. {
  1682. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1683. compositePeriodIdx++;
  1684. }
  1685. else
  1686. {
  1687. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1688. }
  1689. }
  1690. }
  1691. if(idxTxPeriod == (limitTx-1))
  1692. {
  1693. if(defaultTxProfile.ChargingProfileId != -1)
  1694. {
  1695. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1696. {
  1697. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  1698. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  1699. (defaultTxProfile.ChargingSchedule.Duration>0))
  1700. {
  1701. if(maxProfile.ChargingProfileId != -1)
  1702. {
  1703. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1704. {
  1705. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1706. {
  1707. if((maxProfile.ChargingSchedule.Duration > 0))
  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>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1712. }
  1713. else
  1714. {
  1715. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1716. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1717. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  1718. }
  1719. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1720. {
  1721. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1722. {
  1723. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1724. compositePeriodIdx++;
  1725. }
  1726. else
  1727. {
  1728. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1729. }
  1730. }
  1731. break;
  1732. }
  1733. }
  1734. }
  1735. else
  1736. {
  1737. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1738. {
  1739. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1740. compositePeriodIdx++;
  1741. }
  1742. else
  1743. {
  1744. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1745. }
  1746. }
  1747. }
  1748. }
  1749. }
  1750. }
  1751. }
  1752. }
  1753. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  1754. else if(defaultTxProfile.ChargingProfileId != -1)
  1755. {
  1756. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1757. {
  1758. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  1759. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  1760. (defaultTxProfile.ChargingSchedule.Duration > 0))
  1761. {
  1762. if(maxProfile.ChargingProfileId != -1)
  1763. {
  1764. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1765. {
  1766. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1767. {
  1768. if((maxProfile.ChargingSchedule.Duration > 0))
  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>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  1773. }
  1774. else
  1775. {
  1776. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1777. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1778. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  1779. }
  1780. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1781. {
  1782. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1783. {
  1784. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1785. compositePeriodIdx++;
  1786. }
  1787. else
  1788. {
  1789. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1790. }
  1791. }
  1792. break;
  1793. }
  1794. }
  1795. }
  1796. else
  1797. {
  1798. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1799. {
  1800. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1801. compositePeriodIdx++;
  1802. }
  1803. else
  1804. {
  1805. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1806. }
  1807. }
  1808. }
  1809. }
  1810. }
  1811. // Fill other period by MaxProfile
  1812. if(maxProfile.ChargingProfileId != -1)
  1813. {
  1814. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1815. {
  1816. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1817. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1818. (maxProfile.ChargingSchedule.Duration > 0))
  1819. {
  1820. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  1821. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  1822. {
  1823. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  1824. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  1825. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1826. }
  1827. if((maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  1828. {
  1829. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.Duration;
  1830. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  1831. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1832. }
  1833. if(tmpPeriod.Limit != -1)
  1834. {
  1835. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1836. {
  1837. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1838. {
  1839. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1840. compositePeriodIdx++;
  1841. }
  1842. else
  1843. {
  1844. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1845. }
  1846. }
  1847. }
  1848. }
  1849. }
  1850. }
  1851. DEBUG_INFO("Composite schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1852. DEBUG_INFO("Composite schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1853. DEBUG_INFO("Composite rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1854. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1855. {
  1856. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1857. {
  1858. compositeProfile->ChargingProfileId = 1;
  1859. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1860. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1861. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1862. }
  1863. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1864. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1865. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1866. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1867. }
  1868. if(line)
  1869. free(line);
  1870. }
  1871. //==========================================
  1872. // Init all share memory
  1873. //==========================================
  1874. int InitShareMemory()
  1875. {
  1876. int result = PASS;
  1877. int MeterSMId;
  1878. //creat ShmSysConfigAndInfo
  1879. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  1880. {
  1881. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  1882. result = FAIL;
  1883. }
  1884. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1885. {
  1886. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  1887. result = FAIL;
  1888. }
  1889. else
  1890. {}
  1891. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  1892. {
  1893. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  1894. result = FAIL;
  1895. }
  1896. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1897. {
  1898. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  1899. result = FAIL;
  1900. }
  1901. else
  1902. {}
  1903. //creat ShmPsuData
  1904. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  1905. {
  1906. DEBUG_ERROR("shmget ShmPsuData NG\n");
  1907. result = FAIL;
  1908. }
  1909. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1910. {
  1911. DEBUG_ERROR("shmat ShmPsuData NG\n");
  1912. result = FAIL;
  1913. }
  1914. else
  1915. {}
  1916. //creat ShmOCPP16Data
  1917. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  1918. {
  1919. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  1920. result = FAIL;
  1921. }
  1922. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1923. {
  1924. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  1925. result = FAIL;
  1926. }
  1927. else
  1928. {}
  1929. /****************************** For Initial Settings************************************************/
  1930. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  1931. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  1932. // allocate Configuration memory address
  1933. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  1934. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  1935. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  1936. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  1937. //offline MeterValue Interval
  1938. TempMeterValueInterval = 0;
  1939. return result;
  1940. }
  1941. int ProcessShareMemory()
  1942. {
  1943. if(InitShareMemory() == FAIL)
  1944. {
  1945. DEBUG_ERROR("InitShareMemory NG\n");
  1946. if(ShmStatusCodeData!=NULL)
  1947. {
  1948. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  1949. }
  1950. sleep(5);
  1951. return FAIL;
  1952. }
  1953. return PASS;
  1954. }
  1955. //---------------------common routine---------------------------//
  1956. int isOFFline(void)
  1957. {
  1958. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  1959. {
  1960. if(TempMeterValueInterval >= 2 )
  1961. {
  1962. TempMeterValueInterval = 0;
  1963. return TRUE;
  1964. }
  1965. else
  1966. {
  1967. TempMeterValueInterval = TempMeterValueInterval+ 1;
  1968. return FALSE;
  1969. }
  1970. }
  1971. else
  1972. {
  1973. return FALSE;
  1974. }
  1975. }
  1976. //---------------------------------------------
  1977. // new:
  1978. // enum SYSTEM_STATUS
  1979. // {
  1980. // SYS_MODE_BOOTING = 0,
  1981. // SYS_MODE_IDLE = 1,
  1982. // SYS_MODE_AUTHORIZING = 2,
  1983. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  1984. // SYS_MODE_REASSIGN = 4,
  1985. // SYS_MODE_PREPARING = 5,
  1986. // SYS_MODE_PREPARE_FOR_EV = 6,
  1987. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  1988. // SYS_MODE_CHARGING = 8,
  1989. // SYS_MODE_TERMINATING = 9,
  1990. // SYS_MODE_COMPLETE = 10,
  1991. // SYS_MODE_ALARM = 11,
  1992. // SYS_MODE_FAULT = 12,
  1993. // SYS_MODE_RESERVATION = 13,
  1994. // SYS_MODE_BOOKING = 14,
  1995. // SYS_MODE_MAINTAIN = 15,
  1996. // SYS_MODE_DEBUG = 16,
  1997. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  1998. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  1999. // SYS_MODE_UPDATE = 19
  2000. // };
  2001. //
  2002. //
  2003. //-----------------------------------------
  2004. void CheckSystemValue(void)
  2005. {
  2006. uint8_t reqSampleMeter[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  2007. uint8_t reqClockAlignMeter[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  2008. char filenmae[100]={0};
  2009. char str[100]={0};
  2010. int tempIndex = 0;
  2011. //===============================
  2012. // send Heartbeat
  2013. //===============================
  2014. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2015. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2016. {
  2017. clientTime.Heartbeat=time((time_t*)NULL);
  2018. if(server_sign == TRUE)
  2019. {
  2020. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2021. }
  2022. else
  2023. {
  2024. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2025. }
  2026. }
  2027. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  2028. {
  2029. //parameter for test
  2030. sendHeartbeatRequest(0);
  2031. //==============================================
  2032. // Reset Waiting Time
  2033. //==============================================
  2034. clientTime.Heartbeat=time((time_t*)NULL);
  2035. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  2036. }
  2037. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2038. {
  2039. //===============================
  2040. // CSU Trigger Reset Conf
  2041. //===============================
  2042. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  2043. {
  2044. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  2045. }
  2046. //===============================
  2047. // CSU Trigger Authorize Request
  2048. //===============================
  2049. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2050. {
  2051. sendAuthorizeRequest(0);
  2052. authorizeRetryTimes = authorizeRetryTimes + 1;
  2053. if(authorizeRetryTimes < 3)
  2054. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2055. }
  2056. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  2057. {
  2058. authorizeRetryTimes = 0;
  2059. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  2060. server_sign = FALSE;
  2061. }
  2062. 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))
  2063. {
  2064. sendAuthorizeRequest(0);
  2065. }
  2066. //===============================
  2067. // CSU Trigger Smart Charging Profilw
  2068. //===============================
  2069. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2070. {
  2071. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index]);
  2072. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2073. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  2074. }
  2075. //==============================================
  2076. // Charger start transaction
  2077. //==============================================
  2078. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2079. {
  2080. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  2081. sendStartTransactionRequest(gun_index);
  2082. clientTime.StartTransaction = time((time_t*)NULL);
  2083. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2084. }
  2085. //==============================================
  2086. // Charger stop transaction
  2087. //==============================================
  2088. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2089. {
  2090. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  2091. sendStopTransactionRequest(gun_index);
  2092. clientTime.StopTransaction = time((time_t*)NULL);
  2093. }
  2094. //==============================================
  2095. // Charger status report
  2096. //==============================================
  2097. //--- Check Mode Change ---//
  2098. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2099. if(gunType[gun_index] == 'J')
  2100. {
  2101. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2102. {
  2103. tempIndex = ((gun_index==2) ? 1: 0);
  2104. }
  2105. else
  2106. {
  2107. tempIndex = gun_index;
  2108. }
  2109. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2110. {
  2111. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2112. {
  2113. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  2114. {
  2115. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2116. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2117. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2118. statusModeChage[gun_index] = TRUE;
  2119. }
  2120. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2121. {
  2122. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2123. if((access(filenmae,F_OK))!=-1)
  2124. {
  2125. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2126. sprintf(str,"rm -f %s",filenmae);
  2127. system(str);
  2128. }
  2129. }
  2130. #if 1 // for TempStopTransaction
  2131. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2132. {
  2133. checkTempStopTransaction(gun_index);
  2134. }
  2135. #endif
  2136. }
  2137. }
  2138. }
  2139. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2140. {
  2141. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2142. {
  2143. tempIndex = ((gun_index==2) ? 1: 0);
  2144. }
  2145. else
  2146. {
  2147. tempIndex = gun_index;
  2148. }
  2149. for (int index = 0; index < CCS_QUANTITY; index++)
  2150. {
  2151. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2152. {
  2153. 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]*/ )
  2154. {
  2155. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2156. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2157. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2158. statusModeChage[gun_index] = TRUE;
  2159. }
  2160. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2161. {
  2162. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2163. if((access(filenmae,F_OK))!=-1)
  2164. {
  2165. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2166. sprintf(str,"rm -f %s",filenmae);
  2167. system(str);
  2168. }
  2169. }
  2170. #if 1 // for TempStopTransaction
  2171. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2172. {
  2173. checkTempStopTransaction(gun_index);
  2174. }
  2175. #endif
  2176. }
  2177. }
  2178. }
  2179. else if(gunType[gun_index] == 'G')
  2180. {
  2181. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2182. {
  2183. tempIndex = ((gun_index==2) ? 1: 0);
  2184. }
  2185. else
  2186. {
  2187. tempIndex = gun_index;
  2188. }
  2189. for (int index = 0; index < GB_QUANTITY; index++)
  2190. {
  2191. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2192. {
  2193. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2194. {
  2195. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2196. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2197. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2198. statusModeChage[gun_index] = TRUE;
  2199. }
  2200. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2201. {
  2202. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2203. if((access(filenmae,F_OK))!=-1)
  2204. {
  2205. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2206. sprintf(str,"rm -f %s",filenmae);
  2207. system(str);
  2208. }
  2209. }
  2210. #if 1 // for TempStopTransaction
  2211. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2212. {
  2213. checkTempStopTransaction(gun_index);
  2214. }
  2215. #endif
  2216. }
  2217. }
  2218. }
  2219. else
  2220. {
  2221. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2222. {
  2223. tempIndex = 2;
  2224. }
  2225. else
  2226. {
  2227. tempIndex = gun_index;
  2228. }
  2229. for (int index = 0; index < AC_QUANTITY; index++)
  2230. {
  2231. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2232. {
  2233. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2234. {
  2235. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2236. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2237. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2238. statusModeChage[gun_index] = TRUE;
  2239. }
  2240. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2241. {
  2242. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2243. if((access(filenmae,F_OK))!=-1)
  2244. {
  2245. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2246. sprintf(str,"rm -f %s",filenmae);
  2247. system(str);
  2248. }
  2249. }
  2250. #if 1 // for TempStopTransaction
  2251. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2252. {
  2253. checkTempStopTransaction(gun_index);
  2254. }
  2255. #endif
  2256. }
  2257. }// END
  2258. }
  2259. if(isWebsocketSendable &&
  2260. (((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)))) )
  2261. {
  2262. if(SystemInitial > 0)
  2263. SystemInitial -= 1;
  2264. sendStatusNotificationRequest(gun_index);
  2265. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2266. statusModeChage[gun_index] = FALSE;
  2267. }
  2268. //==============================================
  2269. // Meter report
  2270. //==============================================
  2271. if(cpinitateMsg.bits[gun_index].TriggerMeterValue)
  2272. {
  2273. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  2274. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  2275. }
  2276. if(/*(server_sign == TRUE) &&(isOFFline() == TRUE) ||*/
  2277. (((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)))
  2278. {
  2279. //check Transaction active
  2280. if(gunType[gun_index] == 'J')
  2281. {
  2282. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2283. {
  2284. tempIndex = ((gun_index==2) ? 1: 0);
  2285. }
  2286. else
  2287. {
  2288. tempIndex = gun_index;
  2289. }
  2290. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2291. {
  2292. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2293. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2294. {
  2295. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2296. {
  2297. reqSampleMeter[gun_index] = 1;
  2298. }
  2299. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2300. {
  2301. reqClockAlignMeter[gun_index] = 1;
  2302. }
  2303. }
  2304. }// End for CHAdeMO
  2305. }
  2306. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2307. {
  2308. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2309. {
  2310. tempIndex = ((gun_index==2) ? 1: 0);
  2311. }
  2312. else
  2313. {
  2314. tempIndex = gun_index;
  2315. }
  2316. for (int index = 0; index < CCS_QUANTITY; index++)
  2317. {
  2318. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2319. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2320. {
  2321. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2322. {
  2323. reqSampleMeter[gun_index] = 1;
  2324. }
  2325. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2326. {
  2327. reqClockAlignMeter[gun_index] = 1;
  2328. }
  2329. }
  2330. } // End for CCS
  2331. }
  2332. else if(gunType[gun_index] == 'G')
  2333. {
  2334. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2335. {
  2336. tempIndex = ((gun_index==2) ? 1: 0);
  2337. }
  2338. else
  2339. {
  2340. tempIndex = gun_index;
  2341. }
  2342. for (int index = 0; index < GB_QUANTITY; index++)
  2343. {
  2344. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2345. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2346. {
  2347. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2348. {
  2349. reqSampleMeter[gun_index] = 1;
  2350. }
  2351. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2352. {
  2353. reqClockAlignMeter[gun_index] = 1;
  2354. }
  2355. }
  2356. }// End for GB
  2357. }
  2358. else
  2359. {
  2360. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2361. {
  2362. tempIndex = 2;
  2363. }
  2364. else
  2365. {
  2366. tempIndex = gun_index;
  2367. }
  2368. for (int index = 0; index < AC_QUANTITY; index++)
  2369. {
  2370. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2371. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2372. {
  2373. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2374. {
  2375. reqSampleMeter[gun_index] = 1;
  2376. }
  2377. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2378. {
  2379. reqClockAlignMeter[gun_index] = 1;
  2380. }
  2381. }
  2382. }//End for AC
  2383. }
  2384. if(reqSampleMeter[gun_index] == 1)
  2385. {
  2386. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  2387. storeTempStopTransaction(gun_index);
  2388. }
  2389. else if(reqClockAlignMeter[gun_index] == 1)
  2390. {
  2391. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2392. }
  2393. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2394. sleep(1);
  2395. }
  2396. //==============================================
  2397. // Check Connector reserved
  2398. //==============================================
  2399. //===============================
  2400. // Check if Reserve is expired
  2401. //===============================
  2402. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  2403. {
  2404. double diff_t;
  2405. struct tm tp;
  2406. // current time
  2407. time_t t = time(NULL);
  2408. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  2409. tp.tm_isdst = -1;
  2410. time_t utc = mktime(&tp);
  2411. diff_t = difftime(utc, t);
  2412. if(diff_t <= 0)
  2413. {
  2414. DEBUG_INFO("reserve expired.\n");
  2415. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  2416. }
  2417. }//END OF Check if Reserve is expired
  2418. //==========================================
  2419. // csu trigger FirmwareStatusNotificationReq
  2420. //==========================================
  2421. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  2422. {
  2423. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  2424. }
  2425. //==========================================
  2426. // csu trigger CancelReservationConf
  2427. //==========================================
  2428. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  2429. {
  2430. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  2431. }
  2432. //==========================================
  2433. // csu trigger ChangeAvailabilityConf
  2434. //==========================================
  2435. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  2436. {
  2437. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  2438. }
  2439. //==========================================
  2440. // csu trigger UnlockConnectorConf
  2441. //==========================================
  2442. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  2443. {
  2444. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  2445. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  2446. }
  2447. //==========================================
  2448. // csu trigger ReserveNowConf
  2449. //==========================================
  2450. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  2451. {
  2452. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  2453. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  2454. }
  2455. //==========================================
  2456. // csu trigger DataTransferReq
  2457. //==========================================
  2458. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2459. {
  2460. sendDataTransferRequest(gun_index);
  2461. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2462. }
  2463. }
  2464. }
  2465. //==========================================
  2466. // send request routine
  2467. //==========================================
  2468. int sendAuthorizeRequest(int gun_index)
  2469. {
  2470. mtrace();
  2471. int result = FAIL;
  2472. char message[100]={0};
  2473. char guid[37];
  2474. char tempdata[65]={0};
  2475. DEBUG_INFO("sendAuthorizeRequest...\n");
  2476. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  2477. //Local Authorize
  2478. if ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  2479. {
  2480. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  2481. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2482. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  2483. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  2484. result = PASS;
  2485. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2486. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2487. authorizeRetryTimes = 0;
  2488. return result;
  2489. }
  2490. 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))||
  2491. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  2492. {
  2493. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2494. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  2495. {
  2496. if(strcmp(idTagQuery.idTagstr,"") == 0)
  2497. {
  2498. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  2499. }
  2500. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  2501. {
  2502. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  2503. }
  2504. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  2505. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2506. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2507. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  2508. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  2509. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2510. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2511. authorizeRetryTimes = 0;
  2512. return result;
  2513. }
  2514. else
  2515. {
  2516. DEBUG_INFO("offline Local Authorization Pass !!!!\n");
  2517. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  2518. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2519. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  2520. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  2521. result = PASS;
  2522. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2523. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2524. authorizeRetryTimes = 0;
  2525. return result;
  2526. }
  2527. }
  2528. //initailize struct Authorize
  2529. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  2530. //get data from shared memory
  2531. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2532. random_uuid(guid);
  2533. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  2534. LWS_Send(message);
  2535. sprintf(tempdata, "Authorize,%d", gun_index);
  2536. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2537. {
  2538. result = PASS;
  2539. DEBUG_INFO("Authorize mapItem pass\n");
  2540. }
  2541. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2542. return result;
  2543. }
  2544. int sendBootNotificationRequest(void)
  2545. {
  2546. mtrace();
  2547. int result = FAIL;
  2548. char message[500]={0}, payload[700]={0};
  2549. char guid[37]={0};
  2550. char tempdata[65]={0};
  2551. /*
  2552. int IsGunCharging = FALSE;
  2553. //check Transaction active
  2554. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2555. {
  2556. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2557. {
  2558. IsGunCharging = TRUE;
  2559. }
  2560. }
  2561. for (int index = 0; index < CCS_QUANTITY; index++)
  2562. {
  2563. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2564. {
  2565. IsGunCharging = TRUE;
  2566. }
  2567. }
  2568. for (int index = 0; index < GB_QUANTITY; index++)
  2569. {
  2570. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2571. {
  2572. IsGunCharging = TRUE;
  2573. }
  2574. }
  2575. for (int index = 0; index < AC_QUANTITY; index++)
  2576. {
  2577. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2578. {
  2579. IsGunCharging = TRUE;
  2580. }
  2581. }
  2582. if(IsGunCharging == TRUE)
  2583. {
  2584. server_sign = TRUE;
  2585. return result;
  2586. }
  2587. */
  2588. // Fill BootNotification fields
  2589. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  2590. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  2591. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  2592. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2593. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  2594. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  2595. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  2596. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  2597. ShmOCPP16Data->ChargeBoxId
  2598. ,ShmSysConfigAndInfo->SysConfig.ModelName
  2599. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  2600. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  2601. ,ShmOCPP16Data->BootNotification.CpFwVersion
  2602. ,ShmOCPP16Data->BootNotification.CpIccid
  2603. ,ShmOCPP16Data->BootNotification.CpImsi);
  2604. random_uuid(guid);
  2605. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  2606. LWS_Send(message);
  2607. sprintf(tempdata, "BootNotification,0");
  2608. 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*/)
  2609. {
  2610. result = PASS;
  2611. }
  2612. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  2613. strcpy(queuedata,message);
  2614. return result;
  2615. }
  2616. int sendDataTransferRequest(int gun_index)
  2617. {
  2618. mtrace();
  2619. char message[1000]={0};
  2620. char guid[37]={0};
  2621. char tempdata[65]={0};
  2622. int result = FAIL;
  2623. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  2624. random_uuid(guid);
  2625. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  2626. MESSAGE_TYPE_CALL,
  2627. guid,
  2628. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  2629. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  2630. ShmOCPP16Data->DataTransfer[gun_index].Data);
  2631. LWS_Send(message);
  2632. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  2633. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2634. {
  2635. result = PASS;
  2636. DEBUG_INFO("DataTransfer mapItem pass\n");
  2637. }
  2638. return result;
  2639. }
  2640. int sendDiagnosticsStatusNotificationRequest(char *status)
  2641. {
  2642. mtrace();
  2643. int result = FAIL;
  2644. char message[110]={0};
  2645. char guid[37]={0};
  2646. char tempdata[65]={0};
  2647. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  2648. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  2649. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  2650. random_uuid(guid);
  2651. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  2652. LWS_Send(message);
  2653. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  2654. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2655. {
  2656. result = PASS;
  2657. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  2658. }
  2659. //#ifdef SystemLogMessage
  2660. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  2661. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2662. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  2663. //#endif
  2664. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  2665. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  2666. //record status
  2667. if(strcmp(status,"Idle")==0)
  2668. {
  2669. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  2670. }
  2671. else if(strcmp(status,"Uploaded")==0)
  2672. {
  2673. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  2674. }
  2675. else if(strcmp(status,"UploadFailed")==0)
  2676. {
  2677. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  2678. }
  2679. else if(strcmp(status,"Uploading")==0)
  2680. {
  2681. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  2682. }
  2683. return result;
  2684. }
  2685. int sendFirmwareStatusNotificationRequest(char *status)
  2686. {
  2687. mtrace();
  2688. int result = FAIL;
  2689. char message[110]={0};
  2690. char guid[37]={0};
  2691. char tempdata[65]={0};
  2692. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  2693. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  2694. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  2695. random_uuid(guid);
  2696. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  2697. LWS_Send(message);
  2698. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  2699. 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*/)
  2700. {
  2701. result = PASS;
  2702. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  2703. }
  2704. //#ifdef SystemLogMessage
  2705. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  2706. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2707. //#endif
  2708. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  2709. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  2710. //record status
  2711. if(strcmp(status,"Downloaded")==0)
  2712. {
  2713. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  2714. }
  2715. else if(strcmp(status,"DownloadFailed")==0)
  2716. {
  2717. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  2718. }
  2719. else if(strcmp(status,"Downloading")==0)
  2720. {
  2721. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  2722. }
  2723. else if(strcmp(status,"Idle")==0)
  2724. {
  2725. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  2726. }
  2727. else if(strcmp(status,"InstallationFailed")==0)
  2728. {
  2729. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  2730. }
  2731. else if(strcmp(status,"Installing")==0)
  2732. {
  2733. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  2734. }
  2735. else if(strcmp(status,"Installed")==0)
  2736. {
  2737. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  2738. }
  2739. return result;
  2740. }
  2741. int sendHeartbeatRequest(int gun_index)
  2742. {
  2743. mtrace();
  2744. int result = FAIL;
  2745. char message[80]={0};
  2746. char guid[37]={0};
  2747. char tempdata[65]={0};
  2748. random_uuid(guid);
  2749. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  2750. , MESSAGE_TYPE_CALL
  2751. , guid );
  2752. LWS_Send(message);
  2753. sprintf(tempdata, "Heartbeat,%d", 0);
  2754. 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*/)
  2755. {
  2756. result = PASS;
  2757. }
  2758. return result;
  2759. }
  2760. int sendStartTransactionRequest(int gun_index)
  2761. {
  2762. mtrace();
  2763. int result = FAIL;
  2764. char message[250]={0};
  2765. char guid[37]={0};
  2766. struct timeval tmnow;
  2767. struct tm *tm;
  2768. char buf[28];//, usec_buf[6];
  2769. char tempdata[65]={0};
  2770. int tempIndex = 0;
  2771. DEBUG_INFO("sendStartTransactionRequest...\n");
  2772. gettimeofday(&tmnow, NULL);
  2773. time_t t;
  2774. t = time(NULL);
  2775. /*UTC time and date*/
  2776. tm = gmtime(&t);
  2777. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2778. #if 0 // remove temporally
  2779. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2780. strcat(buf,".");
  2781. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2782. strcat(buf,usec_buf);
  2783. #endif
  2784. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  2785. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  2786. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2787. // clear StartTransaction Response
  2788. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  2789. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  2790. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  2791. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  2792. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2793. if(gunType[gun_index] == 'J')
  2794. {
  2795. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2796. {
  2797. tempIndex = ((gun_index==2) ? 1: 0);
  2798. }
  2799. else
  2800. {
  2801. tempIndex = gun_index;
  2802. }
  2803. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2804. {
  2805. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2806. {
  2807. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  2808. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  2809. }
  2810. }
  2811. }
  2812. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2813. {
  2814. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2815. {
  2816. tempIndex = ((gun_index==2) ? 1: 0);
  2817. }
  2818. else
  2819. {
  2820. tempIndex = gun_index;
  2821. }
  2822. for (int index = 0; index < CCS_QUANTITY; index++)
  2823. {
  2824. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2825. {
  2826. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  2827. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  2828. }
  2829. }
  2830. }
  2831. else if(gunType[gun_index] == 'G')
  2832. {
  2833. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2834. {
  2835. tempIndex = ((gun_index==2) ? 1: 0);
  2836. }
  2837. else
  2838. {
  2839. tempIndex = gun_index;
  2840. }
  2841. for (int index = 0; index < GB_QUANTITY; index++)
  2842. {
  2843. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2844. {
  2845. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  2846. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  2847. }
  2848. }
  2849. }
  2850. else
  2851. {
  2852. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2853. {
  2854. tempIndex = 2;
  2855. }
  2856. else
  2857. {
  2858. tempIndex = gun_index;
  2859. }
  2860. for (int index = 0; index < AC_QUANTITY; index++)
  2861. {
  2862. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2863. {
  2864. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  2865. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  2866. }
  2867. }
  2868. }
  2869. random_uuid(guid);
  2870. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  2871. {
  2872. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  2873. , gun_index +1
  2874. , MESSAGE_TYPE_CALL
  2875. , guid
  2876. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  2877. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  2878. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  2879. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  2880. }
  2881. else
  2882. {
  2883. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  2884. , gun_index +1
  2885. , MESSAGE_TYPE_CALL
  2886. , guid
  2887. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  2888. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  2889. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  2890. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  2891. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  2892. }
  2893. #if 1
  2894. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  2895. 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*/)
  2896. {
  2897. result = PASS;
  2898. }
  2899. #endif
  2900. strcpy(queuedata, message);
  2901. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2902. /*
  2903. if(GetTransactionQueueNum() == 1)
  2904. {
  2905. LWS_Send(message + 2);
  2906. }*/
  2907. return result;
  2908. }
  2909. int sendStatusNotificationRequest(int gun_index)
  2910. {
  2911. mtrace();
  2912. int result = FAIL;
  2913. char message[600]={0};
  2914. char guid[37];
  2915. int currentStatus = 0;
  2916. struct timeval tmnow;
  2917. struct tm *tm;
  2918. char buf[28];//, usec_buf[6];
  2919. char tempdata[65]={0};
  2920. int tempIndex = 0;
  2921. gettimeofday(&tmnow, NULL);
  2922. time_t t;
  2923. t = time(NULL);
  2924. /*UTC time and date*/
  2925. tm = gmtime(&t);
  2926. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2927. #if 0 // remove temporally
  2928. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2929. strcat(buf,".");
  2930. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2931. strcat(buf,usec_buf);
  2932. #endif
  2933. printf("%s",buf);
  2934. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  2935. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  2936. // it's option
  2937. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  2938. /*
  2939. enum _SYSTEM_STATUS
  2940. {
  2941. S_BOOTING = 0,
  2942. S_IDLE, = 1
  2943. S_AUTHORIZING, =2
  2944. S_REASSIGN_CHECK, =3
  2945. S_REASSIGN, =4
  2946. S_PRECHARGE, =5
  2947. S_PREPARING_FOR_EV, =6
  2948. S_PREPARING_FOR_EVSE, =7
  2949. S_CHARGING, =8
  2950. S_TERMINATING, =9
  2951. S_COMPLETE, =10
  2952. S_ALARM, =11
  2953. S_FAULT =12
  2954. }
  2955. */
  2956. //check Transaction active
  2957. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2958. if(gunType[gun_index] == 'J')
  2959. {
  2960. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2961. {
  2962. tempIndex = ((gun_index==2) ? 1: 0);
  2963. }
  2964. else
  2965. {
  2966. tempIndex = gun_index;
  2967. }
  2968. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2969. {
  2970. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  2971. {
  2972. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  2973. {
  2974. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  2975. {
  2976. currentStatus = 1; //OCPP Status: Preparing
  2977. }
  2978. else
  2979. {
  2980. currentStatus = 0; //OCPP Status: Available
  2981. }
  2982. }
  2983. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  2984. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  2985. ) //S_PRECHARGE
  2986. {
  2987. currentStatus = 1; //OCPP Status: Preparing
  2988. }
  2989. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2990. {
  2991. currentStatus = 2; //OCPP Status: Charging
  2992. }
  2993. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  2994. {
  2995. currentStatus = 5; //OCPP Status: Finishing
  2996. }
  2997. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  2998. {
  2999. currentStatus = 4; //OCPP Status: SuspendedEV
  3000. }
  3001. 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
  3002. {
  3003. currentStatus = 7; //OCPP Status: Unavailable
  3004. }
  3005. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3006. {
  3007. currentStatus = 8; //OCPP Status: Faulted
  3008. }
  3009. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3010. {
  3011. currentStatus = 6; //OCPP Status: Reserved
  3012. }
  3013. } //end of the same index
  3014. }//end of for CHAdeMO_QUANTITY
  3015. }
  3016. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3017. {
  3018. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3019. {
  3020. tempIndex = ((gun_index==2) ? 1: 0);
  3021. }
  3022. else
  3023. {
  3024. tempIndex = gun_index;
  3025. }
  3026. for (int index = 0; index < CCS_QUANTITY; index++)
  3027. {
  3028. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3029. {
  3030. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3031. {
  3032. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3033. {
  3034. currentStatus = 1; //OCPP Status: Preparing
  3035. }
  3036. else
  3037. {
  3038. currentStatus = 0; //OCPP Status: Available
  3039. }
  3040. }
  3041. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3042. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3043. ) //S_PRECHARGE
  3044. {
  3045. currentStatus = 1; //OCPP Status: Preparing
  3046. }
  3047. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3048. {
  3049. currentStatus = 2; //OCPP Status: Charging
  3050. }
  3051. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3052. {
  3053. currentStatus = 5; //OCPP Status: Finishing
  3054. }
  3055. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3056. {
  3057. currentStatus = 4; //OCPP Status: SuspendedEV
  3058. }
  3059. 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
  3060. {
  3061. currentStatus = 7; //OCPP Status : Unavailable
  3062. }
  3063. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3064. {
  3065. currentStatus = 8; //OCPP Status: Faulted
  3066. }
  3067. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3068. {
  3069. currentStatus = 6; //OCPP Status: Reserved
  3070. }
  3071. } //end of the same index
  3072. } // end of for CCS_QUANTITY
  3073. }
  3074. else if(gunType[gun_index] == 'G')
  3075. {
  3076. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3077. {
  3078. tempIndex = ((gun_index==2) ? 1: 0);
  3079. }
  3080. else
  3081. {
  3082. tempIndex = gun_index;
  3083. }
  3084. for (int index = 0; index < GB_QUANTITY; index++)
  3085. {
  3086. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3087. {
  3088. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3089. {
  3090. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3091. {
  3092. currentStatus = 1; //OCPP Status: Preparing
  3093. }
  3094. else
  3095. {
  3096. currentStatus = 0; //OCPP Status: Available
  3097. }
  3098. }
  3099. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3100. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3101. ) //S_PRECHARGE
  3102. {
  3103. currentStatus = 1; //OCPP Status: Preparing
  3104. }
  3105. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3106. {
  3107. currentStatus = 2; //OCPP Status: Charging
  3108. }
  3109. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3110. {
  3111. currentStatus = 5; //OCPP Status: Finishing
  3112. }
  3113. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3114. {
  3115. currentStatus = 4; //OCPP Status: SuspendedEV
  3116. }
  3117. 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
  3118. {
  3119. currentStatus = 7; //OCPP Status: Unavailable
  3120. }
  3121. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3122. {
  3123. currentStatus = 8; //OCPP Status: Faulted
  3124. }
  3125. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3126. {
  3127. currentStatus = 6; //OCPP Status: Reserved
  3128. }
  3129. } //end of the same index
  3130. } // end of for GB_QUANTITY
  3131. }
  3132. else
  3133. {
  3134. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3135. {
  3136. tempIndex = 2;
  3137. }
  3138. else
  3139. {
  3140. tempIndex = gun_index;
  3141. }
  3142. for (int index = 0; index < AC_QUANTITY; index++)
  3143. {
  3144. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3145. {
  3146. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3147. {
  3148. 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))
  3149. {
  3150. currentStatus = 1; //OCPP Status: Preparing
  3151. }
  3152. else
  3153. {
  3154. currentStatus = 0; //OCPP Status: Available
  3155. }
  3156. }
  3157. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3158. {
  3159. currentStatus = 1; //OCPP Status: Preparing
  3160. }
  3161. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3162. {
  3163. currentStatus = 2; //OCPP Status: Charging
  3164. }
  3165. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3166. {
  3167. currentStatus = 5; //OCPP Status: Finishing
  3168. }
  3169. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3170. {
  3171. currentStatus = 4; //OCPP Status: SuspendedEV
  3172. }
  3173. 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
  3174. {
  3175. currentStatus = 7; //OCPP Status: Unavailable
  3176. }
  3177. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3178. {
  3179. currentStatus = 8; //OCPP Status: Faulted
  3180. }
  3181. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3182. {
  3183. currentStatus = 6; //OCPP Status: Reserved
  3184. }
  3185. }//end of the same index
  3186. }//end of for AC_QUANTITY
  3187. }
  3188. //it's option
  3189. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3190. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  3191. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3192. random_uuid(guid);
  3193. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3194. , MESSAGE_TYPE_CALL
  3195. , guid
  3196. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3197. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3198. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3199. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3200. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3201. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3202. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3203. if((server_sign == TRUE))
  3204. {
  3205. LWS_Send(message);
  3206. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3207. 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*/)
  3208. {
  3209. //DEBUG_ERROR("statusNotification mapitem pass");
  3210. result = PASS;
  3211. }
  3212. }
  3213. else
  3214. {
  3215. result = PASS;
  3216. }
  3217. return result;
  3218. }
  3219. int sendStopTransactionRequest(int gun_index)
  3220. {
  3221. mtrace();
  3222. int result = FAIL;
  3223. //char message[1500]={0};
  3224. char guid[37]={0};
  3225. char tempdata[65]={0};
  3226. int tempIndex = 0;
  3227. //int idx_sample=0;
  3228. DEBUG_ERROR("sendStopTransactionRequest \n");
  3229. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3230. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3231. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3232. if(gunType[gun_index] == 'J')
  3233. {
  3234. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3235. {
  3236. tempIndex = ((gun_index==2) ? 1: 0);
  3237. }
  3238. else
  3239. {
  3240. tempIndex = gun_index;
  3241. }
  3242. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3243. {
  3244. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3245. {
  3246. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3247. }
  3248. }// END OF CHAdeMO_QUANTITY
  3249. }
  3250. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3251. {
  3252. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3253. {
  3254. tempIndex = ((gun_index==2) ? 1: 0);
  3255. }
  3256. else
  3257. {
  3258. tempIndex = gun_index;
  3259. }
  3260. for (int index = 0; index < CCS_QUANTITY; index++)
  3261. {
  3262. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3263. {
  3264. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3265. }
  3266. }// END OF CCS_QUANTITY
  3267. }
  3268. else if(gunType[gun_index] == 'G')
  3269. {
  3270. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3271. {
  3272. tempIndex = ((gun_index==2) ? 1: 0);
  3273. }
  3274. else
  3275. {
  3276. tempIndex = gun_index;
  3277. }
  3278. for (int index = 0; index < GB_QUANTITY; index++)
  3279. {
  3280. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3281. {
  3282. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3283. }
  3284. }// END OF GB_QUANTITY
  3285. }
  3286. else
  3287. {
  3288. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3289. {
  3290. tempIndex = 2;
  3291. }
  3292. else
  3293. {
  3294. tempIndex = gun_index;
  3295. }
  3296. for (int index = 0; index < AC_QUANTITY; index++)
  3297. {
  3298. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3299. {
  3300. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3301. }
  3302. }// END OF AC_QUANTITY
  3303. }
  3304. //====================================== Stop Transaction Time =====================================================
  3305. struct timeval tmnow;
  3306. struct tm *tm;
  3307. char buf[28];//, usec_buf[6];
  3308. gettimeofday(&tmnow, NULL);
  3309. time_t t;
  3310. t = time(NULL);
  3311. /*UTC time and date*/
  3312. tm = gmtime(&t);
  3313. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3314. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  3315. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  3316. random_uuid(guid);
  3317. /***********************************transactionData******************************************************/
  3318. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  3319. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  3320. //=================================
  3321. // Transaction_Begin
  3322. //=================================
  3323. //============================================ Energy.Active.Import.Interval ================================
  3324. //idx_sample=0;
  3325. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  3326. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  3327. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  3328. 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*/]);
  3329. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3330. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3331. {
  3332. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  3333. }
  3334. else
  3335. {
  3336. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  3337. }
  3338. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  3339. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3340. //=================================
  3341. // Transaction_End
  3342. //=================================
  3343. // ================================= Current.Import L1 ===============================================
  3344. //idx_sample=1;
  3345. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  3346. if(gunType[gun_index] == 'J')
  3347. {
  3348. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3349. {
  3350. tempIndex = ((gun_index==2) ? 1: 0);
  3351. }
  3352. else
  3353. {
  3354. tempIndex = gun_index;
  3355. }
  3356. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3357. {
  3358. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3359. {
  3360. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3361. }
  3362. }// End of for CHAdeMO_QUANTITY
  3363. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3364. }
  3365. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3366. {
  3367. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3368. {
  3369. tempIndex = ((gun_index==2) ? 1: 0);
  3370. }
  3371. else
  3372. {
  3373. tempIndex = gun_index;
  3374. }
  3375. for (int index = 0; index < CCS_QUANTITY; index++)
  3376. {
  3377. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3378. {
  3379. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3380. }
  3381. }// End of for CCS_QUANTITY
  3382. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3383. }
  3384. else if(gunType[gun_index] == 'G')
  3385. {
  3386. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3387. {
  3388. tempIndex = ((gun_index==2) ? 1: 0);
  3389. }
  3390. else
  3391. {
  3392. tempIndex = gun_index;
  3393. }
  3394. for (int index = 0; index < GB_QUANTITY; index++)
  3395. {
  3396. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3397. {
  3398. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3399. }
  3400. }// End of for GB_QUANTITY
  3401. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3402. }
  3403. else
  3404. {
  3405. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3406. {
  3407. tempIndex = 2;
  3408. }
  3409. else
  3410. {
  3411. tempIndex = gun_index;
  3412. }
  3413. for (int index = 0; index < AC_QUANTITY; index++)
  3414. {
  3415. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3416. {
  3417. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  3418. }
  3419. }// End of for AC_QUANTITY
  3420. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  3421. }
  3422. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3423. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  3424. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  3425. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  3426. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3427. // ================================= Energy.Active.Import.Interval ==============================================
  3428. //idx_sample=2;
  3429. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3430. if(gunType[gun_index] == 'J')
  3431. {
  3432. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3433. {
  3434. tempIndex = ((gun_index==2) ? 1: 0);
  3435. }
  3436. else
  3437. {
  3438. tempIndex = gun_index;
  3439. }
  3440. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3441. {
  3442. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3443. {
  3444. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3445. }
  3446. }// END OF CHAdeMO_QUANTITY
  3447. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3448. }
  3449. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3450. {
  3451. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3452. {
  3453. tempIndex = ((gun_index==2) ? 1: 0);
  3454. }
  3455. else
  3456. {
  3457. tempIndex = gun_index;
  3458. }
  3459. for (int index = 0; index < CCS_QUANTITY; index++)
  3460. {
  3461. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3462. {
  3463. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3464. }
  3465. }// END OF CCS_QUANTITY
  3466. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3467. }
  3468. else if(gunType[gun_index] == 'G')
  3469. {
  3470. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3471. {
  3472. tempIndex = ((gun_index==2) ? 1: 0);
  3473. }
  3474. else
  3475. {
  3476. tempIndex = gun_index;
  3477. }
  3478. for (int index = 0; index < GB_QUANTITY; index++)
  3479. {
  3480. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3481. {
  3482. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3483. }
  3484. }// END OF GB_QUANTITY
  3485. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3486. }
  3487. else
  3488. {
  3489. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3490. {
  3491. tempIndex = 2;
  3492. }
  3493. else
  3494. {
  3495. tempIndex = gun_index;
  3496. }
  3497. for (int index = 0; index < AC_QUANTITY; index++)
  3498. {
  3499. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3500. {
  3501. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3502. }
  3503. }// END OF AC_QUANTITY
  3504. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  3505. }
  3506. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3507. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  3508. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  3509. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  3510. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3511. //=================================== Power.Active.Import ==================================================
  3512. //idx_sample=3;
  3513. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3514. if(gunType[gun_index] == 'J')
  3515. {
  3516. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3517. {
  3518. tempIndex = ((gun_index==2) ? 1: 0);
  3519. }
  3520. else
  3521. {
  3522. tempIndex = gun_index;
  3523. }
  3524. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3525. {
  3526. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3527. {
  3528. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3529. }
  3530. } // End for CHAdeMO_QUANTITY
  3531. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3532. }
  3533. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3534. {
  3535. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3536. {
  3537. tempIndex = ((gun_index==2) ? 1: 0);
  3538. }
  3539. else
  3540. {
  3541. tempIndex = gun_index;
  3542. }
  3543. for (int index = 0; index < CCS_QUANTITY; index++)
  3544. {
  3545. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3546. {
  3547. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3548. }
  3549. } // END for CCS_QUANTITY
  3550. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3551. }
  3552. else if(gunType[gun_index] == 'G')
  3553. {
  3554. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3555. {
  3556. tempIndex = ((gun_index==2) ? 1: 0);
  3557. }
  3558. else
  3559. {
  3560. tempIndex = gun_index;
  3561. }
  3562. for (int index = 0; index < GB_QUANTITY; index++)
  3563. {
  3564. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3565. {
  3566. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3567. }
  3568. }// END for GB_QUANTITY
  3569. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3570. }
  3571. else
  3572. {
  3573. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3574. {
  3575. tempIndex = 2;
  3576. }
  3577. else
  3578. {
  3579. tempIndex = gun_index;
  3580. }
  3581. for (int index = 0; index < AC_QUANTITY; index++)
  3582. {
  3583. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3584. {
  3585. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3586. }
  3587. } // END for AC_QUANTITY
  3588. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  3589. }
  3590. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3591. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  3592. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  3593. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  3594. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  3595. //============================ Voltage L1 ====================================
  3596. //idx_sample=4;
  3597. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3598. if(gunType[gun_index] == 'J')
  3599. {
  3600. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3601. {
  3602. tempIndex = ((gun_index==2) ? 1: 0);
  3603. }
  3604. else
  3605. {
  3606. tempIndex = gun_index;
  3607. }
  3608. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3609. {
  3610. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3611. {
  3612. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3613. }
  3614. } // END OF FOR CHAdeMO_QUANTITY
  3615. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3616. }
  3617. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3618. {
  3619. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3620. {
  3621. tempIndex = ((gun_index==2) ? 1: 0);
  3622. }
  3623. else
  3624. {
  3625. tempIndex = gun_index;
  3626. }
  3627. for (int index = 0; index < CCS_QUANTITY; index++)
  3628. {
  3629. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3630. {
  3631. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3632. }
  3633. } // END OF FOR CCS_QUANTITY
  3634. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3635. }
  3636. else if(gunType[gun_index] == 'G')
  3637. {
  3638. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3639. {
  3640. tempIndex = ((gun_index==2) ? 1: 0);
  3641. }
  3642. else
  3643. {
  3644. tempIndex = gun_index;
  3645. }
  3646. for (int index = 0; index < GB_QUANTITY; index++)
  3647. {
  3648. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3649. {
  3650. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3651. }
  3652. } // END OF FOR GB_QUANTITY
  3653. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3654. }
  3655. else
  3656. {
  3657. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3658. {
  3659. tempIndex = 2;
  3660. }
  3661. else
  3662. {
  3663. tempIndex = gun_index;
  3664. }
  3665. for (int index = 0; index < AC_QUANTITY; index++)
  3666. {
  3667. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3668. {
  3669. 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
  3670. }
  3671. } // END OF FOR AC_QUANTITY
  3672. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  3673. }
  3674. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3675. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  3676. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  3677. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  3678. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3679. //====================== SoC ================================
  3680. //idx_sample=5;
  3681. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3682. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3683. {
  3684. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3685. {
  3686. tempIndex = ((gun_index==2) ? 1: 0);
  3687. }
  3688. else
  3689. {
  3690. tempIndex = gun_index;
  3691. }
  3692. if(gunType[gun_index] == 'J')
  3693. {
  3694. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3695. {
  3696. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3697. {
  3698. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  3699. }
  3700. }
  3701. }
  3702. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3703. {
  3704. for (int index = 0; index < CCS_QUANTITY; index++)
  3705. {
  3706. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3707. {
  3708. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  3709. }
  3710. }
  3711. }
  3712. else if(gunType[gun_index] == 'G')
  3713. {
  3714. for (int index = 0; index < GB_QUANTITY; index++)
  3715. {
  3716. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3717. {
  3718. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  3719. }
  3720. }
  3721. }
  3722. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3723. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  3724. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  3725. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  3726. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  3727. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  3728. } // END FOR DC CASE
  3729. // ================================= Current.Import L2 ===============================================
  3730. //idx_sample=6;
  3731. // AC 3 phse L2 current
  3732. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3733. {
  3734. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3735. {
  3736. tempIndex = 2;
  3737. }
  3738. else
  3739. {
  3740. tempIndex = gun_index;
  3741. }
  3742. for (int index = 0; index < AC_QUANTITY; index++)
  3743. {
  3744. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3745. {
  3746. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  3747. }
  3748. }// End of for AC_QUANTITY
  3749. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  3750. }
  3751. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3752. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  3753. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  3754. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  3755. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3756. // ================================= Current.Import L3 ===============================================
  3757. //idx_sample=7;
  3758. // AC 3 phse L3 current
  3759. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3760. {
  3761. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3762. {
  3763. tempIndex = 2;
  3764. }
  3765. else
  3766. {
  3767. tempIndex = gun_index;
  3768. }
  3769. for (int index = 0; index < AC_QUANTITY; index++)
  3770. {
  3771. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3772. {
  3773. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  3774. }
  3775. }// End of for AC_QUANTITY
  3776. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  3777. }
  3778. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3779. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  3780. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  3781. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  3782. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3783. //============================ Voltage L2 ====================================
  3784. //idx_sample=8;
  3785. // AC 3 phse L2 voltage
  3786. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3787. {
  3788. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3789. {
  3790. tempIndex = 2;
  3791. }
  3792. else
  3793. {
  3794. tempIndex = gun_index;
  3795. }
  3796. for (int index = 0; index < AC_QUANTITY; index++)
  3797. {
  3798. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3799. {
  3800. 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
  3801. }
  3802. } // END OF FOR AC_QUANTITY
  3803. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  3804. }
  3805. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3806. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  3807. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  3808. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  3809. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3810. //============================ Voltage L3 ====================================
  3811. //idx_sample=8;
  3812. // AC 3 phse L3 voltage
  3813. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3814. {
  3815. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3816. {
  3817. tempIndex = 2;
  3818. }
  3819. else
  3820. {
  3821. tempIndex = gun_index;
  3822. }
  3823. for (int index = 0; index < AC_QUANTITY; index++)
  3824. {
  3825. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3826. {
  3827. 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
  3828. }
  3829. } // END OF FOR AC_QUANTITY
  3830. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  3831. }
  3832. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3833. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  3834. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  3835. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  3836. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3837. //================================================ Message create ====================================================
  3838. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3839. {
  3840. 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\"}]}]}]"
  3841. ,gun_index+1
  3842. ,MESSAGE_TYPE_CALL
  3843. ,guid
  3844. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3845. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3846. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3847. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3848. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3849. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3850. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3851. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3852. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3853. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3854. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3855. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3856. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3857. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3858. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3859. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3860. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3861. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3862. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3863. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3864. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3865. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3866. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3867. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3868. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3869. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3870. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3871. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3872. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3873. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3874. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3875. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3876. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3877. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3878. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3879. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3880. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3881. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3882. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3883. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3884. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3885. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  3886. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  3887. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  3888. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  3889. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  3890. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  3891. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  3892. );
  3893. }
  3894. else
  3895. {
  3896. if((ShmSysConfigAndInfo->SysConfig.ModelName[2]!='Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2]!='W'))
  3897. {
  3898. 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\"}]}]}]"
  3899. ,gun_index+1
  3900. ,MESSAGE_TYPE_CALL
  3901. ,guid
  3902. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3903. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3904. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3905. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3906. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3907. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3908. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3909. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3910. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3911. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3912. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3913. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3914. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3915. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3916. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3917. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3918. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3919. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3920. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3921. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3922. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3923. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3924. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3925. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3926. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3927. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3928. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3929. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3930. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3931. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3932. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3933. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3934. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3935. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3936. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3937. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3938. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3939. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3940. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3941. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3942. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3943. );
  3944. }
  3945. else
  3946. {
  3947. 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\"}]}]}]"
  3948. ,gun_index+1
  3949. ,MESSAGE_TYPE_CALL
  3950. ,guid
  3951. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3952. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3953. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3954. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3955. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3956. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3957. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3958. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3959. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3960. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3961. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3962. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3963. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3964. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3965. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3966. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3967. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3968. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3969. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3970. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3971. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3972. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3973. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3974. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3975. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3976. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3977. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3978. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3979. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3980. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3981. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3982. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3983. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3984. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3985. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3986. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3987. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3988. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3989. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3990. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3991. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3992. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value
  3993. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context
  3994. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format
  3995. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand
  3996. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase
  3997. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location
  3998. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit
  3999. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value
  4000. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context
  4001. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format
  4002. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand
  4003. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase
  4004. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location
  4005. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit
  4006. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value
  4007. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context
  4008. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format
  4009. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand
  4010. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase
  4011. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location
  4012. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit
  4013. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value
  4014. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context
  4015. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format
  4016. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand
  4017. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase
  4018. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location
  4019. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit
  4020. );
  4021. }
  4022. }
  4023. #if 1 // for TempStopTransaction
  4024. //Delete TempStopTransaction
  4025. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  4026. {
  4027. remove("/Storage/OCPP/TempStopTransaction"); // remove file "TempStopTransaction"
  4028. }
  4029. #endif
  4030. #if 1
  4031. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4032. if(hashmap_operation(0, guid, tempdata) == 1)
  4033. {
  4034. result = PASS;
  4035. DEBUG_INFO("StopTransaction mapitem pass\n");
  4036. }
  4037. #endif
  4038. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4039. /*
  4040. if(GetTransactionQueueNum() == 1)
  4041. {
  4042. LWS_Send(queuedata+2);
  4043. }*/
  4044. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4045. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4046. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  4047. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4048. {
  4049. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4050. }
  4051. //for test
  4052. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4053. return result;
  4054. }
  4055. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4056. {
  4057. mtrace();
  4058. int result = FAIL;
  4059. char guid[37]={0};
  4060. char tempdata[65]={0};
  4061. int tempIndex = 0;
  4062. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4063. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4064. //set value
  4065. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4066. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ((strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging") != NULL) ? ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId : 0);
  4067. random_uuid(guid);
  4068. //UTC Date time
  4069. struct timeval tmnow;
  4070. struct tm *tm;
  4071. char buf[28];//, usec_buf[6];
  4072. gettimeofday(&tmnow, NULL);
  4073. time_t t;
  4074. t = time(NULL);
  4075. /*UTC time and date*/
  4076. tm = gmtime(&t);
  4077. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4078. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4079. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4080. //idx_sample=0;
  4081. //********************************(1)Current.Import L1************************************************/
  4082. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4083. if(gunType[gun_index] == 'J')
  4084. {
  4085. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4086. {
  4087. tempIndex = ((gun_index==2) ? 1: 0);
  4088. }
  4089. else
  4090. {
  4091. tempIndex = gun_index;
  4092. }
  4093. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4094. {
  4095. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4096. {
  4097. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4098. }
  4099. }
  4100. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4101. }
  4102. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4103. {
  4104. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4105. {
  4106. tempIndex = ((gun_index==2) ? 1: 0);
  4107. }
  4108. else
  4109. {
  4110. tempIndex = gun_index;
  4111. }
  4112. for (int index = 0; index < CCS_QUANTITY; index++)
  4113. {
  4114. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4115. {
  4116. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4117. }
  4118. }
  4119. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4120. }
  4121. else if(gunType[gun_index] == 'G')
  4122. {
  4123. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4124. {
  4125. tempIndex = ((gun_index==2) ? 1: 0);
  4126. }
  4127. else
  4128. {
  4129. tempIndex = gun_index;
  4130. }
  4131. for (int index = 0; index < GB_QUANTITY; index++)
  4132. {
  4133. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4134. {
  4135. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4136. }
  4137. }
  4138. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4139. }
  4140. else
  4141. {
  4142. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4143. {
  4144. tempIndex = 2;
  4145. }
  4146. else
  4147. {
  4148. tempIndex = gun_index;
  4149. }
  4150. for (int index = 0; index < AC_QUANTITY; index++)
  4151. {
  4152. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4153. {
  4154. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4155. }
  4156. }
  4157. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4158. }
  4159. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4160. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4161. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4162. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4163. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4164. //idx_sample=1;
  4165. //********************************(2)Energy.Active.Import.Register ************************************************/
  4166. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4167. if(gunType[gun_index] == 'J')
  4168. {
  4169. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4170. {
  4171. tempIndex = ((gun_index==2) ? 1: 0);
  4172. }
  4173. else
  4174. {
  4175. tempIndex = gun_index;
  4176. }
  4177. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4178. {
  4179. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4180. {
  4181. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4182. }
  4183. }
  4184. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4185. }
  4186. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4187. {
  4188. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4189. {
  4190. tempIndex = ((gun_index==2) ? 1: 0);
  4191. }
  4192. else
  4193. {
  4194. tempIndex = gun_index;
  4195. }
  4196. for (int index = 0; index < CCS_QUANTITY; index++)
  4197. {
  4198. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4199. {
  4200. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4201. }
  4202. }
  4203. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4204. }
  4205. else if(gunType[gun_index] == 'G')
  4206. {
  4207. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4208. {
  4209. tempIndex = ((gun_index==2) ? 1: 0);
  4210. }
  4211. else
  4212. {
  4213. tempIndex = gun_index;
  4214. }
  4215. for (int index = 0; index < GB_QUANTITY; index++)
  4216. {
  4217. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4218. {
  4219. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4220. }
  4221. }
  4222. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4223. }
  4224. else
  4225. {
  4226. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4227. {
  4228. tempIndex = 2;
  4229. }
  4230. else
  4231. {
  4232. tempIndex = gun_index;
  4233. }
  4234. for (int index = 0; index < AC_QUANTITY; index++)
  4235. {
  4236. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4237. {
  4238. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4239. }
  4240. }
  4241. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4242. }
  4243. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  4244. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4245. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4246. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4247. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4248. //idx_sample=2;
  4249. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  4250. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4251. if(gunType[gun_index] == 'J')
  4252. {
  4253. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4254. {
  4255. tempIndex = ((gun_index==2) ? 1: 0);
  4256. }
  4257. else
  4258. {
  4259. tempIndex = gun_index;
  4260. }
  4261. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4262. {
  4263. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4264. {
  4265. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4266. }
  4267. } // END OF FOR CHAdeMO_QUANTITY
  4268. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4269. }
  4270. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4271. {
  4272. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4273. {
  4274. tempIndex = ((gun_index==2) ? 1: 0);
  4275. }
  4276. else
  4277. {
  4278. tempIndex = gun_index;
  4279. }
  4280. for (int index = 0; index < CCS_QUANTITY; index++)
  4281. {
  4282. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4283. {
  4284. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  4285. }
  4286. } // END OF CCS_QUANTITY
  4287. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4288. }
  4289. else if(gunType[gun_index] == 'G')
  4290. {
  4291. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4292. {
  4293. tempIndex = ((gun_index==2) ? 1: 0);
  4294. }
  4295. else
  4296. {
  4297. tempIndex = gun_index;
  4298. }
  4299. for (int index = 0; index < GB_QUANTITY; index++)
  4300. {
  4301. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4302. {
  4303. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  4304. }
  4305. } // END OF GB_QUANTITY
  4306. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4307. }
  4308. else
  4309. {
  4310. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4311. {
  4312. tempIndex = 2;
  4313. }
  4314. else
  4315. {
  4316. tempIndex = gun_index;
  4317. }
  4318. for (int index = 0; index < AC_QUANTITY; index++)
  4319. {
  4320. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4321. {
  4322. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  4323. }
  4324. }
  4325. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  4326. }
  4327. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  4328. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  4329. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  4330. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  4331. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4332. //idx_sample=3;
  4333. //********************************(4)Power.Active.Import************************************************/
  4334. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4335. if(gunType[gun_index] == 'J')
  4336. {
  4337. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4338. {
  4339. tempIndex = ((gun_index==2) ? 1: 0);
  4340. }
  4341. else
  4342. {
  4343. tempIndex = gun_index;
  4344. }
  4345. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4346. {
  4347. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4348. {
  4349. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  4350. }
  4351. } // END OF FOR
  4352. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4353. }
  4354. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4355. {
  4356. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4357. {
  4358. tempIndex = ((gun_index==2) ? 1: 0);
  4359. }
  4360. else
  4361. {
  4362. tempIndex = gun_index;
  4363. }
  4364. for (int index = 0; index < CCS_QUANTITY; index++)
  4365. {
  4366. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4367. {
  4368. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  4369. }
  4370. }
  4371. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4372. }
  4373. else if(gunType[gun_index] == 'G')
  4374. {
  4375. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4376. {
  4377. tempIndex = ((gun_index==2) ? 1: 0);
  4378. }
  4379. else
  4380. {
  4381. tempIndex = gun_index;
  4382. }
  4383. for (int index = 0; index < GB_QUANTITY; index++)
  4384. {
  4385. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4386. {
  4387. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4388. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  4389. }
  4390. }
  4391. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4392. }
  4393. else
  4394. {
  4395. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4396. {
  4397. tempIndex = 2;
  4398. }
  4399. else
  4400. {
  4401. tempIndex = gun_index;
  4402. }
  4403. for (int index = 0; index < AC_QUANTITY; index++)
  4404. {
  4405. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4406. {
  4407. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  4408. }
  4409. }
  4410. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  4411. }
  4412. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  4413. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  4414. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  4415. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  4416. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  4417. //idx_sample=4;
  4418. //***********************************************(5)VOLTAGE L1******************************************************/
  4419. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4420. if(gunType[gun_index] == 'J')
  4421. {
  4422. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4423. {
  4424. tempIndex = ((gun_index==2) ? 1: 0);
  4425. }
  4426. else
  4427. {
  4428. tempIndex = gun_index;
  4429. }
  4430. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4431. {
  4432. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4433. {
  4434. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  4435. }
  4436. }
  4437. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4438. }
  4439. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4440. {
  4441. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4442. {
  4443. tempIndex = ((gun_index==2) ? 1: 0);
  4444. }
  4445. else
  4446. {
  4447. tempIndex = gun_index;
  4448. }
  4449. for (int index = 0; index < CCS_QUANTITY; index++)
  4450. {
  4451. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4452. {
  4453. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  4454. }
  4455. }
  4456. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4457. }
  4458. else if(gunType[gun_index] == 'G')
  4459. {
  4460. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4461. {
  4462. tempIndex = ((gun_index==2) ? 1: 0);
  4463. }
  4464. else
  4465. {
  4466. tempIndex = gun_index;
  4467. }
  4468. for (int index = 0; index < GB_QUANTITY; index++)
  4469. {
  4470. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4471. {
  4472. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  4473. }
  4474. }
  4475. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4476. }
  4477. else
  4478. {
  4479. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4480. {
  4481. tempIndex = 2;
  4482. }
  4483. else
  4484. {
  4485. tempIndex = gun_index;
  4486. }
  4487. for (int index = 0; index < AC_QUANTITY; index++)
  4488. {
  4489. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4490. {
  4491. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  4492. }
  4493. }
  4494. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  4495. }
  4496. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  4497. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  4498. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  4499. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  4500. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4501. //***********************************************(6)SOC******************************************************/
  4502. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  4503. {
  4504. //idx_sample=5;
  4505. //sampledValue = NULL;
  4506. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4507. {
  4508. tempIndex = ((gun_index==2) ? 1: 0);
  4509. }
  4510. else
  4511. {
  4512. tempIndex = gun_index;
  4513. }
  4514. if(gunType[gun_index] == 'J')
  4515. {
  4516. //tempIndex = ((gun_index==2) ? 1: 0);
  4517. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4518. {
  4519. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4520. {
  4521. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  4522. }
  4523. }
  4524. }
  4525. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4526. {
  4527. //tempIndex = ((gun_index==2) ? 1: 0);
  4528. for (int index = 0; index < CCS_QUANTITY; index++)
  4529. {
  4530. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4531. {
  4532. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  4533. }
  4534. }
  4535. }
  4536. else if(gunType[gun_index] == 'G')
  4537. {
  4538. //tempIndex = ((gun_index==2) ? 1: 0);
  4539. for (int index = 0; index < GB_QUANTITY; index++)
  4540. {
  4541. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4542. {
  4543. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  4544. }
  4545. }
  4546. }
  4547. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4548. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  4549. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  4550. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  4551. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_Outlet]);
  4552. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  4553. }
  4554. //********************************(7)Current.Import L2************************************************/
  4555. // Only for AC 3 phase
  4556. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4557. {
  4558. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4559. {
  4560. tempIndex = 2;
  4561. }
  4562. else
  4563. {
  4564. tempIndex = gun_index;
  4565. }
  4566. for (int index = 0; index < AC_QUANTITY; index++)
  4567. {
  4568. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4569. {
  4570. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  4571. }
  4572. }
  4573. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  4574. }
  4575. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  4576. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  4577. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  4578. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  4579. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4580. //********************************(8)Current.Import L3************************************************/
  4581. // Only for AC 3 phase
  4582. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4583. {
  4584. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4585. {
  4586. tempIndex = 2;
  4587. }
  4588. else
  4589. {
  4590. tempIndex = gun_index;
  4591. }
  4592. for (int index = 0; index < AC_QUANTITY; index++)
  4593. {
  4594. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4595. {
  4596. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  4597. }
  4598. }
  4599. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  4600. }
  4601. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  4602. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  4603. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  4604. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  4605. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4606. //***********************************************(9)VOLTAGE L2******************************************************/
  4607. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4608. {
  4609. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4610. {
  4611. tempIndex = 2;
  4612. }
  4613. else
  4614. {
  4615. tempIndex = gun_index;
  4616. }
  4617. for (int index = 0; index < AC_QUANTITY; index++)
  4618. {
  4619. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4620. {
  4621. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  4622. }
  4623. }
  4624. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  4625. }
  4626. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  4627. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  4628. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  4629. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  4630. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4631. //***********************************************(10)VOLTAGE L3******************************************************/
  4632. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4633. {
  4634. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4635. {
  4636. tempIndex = 2;
  4637. }
  4638. else
  4639. {
  4640. tempIndex = gun_index;
  4641. }
  4642. for (int index = 0; index < AC_QUANTITY; index++)
  4643. {
  4644. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4645. {
  4646. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  4647. }
  4648. }
  4649. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  4650. }
  4651. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  4652. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  4653. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  4654. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  4655. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4656. // Message create ====================================================================================================
  4657. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  4658. {
  4659. 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\"}]}]}]"
  4660. ,gun_index + 1
  4661. ,MESSAGE_TYPE_CALL
  4662. ,guid
  4663. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4664. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4665. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4666. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4667. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4668. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4669. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4670. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4671. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4672. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4673. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4674. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4675. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4676. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4677. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4678. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4679. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4680. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4681. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4682. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4683. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4684. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4685. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4686. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4687. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4688. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4689. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4690. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4691. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4692. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4693. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4694. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4695. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4696. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4697. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4698. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4699. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4700. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4701. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value
  4702. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context
  4703. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format
  4704. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand
  4705. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase
  4706. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location
  4707. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit
  4708. );
  4709. }
  4710. else
  4711. {
  4712. if((ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'W'))
  4713. {
  4714. 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\"}]}]}]"
  4715. ,gun_index + 1
  4716. ,MESSAGE_TYPE_CALL
  4717. ,guid
  4718. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4719. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4720. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4721. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4722. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4723. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4724. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4725. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4726. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4727. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4728. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4729. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4730. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4731. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4732. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4733. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4734. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4735. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4736. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4737. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4738. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4739. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4740. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4741. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4742. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4743. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4744. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4745. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4746. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4747. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4748. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4749. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4750. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4751. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4752. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4753. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4754. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4755. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4756. );
  4757. }
  4758. else
  4759. {
  4760. 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\"}]}]}]"
  4761. ,gun_index + 1
  4762. ,MESSAGE_TYPE_CALL
  4763. ,guid
  4764. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4765. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4766. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4767. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4768. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4769. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4770. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4771. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4772. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4773. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4774. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4775. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4776. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4777. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4778. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4779. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4780. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4781. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4782. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4783. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4784. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4785. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4786. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4787. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4788. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4789. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4790. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4791. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4792. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4793. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4794. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4795. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4796. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4797. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4798. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4799. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4800. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4801. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4802. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value
  4803. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context
  4804. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format
  4805. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand
  4806. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase
  4807. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location
  4808. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit
  4809. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value
  4810. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context
  4811. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format
  4812. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand
  4813. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase
  4814. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location
  4815. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit
  4816. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value
  4817. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context
  4818. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format
  4819. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand
  4820. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase
  4821. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location
  4822. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit
  4823. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value
  4824. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context
  4825. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format
  4826. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand
  4827. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase
  4828. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location
  4829. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit
  4830. );
  4831. }
  4832. }
  4833. // Put request guid to hash map
  4834. sprintf(tempdata, "MeterValues,%d", (gun_index));
  4835. 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*/)
  4836. {
  4837. result = PASS;
  4838. DEBUG_INFO("MeterValues mapitem pass\n");
  4839. }
  4840. if(dataType != ReadingContext_Trigger)
  4841. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4842. else
  4843. LWS_Send(queuedata +2);
  4844. /*
  4845. if(GetTransactionQueueNum() == 1)
  4846. {
  4847. LWS_Send(queuedata +2);
  4848. }*/
  4849. return result;
  4850. }
  4851. //==========================================
  4852. // send confirm routine
  4853. //==========================================
  4854. int sendCancelReservationConfirmation(char *uuid,char *payload)
  4855. {
  4856. mtrace();
  4857. int result = FAIL;
  4858. char message[100]={0};
  4859. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  4860. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4861. LWS_Send(message);
  4862. result = TRUE;
  4863. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  4864. return result;
  4865. }
  4866. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  4867. {
  4868. mtrace();
  4869. int result = FAIL;
  4870. char message[100]={0};
  4871. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  4872. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4873. LWS_Send(message);
  4874. result = TRUE;
  4875. return result;
  4876. }
  4877. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  4878. {
  4879. mtrace();
  4880. int result = FAIL;
  4881. char message[100]={0};
  4882. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  4883. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4884. LWS_Send(message);
  4885. result = TRUE;
  4886. return result;
  4887. }
  4888. int sendClearCacheConfirmation(char *uuid,char *payload)
  4889. {
  4890. mtrace();
  4891. int result = FAIL;
  4892. char message[500]={0};
  4893. DEBUG_INFO("sendClearCacheConfirmation...\n");
  4894. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4895. LWS_Send(message);
  4896. return result;
  4897. }
  4898. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  4899. {
  4900. mtrace();
  4901. int result = FAIL;
  4902. char message[500]={0};
  4903. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  4904. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4905. LWS_Send(message);
  4906. return result;
  4907. }
  4908. int sendDataTransferConfirmation(char *uuid,char *payload)
  4909. {
  4910. mtrace();
  4911. char statusStr[20]={0};
  4912. char dataStr[10]={0};
  4913. char sstr[20]={0};
  4914. int c = 0;
  4915. char *loc;
  4916. int result = FAIL;
  4917. DEBUG_INFO("sendDataTransferConfirmation...\n");
  4918. /**********************status**************************/
  4919. loc = strstr(payload, "status");
  4920. memset(sstr ,0, ARRAY_SIZE(sstr) );
  4921. c = 0;
  4922. while (loc[3+strlen("status")+c] != '\"')
  4923. {
  4924. sstr[c] = loc[3+strlen("status")+c];
  4925. c++;
  4926. }
  4927. sstr[c] = '\0';
  4928. strcpy(statusStr, sstr);
  4929. /**********************data**************************/
  4930. loc = strstr(payload, "data");
  4931. memset(sstr ,0, ARRAY_SIZE(sstr) );
  4932. c = 0;
  4933. while (loc[3+strlen("data")+c] != '\"')
  4934. {
  4935. sstr[c] = loc[3+strlen("data")+c];
  4936. c++;
  4937. }
  4938. sstr[c] = '\0';
  4939. strcpy(dataStr, sstr);
  4940. return result;
  4941. }
  4942. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  4943. {
  4944. mtrace();
  4945. int result = FAIL;
  4946. char message[1000]={0};
  4947. int CompositeScheduleIndex = 0;
  4948. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  4949. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  4950. if(nPeriod == 0)
  4951. {
  4952. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  4953. {
  4954. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  4955. ,MESSAGE_TYPE_CALLRESULT
  4956. ,uuid
  4957. ,payload
  4958. ,connectorIdInt);
  4959. }
  4960. else
  4961. {
  4962. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  4963. ,MESSAGE_TYPE_CALLRESULT
  4964. ,uuid
  4965. ,payload
  4966. ,connectorIdInt
  4967. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4968. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  4969. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4970. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  4971. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  4972. }
  4973. }
  4974. else
  4975. {
  4976. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  4977. ,MESSAGE_TYPE_CALLRESULT
  4978. ,uuid
  4979. ,payload
  4980. ,connectorIdInt
  4981. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4982. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  4983. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4984. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  4985. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  4986. {
  4987. if (idx_sample == 0)
  4988. {
  4989. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  4990. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  4991. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  4992. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  4993. }
  4994. else
  4995. {
  4996. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  4997. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  4998. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  4999. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5000. }
  5001. }
  5002. sprintf(message + strlen(message), "]}}]");
  5003. }
  5004. LWS_Send(message);
  5005. result = TRUE;
  5006. return result;
  5007. }
  5008. int sendGetConfigurationConfirmation(char *uuid)
  5009. {
  5010. mtrace();
  5011. int result = FAIL;
  5012. int MaxKeySupported = 0;
  5013. int sentConfigurationNumber= 0;
  5014. int sentunConfigurationNumber= 0;
  5015. char message[4000]={0};
  5016. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5017. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5018. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5019. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5020. ,MESSAGE_TYPE_CALLRESULT
  5021. ,uuid );
  5022. //configuration key
  5023. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5024. {
  5025. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5026. {
  5027. if (sentConfigurationNumber == 0)
  5028. {
  5029. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5030. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5031. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5032. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5033. }
  5034. else
  5035. {
  5036. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5037. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5038. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5039. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5040. }
  5041. sentConfigurationNumber = sentConfigurationNumber + 1;
  5042. }
  5043. }
  5044. sprintf(message + strlen(message), "]");
  5045. if(UnknownKeynum != 0)
  5046. {
  5047. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5048. //unkown key
  5049. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5050. {
  5051. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5052. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5053. if(sentunConfigurationNumber == 0)
  5054. {
  5055. sprintf(message + strlen(message), "\"%s\""
  5056. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5057. }
  5058. else
  5059. {
  5060. sprintf(message + strlen(message), ",\"%s\""
  5061. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5062. }
  5063. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5064. }
  5065. sprintf(message + strlen(message), "]");
  5066. }
  5067. sprintf(message + strlen(message), "}]");
  5068. LWS_Send(message);
  5069. return result;
  5070. }
  5071. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5072. {
  5073. mtrace();
  5074. int result = FAIL;
  5075. char message[400]={0};
  5076. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5077. if(strcmp(payload,"")==0)
  5078. {
  5079. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5080. }
  5081. else
  5082. {
  5083. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5084. }
  5085. LWS_Send(message);
  5086. result = TRUE;
  5087. return result;
  5088. }
  5089. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5090. {
  5091. mtrace();
  5092. int result = FAIL;
  5093. char message[80]={0};
  5094. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5095. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  5096. LWS_Send(message);
  5097. result = TRUE;
  5098. return result;
  5099. }
  5100. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5101. {
  5102. mtrace();
  5103. int result = FAIL;
  5104. char message[80]={0};
  5105. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5106. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5107. LWS_Send(message);
  5108. result = TRUE;
  5109. return result;
  5110. }
  5111. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5112. {
  5113. mtrace();
  5114. int result = FAIL;
  5115. char message[80]={0};
  5116. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5117. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5118. LWS_Send(message);
  5119. result = TRUE;
  5120. return result;
  5121. }
  5122. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5123. {
  5124. mtrace();
  5125. int result = FAIL;
  5126. char message[80]={0};
  5127. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5128. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5129. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5130. LWS_Send(message);
  5131. result = TRUE;
  5132. return result;
  5133. }
  5134. int sendResetConfirmation(char *uuid,char *payload)
  5135. {
  5136. mtrace();
  5137. int result = FAIL;
  5138. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  5139. char message[80]={0};
  5140. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  5141. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5142. LWS_Send(message);
  5143. result = TRUE;
  5144. return result;
  5145. }
  5146. int sendSendLocalListConfirmation(char *uuid,char *payload)
  5147. {
  5148. mtrace();
  5149. int result = FAIL;
  5150. char message[500]={0};
  5151. // [ 3, "1571284266109", { "status": "Accepted" } ]
  5152. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5153. LWS_Send(message);
  5154. result = TRUE;
  5155. return result;
  5156. }
  5157. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  5158. {
  5159. mtrace();
  5160. int result = FAIL;
  5161. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  5162. char message[80]={0};
  5163. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  5164. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5165. LWS_Send(message);
  5166. result = TRUE;
  5167. return result;
  5168. }
  5169. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  5170. {
  5171. mtrace();
  5172. int result = FAIL;
  5173. char message[80]={0};
  5174. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  5175. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5176. LWS_Send(message);
  5177. result = TRUE;
  5178. return result;
  5179. }
  5180. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  5181. {
  5182. mtrace();
  5183. int result = FAIL;
  5184. char message[80]={0};
  5185. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5186. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  5187. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5188. LWS_Send(message);
  5189. result = TRUE;
  5190. return result;
  5191. }
  5192. int sendUpdateFirmwareConfirmation(char *uuid)
  5193. {
  5194. mtrace();
  5195. int result = FAIL;
  5196. char message[60]={0};
  5197. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5198. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  5199. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5200. LWS_Send(message);
  5201. result = TRUE;
  5202. return result;
  5203. }
  5204. //==========================================
  5205. // send CallError routine
  5206. //==========================================
  5207. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  5208. {
  5209. mtrace();
  5210. char message[220]={0};
  5211. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  5212. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  5213. LWS_Send(message);
  5214. }
  5215. //==========================================
  5216. // Handle server request routine Start
  5217. //==========================================
  5218. int handleCancelReservationRequest(char *uuid, char *payload)
  5219. {
  5220. mtrace();
  5221. int result = FAIL;
  5222. int gunNO = 0;
  5223. int reservationIdInt =0;
  5224. char comfirmstr[20];
  5225. DEBUG_INFO("handleCancelReservationRequest...\n");
  5226. json_object *CancelReservation;
  5227. CancelReservation = json_tokener_parse(payload);
  5228. if(!is_error(CancelReservation))
  5229. {
  5230. // Required data
  5231. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  5232. }
  5233. json_object_put(CancelReservation);
  5234. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5235. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  5236. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  5237. //check Transaction active
  5238. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5239. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5240. {
  5241. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  5242. {
  5243. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5244. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5245. if(gunType[2] == 'J')
  5246. {
  5247. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  5248. }
  5249. else
  5250. {
  5251. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  5252. }
  5253. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5254. goto end;
  5255. }
  5256. }
  5257. for (int index = 0; index < CCS_QUANTITY; index++)
  5258. {
  5259. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  5260. {
  5261. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5262. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5263. if((gunType[2] == 'U') || (gunType[2] == 'E'))
  5264. {
  5265. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  5266. }
  5267. else
  5268. {
  5269. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  5270. }
  5271. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5272. goto end;
  5273. }
  5274. }
  5275. for (int index = 0; index < GB_QUANTITY; index++)
  5276. {
  5277. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  5278. {
  5279. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5280. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5281. if(gunType[2] == 'G')
  5282. {
  5283. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  5284. }
  5285. else
  5286. {
  5287. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  5288. }
  5289. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5290. goto end;
  5291. }
  5292. }
  5293. for (int index = 0; index < AC_QUANTITY; index++)
  5294. {
  5295. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  5296. {
  5297. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5298. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5299. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5300. {
  5301. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  5302. }
  5303. else
  5304. {
  5305. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  5306. }
  5307. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5308. goto end;
  5309. }
  5310. }
  5311. //The reservationId does NOT match the reservationId
  5312. sendCancelReservationConfirmation(uuid, comfirmstr);
  5313. end:
  5314. // Fill in ocpp packet uuid
  5315. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  5316. return result;
  5317. }
  5318. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  5319. {
  5320. mtrace();
  5321. int result = FAIL;
  5322. int gunIndex = 0;
  5323. char typeStr[16]={0};
  5324. char comfirmstr[20];
  5325. int specificId = FALSE;
  5326. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  5327. json_object *ChangeAvailability;
  5328. ChangeAvailability = json_tokener_parse(payload);
  5329. if(!is_error(ChangeAvailability))
  5330. {
  5331. // Required data
  5332. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  5333. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  5334. }
  5335. json_object_put(ChangeAvailability);
  5336. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5337. {
  5338. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  5339. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  5340. }
  5341. else if(gunIndex == 0)
  5342. {
  5343. for(int i=0; i < gunTotalNumber; i++)
  5344. {
  5345. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  5346. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  5347. }
  5348. }
  5349. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5350. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5351. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  5352. {
  5353. specificId = TRUE;
  5354. }
  5355. if(specificId == FALSE)
  5356. goto end;
  5357. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  5358. {
  5359. //----------------------gunIndex is 0 ------------------------------------------------//
  5360. if(gunIndex == 0)
  5361. {
  5362. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5363. {
  5364. for(int i=0; i < gunTotalNumber; i++)
  5365. {
  5366. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5367. {
  5368. if ((gunType[i] == 'J')&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  5369. {
  5370. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5371. {
  5372. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5373. goto end;
  5374. }
  5375. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5376. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5377. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5378. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5379. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5380. {
  5381. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5382. goto end;
  5383. }
  5384. }
  5385. }//END FOR CHAdeMO_QUANTITY
  5386. for (int index = 0; index < CCS_QUANTITY; index++)
  5387. {
  5388. if (((gunType[i] == 'U')||(gunType[i] == 'E'))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  5389. {
  5390. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  5391. {
  5392. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5393. goto end;
  5394. }
  5395. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5396. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5397. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5398. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5399. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5400. {
  5401. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5402. goto end;
  5403. }
  5404. }
  5405. }//END FOR CCS_QUANTITY
  5406. for (int index = 0; index < GB_QUANTITY; index++)
  5407. {
  5408. if ((gunType[i] == 'G')&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  5409. {
  5410. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5411. {
  5412. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5413. goto end;
  5414. }
  5415. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5416. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5417. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5418. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5419. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5420. {
  5421. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5422. goto end;
  5423. }
  5424. }
  5425. }// END FOR GB_QUANTITY
  5426. for (int index = 0; index < AC_QUANTITY; index++)
  5427. {
  5428. if (((gunType[i] > '0')&&(gunType[i] <= '9'))&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  5429. {
  5430. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5431. {
  5432. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5433. goto end;
  5434. }
  5435. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5436. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5437. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5438. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5439. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5440. {
  5441. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5442. goto end;
  5443. }
  5444. }
  5445. }//END FOR AC_QUANTITY
  5446. }// END FOR gunTotalNumber
  5447. }
  5448. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5449. {
  5450. for(int i=0; i < gunTotalNumber; i++)
  5451. {
  5452. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5453. {
  5454. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5455. goto end;
  5456. }
  5457. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5458. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  5459. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  5460. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  5461. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5462. {
  5463. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5464. goto end;
  5465. }
  5466. }
  5467. }
  5468. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5469. goto end;
  5470. }
  5471. //----------------------gunIndex is not 0 ------------------------------------------------//
  5472. //check Transaction active
  5473. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5474. {
  5475. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J'))
  5476. {
  5477. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  5478. {
  5479. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5480. goto end;
  5481. }
  5482. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5483. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5484. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5485. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5486. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5487. {
  5488. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5489. goto end;
  5490. }
  5491. else
  5492. {
  5493. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  5494. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5495. goto end;
  5496. }
  5497. }
  5498. }//END FOR CHAdeMO_QUANTITY
  5499. for (int index = 0; index < CCS_QUANTITY; index++)
  5500. {
  5501. if ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E')))
  5502. {
  5503. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  5504. {
  5505. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5506. goto end;
  5507. }
  5508. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5509. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5510. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5511. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5512. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5513. {
  5514. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5515. goto end;
  5516. }
  5517. else
  5518. {
  5519. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  5520. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5521. goto end;
  5522. }
  5523. }
  5524. }//END FOR CCS_QUANTITY
  5525. for (int index = 0; index < GB_QUANTITY; index++)
  5526. {
  5527. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))
  5528. {
  5529. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5530. {
  5531. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5532. goto end;
  5533. }
  5534. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5535. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5536. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5537. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5538. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5539. {
  5540. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5541. goto end;
  5542. }
  5543. else
  5544. {
  5545. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  5546. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5547. goto end;
  5548. }
  5549. }
  5550. }// END FOR GB_QUANTITY
  5551. for (int index = 0; index < AC_QUANTITY; index++)
  5552. {
  5553. if ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))
  5554. {
  5555. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5556. {
  5557. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5558. goto end;
  5559. }
  5560. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5561. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5562. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5563. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5564. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5565. {
  5566. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5567. goto end;
  5568. }
  5569. else
  5570. {
  5571. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  5572. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5573. goto end;
  5574. }
  5575. }
  5576. }//END FOR AC_QUANTITY
  5577. }//END FOR AvailabilityTypeStr[Inoperative]
  5578. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  5579. {
  5580. //----------------------gunIndex is 0 ------------------------------------------------//
  5581. if(gunIndex == 0)
  5582. {
  5583. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5584. {
  5585. for(int i=0; i < gunTotalNumber; i++)
  5586. {
  5587. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5588. {
  5589. 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
  5590. {
  5591. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5592. goto end;
  5593. }
  5594. }//END FOR CHAdeMO_QUANTITY
  5595. for (int index = 0; index < CCS_QUANTITY; index++)
  5596. {
  5597. 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
  5598. {
  5599. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5600. goto end;
  5601. }
  5602. }//END FOR CCS_QUANTITY
  5603. for (int index = 0; index < GB_QUANTITY; index++)
  5604. {
  5605. 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
  5606. {
  5607. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5608. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5609. goto end;
  5610. }
  5611. }// END FOR GB_QUANTITY
  5612. for (int index = 0; index < AC_QUANTITY; index++)
  5613. {
  5614. 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
  5615. {
  5616. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5617. goto end;
  5618. }
  5619. }//END FOR CHAdeMO_QUANTITY
  5620. }// END FOR gunTotalNumber
  5621. }
  5622. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5623. {
  5624. for(int i=0; i < gunTotalNumber; i++)
  5625. {
  5626. for (int index = 0; index < AC_QUANTITY; index++)
  5627. {
  5628. 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
  5629. {
  5630. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5631. goto end;
  5632. }
  5633. }//END FOR CHAdeMO_QUANTITY
  5634. } // END FOR gunTotalNumber
  5635. }
  5636. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5637. goto end;
  5638. }
  5639. //----------------------gunIndex is not 0 ------------------------------------------------//
  5640. //check Transaction active
  5641. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5642. {
  5643. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'J') ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5644. {
  5645. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5646. goto end;
  5647. }
  5648. }//END FOR CHAdeMO_QUANTITY
  5649. for (int index = 0; index < CCS_QUANTITY; index++)
  5650. {
  5651. if ((((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5652. {
  5653. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5654. goto end;
  5655. }
  5656. }//END FOR CCS_QUANTITY
  5657. for (int index = 0; index < GB_QUANTITY; index++)
  5658. {
  5659. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5660. {
  5661. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5662. goto end;
  5663. }
  5664. }// END FOR GB_QUANTITY
  5665. for (int index = 0; index < AC_QUANTITY; index++)
  5666. {
  5667. if (((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9'))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5668. {
  5669. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5670. goto end;
  5671. }
  5672. }//END FOR AC_QUANTITY
  5673. }//END FOR AvailabilityTypeStr[Operative]
  5674. end:
  5675. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5676. {
  5677. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  5678. }
  5679. else
  5680. {
  5681. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  5682. }
  5683. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5684. {
  5685. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5686. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5687. }
  5688. else if(gunIndex == 0)
  5689. {
  5690. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5691. {
  5692. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  5693. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  5694. }
  5695. }
  5696. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  5697. return result;
  5698. }
  5699. int handleChangeConfigurationRequest(char *uuid, char *payload)
  5700. {
  5701. mtrace();
  5702. int result = FAIL;
  5703. char keystr[40]={0};
  5704. char valuestr[100]={0};
  5705. char comfirmstr[20]={0};
  5706. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  5707. json_object *ChangeConfiguration;
  5708. ChangeConfiguration = json_tokener_parse(payload);
  5709. if(!is_error(ChangeConfiguration))
  5710. {
  5711. // Required data
  5712. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  5713. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  5714. }
  5715. json_object_put(ChangeConfiguration);
  5716. if((uuid==NULL) || (payload ==NULL) )
  5717. {
  5718. DEBUG_ERROR("Payload is null\n");
  5719. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5720. }
  5721. else
  5722. {
  5723. int status = setKeyValue(keystr, valuestr);
  5724. switch(status)
  5725. {
  5726. case ConfigurationStatus_Accepted:
  5727. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  5728. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  5729. StoreConfigurationTable();
  5730. break;
  5731. case ConfigurationStatus_Rejected:
  5732. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5733. break;
  5734. case RebootRequired:
  5735. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  5736. StoreConfigurationTable();
  5737. break;
  5738. case NotSupported:
  5739. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  5740. break;
  5741. default:
  5742. break;
  5743. }
  5744. }
  5745. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  5746. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  5747. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  5748. {
  5749. ChageWebSocketPingInterval(atoi(valuestr));
  5750. }
  5751. return result;
  5752. }
  5753. int handleClearCacheRequest(char *uuid, char *payload)
  5754. {
  5755. mtrace();
  5756. int result = FAIL;
  5757. char comfirmstr[20];
  5758. int fd;
  5759. char rmFileCmd[100]={0};
  5760. struct stat stats;
  5761. DEBUG_INFO("handleClearCacheRequest...\n");
  5762. stat("/Storage/OCPP", &stats);
  5763. // Check for directory existence
  5764. if (S_ISDIR(stats.st_mode) == 1)
  5765. {}
  5766. else
  5767. {
  5768. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  5769. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  5770. system(rmFileCmd);
  5771. }
  5772. memset(rmFileCmd, 0, ARRAY_SIZE(rmFileCmd));
  5773. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  5774. {
  5775. DEBUG_INFO("AuthorizationCache file exist.\n");
  5776. }
  5777. else
  5778. {
  5779. DEBUG_INFO("AuthorizationCache file not exist\n");
  5780. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  5781. if(log == NULL)
  5782. {
  5783. DEBUG_INFO("AuthorizationCache file is NULL\n");
  5784. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5785. goto end;
  5786. }
  5787. else
  5788. {
  5789. fclose(log);
  5790. }
  5791. }
  5792. if((fd = open(AuthorizationCache_JSON,O_RDWR)) < 0)
  5793. {
  5794. DEBUG_INFO("open AuthorizationCache file failed\n");
  5795. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5796. }
  5797. else
  5798. {
  5799. DEBUG_INFO("open AuthorizationCache file successful\n");
  5800. ftruncate(fd,0);
  5801. lseek(fd,0,SEEK_SET);
  5802. close(fd);
  5803. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  5804. }
  5805. end:
  5806. sendClearCacheConfirmation(uuid, comfirmstr);
  5807. return result;
  5808. }
  5809. int handleClearChargingProfileRequest(char *uuid, char *payload)
  5810. {
  5811. mtrace();
  5812. int result = FAIL;
  5813. int resultRename;
  5814. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  5815. char chargingProfilePurposeStr[26]={0};
  5816. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  5817. char tempchargingProfilePurposeStr[26]={0};
  5818. char sstr[160]={0};
  5819. char str[100]={0};
  5820. int c = 0;
  5821. char *loc;
  5822. char fname[200]={0};
  5823. char comfirmstr[20]={0};
  5824. char word[1600]={0};
  5825. int clearflag = FALSE;
  5826. int chargingProfileIdIsNULL = FALSE;
  5827. int connectorIsNULL = FALSE;
  5828. int chargingProfilePurposeIsNULL = FALSE;
  5829. int stackLevelIsNULL = FALSE;
  5830. //int GotoEnd = FALSE;
  5831. FILE *fptr1, *fptr2;
  5832. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  5833. int n_chargingProfile=0;
  5834. int isEmptyFile = FALSE;
  5835. char sLineWord[1600]={0};
  5836. char chargingProfiles[10][100]={0};
  5837. int ChargeProfileCount = 0;
  5838. char ch;
  5839. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  5840. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  5841. json_object *ClearChargingProfile;
  5842. ClearChargingProfile = json_tokener_parse(payload);
  5843. if(!is_error(ClearChargingProfile))
  5844. {
  5845. // Optional data
  5846. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  5847. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  5848. else
  5849. chargingProfileIdIsNULL = TRUE;
  5850. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  5851. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  5852. else
  5853. connectorIsNULL = TRUE;
  5854. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  5855. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  5856. else
  5857. chargingProfilePurposeIsNULL = TRUE;
  5858. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  5859. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  5860. else
  5861. stackLevelIsNULL = TRUE;
  5862. }
  5863. json_object_put(ClearChargingProfile);
  5864. if(connectorIsNULL == FALSE)
  5865. {
  5866. switch(connectorIdInt)
  5867. {
  5868. case 0:
  5869. if(chargingProfilePurposeIsNULL == TRUE)
  5870. {
  5871. int l = 0;
  5872. strcpy(fname, ChargePointMaxProfile_JSON);
  5873. if((access(fname,F_OK))!=-1)
  5874. {
  5875. strcpy(chargingProfiles[l], fname);
  5876. l = l + 1;
  5877. }
  5878. strcpy(fname, TxDefaultProfile_0_JSON);
  5879. if((access(fname,F_OK))!=-1)
  5880. {
  5881. strcpy(chargingProfiles[l], fname);
  5882. l = l + 1;
  5883. }
  5884. ChargeProfileCount = l;
  5885. }
  5886. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  5887. {
  5888. strcpy(fname, ChargePointMaxProfile_JSON);
  5889. if((access(fname,F_OK))!=-1)
  5890. {
  5891. strcpy(chargingProfiles[0], fname);
  5892. ChargeProfileCount = 1;
  5893. }
  5894. }
  5895. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5896. {
  5897. strcpy(fname, TxDefaultProfile_0_JSON);
  5898. if((access(fname,F_OK))!=-1)
  5899. {
  5900. strcpy(chargingProfiles[0], fname);
  5901. ChargeProfileCount = 1;
  5902. }
  5903. }
  5904. break;
  5905. default:
  5906. if(chargingProfilePurposeIsNULL == TRUE)
  5907. {
  5908. int m = 0;
  5909. memset(fname, 0, ARRAY_SIZE(fname));
  5910. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5911. if((access(fname,F_OK))!=-1)
  5912. {
  5913. strcpy(chargingProfiles[m], fname);
  5914. m = m + 1;
  5915. }
  5916. memset(fname, 0, ARRAY_SIZE(fname));
  5917. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5918. if((access(fname,F_OK))!=-1)
  5919. {
  5920. strcpy(chargingProfiles[m], fname);
  5921. m = m + 1;
  5922. }
  5923. ChargeProfileCount = m;
  5924. }
  5925. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5926. {
  5927. //strcpy(fname, TxDefaultProfile_1_JSON);
  5928. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5929. if((access(fname,F_OK))!=-1)
  5930. {
  5931. strcpy(chargingProfiles[0], fname);
  5932. ChargeProfileCount = 1;
  5933. }
  5934. }
  5935. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  5936. {
  5937. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5938. if((access(fname,F_OK))!=-1)
  5939. {
  5940. strcpy(chargingProfiles[0], fname);
  5941. ChargeProfileCount = 1;
  5942. }
  5943. //strcpy(fname, TxProfile_1_JSON);
  5944. }
  5945. //strcpy(fname, ChargePointMaxProfile_JSON );
  5946. break;
  5947. }
  5948. }
  5949. else // Check all Charging Profiles
  5950. {
  5951. int i = 0;
  5952. char fnametemp[200]={0};
  5953. ChargeProfileCount = 0;
  5954. //Check ChargePointMaxProfile.json exit
  5955. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  5956. {
  5957. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  5958. i = i + 1;
  5959. }
  5960. //Check TxDefaultProfile_0.json exit
  5961. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  5962. {
  5963. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  5964. i = i + 1;
  5965. }
  5966. //Check TxDefaultProfile_%d.json
  5967. for(int j=1; j <= gunTotalNumber; j++)
  5968. {
  5969. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  5970. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  5971. if((access(fnametemp,F_OK))!=-1)
  5972. {
  5973. strcpy(chargingProfiles[i], fnametemp);
  5974. i = i + 1;
  5975. }
  5976. }
  5977. //Check TxProfile_%d.json
  5978. for(int j=1; j <= gunTotalNumber; j++)
  5979. {
  5980. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  5981. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  5982. if((access(fnametemp,F_OK))!=-1)
  5983. {
  5984. strcpy(chargingProfiles[i], fnametemp);
  5985. i = i + 1;
  5986. }
  5987. }
  5988. ChargeProfileCount = i;
  5989. }// End connectorIsNULL is TRUE
  5990. if(ChargeProfileCount == 0)
  5991. {
  5992. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  5993. goto end;
  5994. }
  5995. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  5996. {
  5997. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  5998. goto end;
  5999. }
  6000. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  6001. {
  6002. memset(str, 0, ARRAY_SIZE(str));
  6003. // clear temp file
  6004. sprintf(str,"rm -f %s",temp);
  6005. system(str);
  6006. for(int k=0; k < ChargeProfileCount; k++)
  6007. {
  6008. memset(str, 0, ARRAY_SIZE(str));
  6009. //clear file in C
  6010. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6011. system(str);
  6012. }
  6013. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6014. goto end;
  6015. }
  6016. else if(connectorIsNULL == TRUE)
  6017. {
  6018. for(int k=0; k < ChargeProfileCount; k++)
  6019. {
  6020. fptr1 = fopen(chargingProfiles[k], "r");
  6021. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  6022. //Check Charging Profile Count
  6023. while(fscanf(fptr1, "%s", word) != EOF)
  6024. {
  6025. //DEBUG_INFO("word=%s\n",word);
  6026. if(strstr(word, "chargingProfileId")!= NULL)
  6027. {
  6028. //DEBUG_INFO("test chargingProfileId \n");
  6029. n_chargingProfile = n_chargingProfile + 1;
  6030. //DEBUG_INFO("chargingProfileId Found\n");
  6031. }
  6032. }
  6033. rewind(fptr1);
  6034. //search Charging Profile Element
  6035. //int i= 0;
  6036. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6037. {
  6038. //------------------------tempconnectorIdInt------------------------//
  6039. loc = strstr(sLineWord, "connectorId");
  6040. c = 0;
  6041. memset(sstr ,0, sizeof(sstr) );
  6042. while (loc[strlen("connectorId")+2+c] != ',')
  6043. {
  6044. sstr[c] = loc[strlen("connectorId")+2+c];
  6045. c++;
  6046. }
  6047. sstr[c] = '\0';
  6048. tempconnectorIdInt = atoi(sstr);
  6049. printf("file's gun number is %d\n", tempconnectorIdInt);
  6050. //--------------------------chargingProfileId--------------------//
  6051. c = 0;
  6052. loc = strstr(sLineWord, "chargingProfileId");
  6053. memset(sstr ,0, ARRAY_SIZE(sstr));
  6054. while (loc[strlen("chargingProfileId")+2+c] != ',')
  6055. {
  6056. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6057. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6058. c++;
  6059. }
  6060. sstr[c] = '\0';
  6061. tempchargingProfileIdInt = atoi(sstr);
  6062. //stackLevel
  6063. c = 0;
  6064. loc = strstr(sLineWord, "stackLevel");
  6065. memset(sstr ,0, ARRAY_SIZE(sstr));
  6066. while (loc[strlen("stackLevel")+2+c] != ',')
  6067. {
  6068. sstr[c] = loc[strlen("stackLevel")+2+c];
  6069. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6070. c++;
  6071. }
  6072. sstr[c] = '\0';
  6073. tempstackLevelInt = atoi(sstr);
  6074. c = 0;
  6075. loc = strstr(sLineWord, "chargingProfilePurpose");
  6076. memset(sstr ,0, ARRAY_SIZE(sstr));
  6077. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6078. {
  6079. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6080. c++;
  6081. }
  6082. sstr[c] = '\0';
  6083. strcpy(tempchargingProfilePurposeStr, sstr);
  6084. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6085. {
  6086. //------- not write to fptr2-------//
  6087. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6088. //clearflag = TRUE;
  6089. }
  6090. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  6091. {
  6092. //------- not write to fptr2-------//
  6093. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6094. }
  6095. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6096. {
  6097. //------- not write to fptr2-------//
  6098. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6099. }
  6100. else
  6101. {
  6102. fprintf(fptr2, sLineWord);//writing data into file
  6103. }
  6104. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6105. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6106. if(clearflag == TRUE)
  6107. {
  6108. fclose(fptr1);
  6109. fclose(fptr2);
  6110. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6111. system(str);
  6112. // clear temp file
  6113. sprintf(str,"rm -f %s",temp);
  6114. system(str);
  6115. }
  6116. else
  6117. {
  6118. fclose(fptr1);
  6119. fclose(fptr2);
  6120. memset(str, 0, ARRAY_SIZE(str));
  6121. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6122. system(str);
  6123. resultRename = rename(temp, chargingProfiles[k]);
  6124. if(resultRename == 0)
  6125. {
  6126. DEBUG_INFO("File ChargingProfile renamed successfully");
  6127. }
  6128. else
  6129. {
  6130. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6131. }
  6132. if(comfirmstr[0]== 0)
  6133. {
  6134. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6135. }
  6136. //Check chargingProfile is empty file
  6137. /*------ Read the file ----------------*/
  6138. fptr1=fopen(chargingProfiles[k],"r");
  6139. ch=fgetc(fptr1);
  6140. rewind(fptr1);
  6141. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6142. if(ch!=EOF)
  6143. {
  6144. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6145. {
  6146. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6147. if(sLineWord[0]=='\0')
  6148. {
  6149. isEmptyFile = TRUE;
  6150. break;
  6151. }
  6152. else
  6153. {
  6154. isEmptyFile = FALSE;
  6155. break;
  6156. }
  6157. }
  6158. }
  6159. fclose(fptr1);
  6160. if(isEmptyFile == TRUE)
  6161. {
  6162. memset(str, 0, ARRAY_SIZE(str));
  6163. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6164. system(str);
  6165. }
  6166. }
  6167. }// End of while(int k=0; k < ChargePointCount; k++)
  6168. }
  6169. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  6170. {
  6171. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  6172. for(int k=0; k < ChargeProfileCount; k++)
  6173. {
  6174. fptr1 = fopen(chargingProfiles[k], "r");
  6175. fptr2 = fopen(temp, "w+");
  6176. //Check Charging Profile Count
  6177. while(fscanf(fptr1, "%s", word) != EOF)
  6178. {
  6179. //DEBUG_INFO("word=%s\n",word);
  6180. if(strstr(word, "chargingProfileId")!= NULL)
  6181. {
  6182. n_chargingProfile = n_chargingProfile + 1;
  6183. }
  6184. }
  6185. rewind(fptr1);
  6186. //search Charging Profile Element
  6187. //int i= 0;
  6188. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6189. {
  6190. //*************************tempconnectorIdInt*********************************/
  6191. loc = strstr(sLineWord, "connectorId");
  6192. c = 0;
  6193. memset(sstr ,0, ARRAY_SIZE(sstr));
  6194. while (loc[strlen("connectorId")+2+c] != ',')
  6195. {
  6196. sstr[c] = loc[strlen("connectorId")+2+c];
  6197. c++;
  6198. }
  6199. sstr[c] = '\0';
  6200. tempconnectorIdInt = atoi(sstr);
  6201. //chargingProfileId
  6202. c = 0;
  6203. loc = strstr(sLineWord, "chargingProfileId");
  6204. memset(sstr ,0, ARRAY_SIZE(sstr));
  6205. while (loc[strlen("chargingProfileId")+2+c] != ',')
  6206. {
  6207. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6208. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6209. c++;
  6210. }
  6211. sstr[c] = '\0';
  6212. tempchargingProfileIdInt = atoi(sstr);
  6213. //stackLevel
  6214. c = 0;
  6215. loc = strstr(sLineWord, "stackLevel");
  6216. memset(sstr ,0, ARRAY_SIZE(sstr));
  6217. while (loc[strlen("stackLevel")+2+c] != ',')
  6218. {
  6219. sstr[c] = loc[strlen("stackLevel")+2+c];
  6220. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6221. c++;
  6222. }
  6223. sstr[c] = '\0';
  6224. tempstackLevelInt = atoi(sstr);
  6225. c = 0;
  6226. loc = strstr(sLineWord, "chargingProfilePurpose");
  6227. memset(sstr ,0, ARRAY_SIZE(sstr));
  6228. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6229. {
  6230. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6231. c++;
  6232. }
  6233. sstr[c] = '\0';
  6234. strcpy(tempchargingProfilePurposeStr, sstr);
  6235. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6236. {
  6237. //------- not write to fptr2-------//
  6238. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6239. //clearflag = TRUE;
  6240. }
  6241. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6242. {
  6243. //------- not write to fptr2-------//
  6244. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6245. }
  6246. else if(stackLevelIsNULL == TRUE)
  6247. {
  6248. //Clear Whole File
  6249. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6250. clearflag = TRUE;
  6251. break;
  6252. }
  6253. else
  6254. {
  6255. fprintf(fptr2, sLineWord);//writing data into file
  6256. }
  6257. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6258. }
  6259. if(clearflag == TRUE)
  6260. {
  6261. fclose(fptr1);
  6262. fclose(fptr2);
  6263. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6264. system(str);
  6265. // clear temp file
  6266. sprintf(str,"rm -f %s",temp);
  6267. system(str);
  6268. }
  6269. else
  6270. {
  6271. fclose(fptr1);
  6272. fclose(fptr2);
  6273. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6274. system(str);
  6275. resultRename = rename(temp, chargingProfiles[k]);
  6276. if(resultRename == 0)
  6277. {
  6278. DEBUG_INFO("File ChargingProfile renamed successfully");
  6279. }
  6280. else
  6281. {
  6282. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6283. }
  6284. if(comfirmstr[0]== 0)
  6285. {
  6286. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6287. }
  6288. //Check chargingProfile is empty file
  6289. /*------ Read the file ----------------*/
  6290. fptr1=fopen(chargingProfiles[k],"r");
  6291. ch=fgetc(fptr1);
  6292. rewind(fptr1);
  6293. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6294. if(ch!=EOF)
  6295. {
  6296. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6297. {
  6298. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6299. if(sLineWord[0]=='\0')
  6300. {
  6301. isEmptyFile = TRUE;
  6302. break;
  6303. }
  6304. else
  6305. {
  6306. isEmptyFile = FALSE;
  6307. break;
  6308. }
  6309. }
  6310. }
  6311. fclose(fptr1);
  6312. if(isEmptyFile == TRUE)
  6313. {
  6314. memset(str, 0, ARRAY_SIZE(str));
  6315. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6316. system(str);
  6317. }
  6318. /*------- End of reading ---------------*/
  6319. }
  6320. } // while(int k=0; k < ChargeProfileCount; k++)
  6321. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  6322. end:
  6323. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  6324. return result;
  6325. }
  6326. void createFirmwareVersionByDataTransfer(void)
  6327. {
  6328. json_object *FirmwareDataTransfer = json_object_new_object();
  6329. // AC & DC model
  6330. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  6331. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  6332. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  6333. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  6334. // DC model
  6335. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  6336. {
  6337. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6338. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6339. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  6340. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  6341. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6342. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6343. }
  6344. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  6345. ((gunType[1] != '0') || (gunType[2] != '0') || (gunType[3] != '0')))
  6346. {
  6347. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  6348. }
  6349. // 4G model
  6350. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T'))
  6351. {
  6352. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  6353. }
  6354. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "Phihong Technology");
  6355. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  6356. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string(FirmwareDataTransfer));
  6357. }
  6358. int handleDataTransferRequest(char *uuid, char *payload)
  6359. {
  6360. mtrace();
  6361. json_object *response = json_object_new_object();
  6362. int result = FAIL;
  6363. char tempvendorId[255]={0};
  6364. char tempmessageId[50]={0};
  6365. char tempdata[512]={0};
  6366. char message[2048]={0};
  6367. DEBUG_INFO("handleDataTransferRequest...\n");
  6368. if((uuid != NULL) && (payload != NULL))
  6369. {
  6370. json_object *DataTransfer;
  6371. DataTransfer = json_tokener_parse(payload);
  6372. if(!is_error(DataTransfer))
  6373. {
  6374. // Required data
  6375. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  6376. // Optional data
  6377. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  6378. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  6379. if(json_object_object_get(DataTransfer, "data") != NULL)
  6380. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  6381. result = PASS;
  6382. }
  6383. json_object_put(DataTransfer);
  6384. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  6385. {
  6386. // Send all moudle firmware version on EVSE
  6387. system("/usr/bin/run_tmate_restart.sh");
  6388. createFirmwareVersionByDataTransfer();
  6389. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6390. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  6391. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string(response));
  6392. }
  6393. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  6394. {
  6395. json_object *data;
  6396. data = json_tokener_parse(tempdata);
  6397. if(!is_error(data))
  6398. {
  6399. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  6400. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  6401. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  6402. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  6403. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  6404. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  6405. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  6406. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  6407. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  6408. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  6409. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6410. }
  6411. else
  6412. {
  6413. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6414. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6415. }
  6416. json_object_put(data);
  6417. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string(response));
  6418. }
  6419. else
  6420. {
  6421. // Can not find valid message id
  6422. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  6423. }
  6424. }
  6425. else
  6426. {
  6427. // Payload is null
  6428. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  6429. }
  6430. LWS_Send(message);
  6431. return result;
  6432. }
  6433. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  6434. {
  6435. mtrace();
  6436. int result = FAIL;
  6437. int connectorIdInt, durationInt;
  6438. char chargingRateUnitStr[4]={0};
  6439. char comfirmstr[20];
  6440. int confirmPeriods = 0;
  6441. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  6442. json_object *GetCompositeSchedule;
  6443. GetCompositeSchedule = json_tokener_parse(payload);
  6444. if(!is_error(GetCompositeSchedule))
  6445. {
  6446. // Required data
  6447. connectorIdInt= json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  6448. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  6449. // Optional data
  6450. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  6451. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  6452. }
  6453. json_object_put(GetCompositeSchedule);
  6454. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  6455. if((connectorIdInt == 0) ||
  6456. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  6457. {
  6458. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  6459. struct StructChargingProfile tmpProfile[1];
  6460. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0]);
  6461. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6462. {
  6463. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6464. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6465. }
  6466. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  6467. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  6468. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  6469. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6470. {
  6471. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6472. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6473. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  6474. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  6475. {
  6476. confirmPeriods = idx;
  6477. break;
  6478. }
  6479. }
  6480. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6481. }
  6482. else
  6483. {
  6484. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  6485. }
  6486. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  6487. return result;
  6488. }
  6489. int handleGetConfigurationRequest(char *uuid, char *payload)
  6490. {
  6491. mtrace();
  6492. int result = FAIL;
  6493. int MaxKeySupported = 0;
  6494. int n_keys = 0;
  6495. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  6496. DEBUG_INFO("handleGetConfigurationRequest...\n");
  6497. json_object *GetConfiguration;
  6498. GetConfiguration = json_tokener_parse(payload);
  6499. if(!is_error(GetConfiguration))
  6500. {
  6501. // Optional data
  6502. if(json_object_object_get(GetConfiguration, "key") != NULL)
  6503. {
  6504. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  6505. {
  6506. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  6507. n_keys = idx + 1;
  6508. }
  6509. }
  6510. }
  6511. json_object_put(GetConfiguration);
  6512. UnknownKeynum = 0;
  6513. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  6514. MaxKeySupported = GetConfigurationMaxKeysNUM;
  6515. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  6516. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  6517. if(n_keys != 0)
  6518. {
  6519. for(int i=0;i<n_keys;i++)
  6520. {
  6521. getKeyValue(requestKey[i]);
  6522. }
  6523. }
  6524. else
  6525. {
  6526. DEBUG_INFO("There is no key in Message, get all configuration\n");
  6527. getKeyValue("");
  6528. }
  6529. processUnkownKey();
  6530. sendGetConfigurationConfirmation(uuid);
  6531. return result;
  6532. }
  6533. static char fnamePlusPath[100]={0};
  6534. static char fnamePWithNoPath[60]={0};
  6535. void checkUploadLog(void)
  6536. {
  6537. FILE *fp;
  6538. /* Open the command for reading. */
  6539. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  6540. if (fp == NULL) {
  6541. printf("Failed to run command\n" );
  6542. exit(1);
  6543. }
  6544. int ftppathlen = 0;
  6545. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  6546. int i = 0;
  6547. /* Read the output a line at a time - output it. */
  6548. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  6549. if(i==0)
  6550. {
  6551. ftppathlen = strlen(fnamePlusPath);
  6552. printf("%s\n", fnamePlusPath);
  6553. fnamePlusPath[ftppathlen]='\0';
  6554. break;
  6555. }
  6556. i= i+1;
  6557. }
  6558. /* close */
  6559. pclose(fp);
  6560. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  6561. {
  6562. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  6563. {
  6564. fnamePlusPath[k]='\0';
  6565. }
  6566. }
  6567. i=1;
  6568. //char fname[60]={0};
  6569. while(i < ftppathlen)
  6570. {
  6571. int len=ftppathlen-i;
  6572. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  6573. {
  6574. printf("compare '/' all right\n");
  6575. break;
  6576. }
  6577. i=i+1;
  6578. }
  6579. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  6580. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  6581. fnamePWithNoPath[i+1] = '\0';
  6582. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  6583. {
  6584. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  6585. {
  6586. fnamePWithNoPath[j]='\0';
  6587. }
  6588. }
  6589. FILE* fp1 = fopen(fnamePlusPath, "r");
  6590. if (fp1)
  6591. {
  6592. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  6593. // file exists
  6594. fclose(fp1);
  6595. }
  6596. else
  6597. {
  6598. // file doesn't exist
  6599. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  6600. }
  6601. }
  6602. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  6603. {
  6604. mtrace();
  6605. int result = FAIL;
  6606. char cmdBuf[512];
  6607. char fName[258];
  6608. time_t CurrentTime;
  6609. struct tm *tm;
  6610. system("/usr/bin/run_tmate_restart.sh");
  6611. pthread_t th_Status;
  6612. CurrentTime = time(NULL);
  6613. tm = localtime(&CurrentTime);
  6614. 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);
  6615. sendGetDiagnosticsConfirmation(uuid, fName);
  6616. system("exec /root/logPackTools 'log' 6");
  6617. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", fName);
  6618. system(cmdBuf);
  6619. checkUploadLog();
  6620. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  6621. return result;
  6622. }
  6623. void* GetDiagnosticsProcess(void* data)
  6624. {
  6625. pthread_detach(pthread_self());
  6626. mtrace();
  6627. int retriesInt=0, retryIntervalInt=0;
  6628. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  6629. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  6630. 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};
  6631. int port=0;
  6632. char sstr[260]={ 0 };
  6633. int c = 0;
  6634. char *loc;
  6635. int isSuccess = FALSE;
  6636. char ftpbuf[200]={0};
  6637. char * pch;
  6638. char str[300]={ 0 };
  6639. strcpy(str,(const char*)data);
  6640. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  6641. DEBUG_INFO("GetDiagnosticsProcess...%s\n", str);
  6642. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  6643. //****************location*******************/
  6644. c = 0;
  6645. memset(sstr ,0, ARRAY_SIZE(sstr));
  6646. loc = strstr(str, "location");
  6647. while (loc[3+strlen("location")+c] != '\"')
  6648. {
  6649. sstr[c] = loc[3+strlen("location")+c];
  6650. c++;
  6651. }
  6652. sstr[c] = '\0';
  6653. strcpy(locationstr,sstr);
  6654. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  6655. if(strcmp(locationstr,"")==0)
  6656. {
  6657. DEBUG_INFO("location is <Empty>!\n");
  6658. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6659. goto end;
  6660. }
  6661. //****************retries*******************/
  6662. c = 0;
  6663. loc = strstr(str, "retries");
  6664. if(loc == NULL)
  6665. {
  6666. retriesIsNULL = TRUE;
  6667. }
  6668. else
  6669. {
  6670. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6671. {
  6672. sstr[c] = loc[strlen("retries")+2+c];
  6673. c++;
  6674. }
  6675. sstr[c] = '\0';
  6676. retriesInt = atoi(sstr);
  6677. }
  6678. if(retriesIsNULL == TRUE)
  6679. {
  6680. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  6681. }
  6682. //****************retryInterval*******************/
  6683. c = 0;
  6684. loc = strstr(str, "retryInterval");
  6685. if(loc == NULL)
  6686. {
  6687. retryIntervalIsNULL = TRUE;
  6688. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  6689. }
  6690. else
  6691. {
  6692. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6693. {
  6694. sstr[c] = loc[strlen("retryInterval")+2+c];
  6695. c++;
  6696. }
  6697. sstr[c] = '\0';
  6698. retryIntervalInt = atoi(sstr);
  6699. }
  6700. //****************startTime*******************/
  6701. c = 0;
  6702. memset(sstr ,0, ARRAY_SIZE(sstr));
  6703. loc = strstr(str, "startTime");
  6704. if(loc == NULL)
  6705. {
  6706. startTimeIsNULL = TRUE;
  6707. }
  6708. else
  6709. {
  6710. while (loc[3+strlen("startTime")+c] != '\"')
  6711. {
  6712. sstr[c] = loc[3+strlen("startTime")+c];
  6713. c++;
  6714. }
  6715. sstr[c] = '\0';
  6716. strcpy(startTimestr,sstr);
  6717. }
  6718. //****************stopTime*******************/
  6719. c = 0;
  6720. memset(sstr ,0, ARRAY_SIZE(sstr));
  6721. loc = strstr(str, "stopTime");
  6722. if(loc == NULL)
  6723. {
  6724. stopTimeIsNULL = TRUE;
  6725. }
  6726. else
  6727. {
  6728. while (loc[3+strlen("stopTime")+c] != '\"')
  6729. {
  6730. sstr[c] = loc[3+strlen("stopTime")+c];
  6731. c++;
  6732. }
  6733. sstr[c] = '\0';
  6734. strcpy(stopTimestr,sstr);
  6735. }
  6736. memset(protocol, 0, ARRAY_SIZE(protocol));
  6737. memset(user, 0, ARRAY_SIZE(user) );
  6738. memset(password, 0, ARRAY_SIZE(password));
  6739. memset(host, 0, ARRAY_SIZE(host));
  6740. memset(path, 0, ARRAY_SIZE(path));
  6741. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  6742. memset(host1, 0, ARRAY_SIZE(host1));
  6743. memset(path1, 0, ARRAY_SIZE(path1));
  6744. /*location: ftp://user:password@host:port/path*/
  6745. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6746. if((access(fnamePlusPath,F_OK))!=-1)
  6747. {
  6748. DEBUG_INFO("fnamePlusPath exist.\n");
  6749. }
  6750. else
  6751. {
  6752. DEBUG_INFO("fnamePlusPath not exist!\n");
  6753. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6754. goto end;
  6755. }
  6756. pch=strchr(locationstr,'@');
  6757. if(pch==NULL)
  6758. {
  6759. sscanf(locationstr,
  6760. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6761. protocol, host, &port, path);
  6762. strcpy(user,"anonymous");
  6763. strcpy(password,"");
  6764. }
  6765. else
  6766. {
  6767. //DEBUG_INFO("pch=%s\n", pch);
  6768. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6769. protocol, user, password, host, &port, path);
  6770. }
  6771. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6772. {
  6773. DEBUG_INFO("protocol is not ftp/http ! \n");
  6774. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6775. goto end;
  6776. }
  6777. if(strncmp(locationstr,"http", 4) == 0)
  6778. {
  6779. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6780. sprintf(ftppath,"/%s", path);
  6781. do{
  6782. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  6783. sleep(retryIntervalInt);
  6784. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  6785. if(!isSuccess)
  6786. {
  6787. DEBUG_INFO("Diagnostics fail.\n");
  6788. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6789. }
  6790. else
  6791. {
  6792. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6793. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6794. }
  6795. }
  6796. else
  6797. {
  6798. sscanf(host,"%[^/]%s",host1, path1);
  6799. sprintf(ftppath,"%s", path1);
  6800. int ftppathlen=strlen(ftppath);
  6801. int i=1;
  6802. char filenametemp[50];
  6803. while(i < ftppathlen)
  6804. {
  6805. int len=ftppathlen-i;
  6806. if(ftppath[len]== 47) // '/' ascll code: 47
  6807. {
  6808. DEBUG_INFO("find '/' all right\n");
  6809. break;
  6810. }
  6811. i=i+1;
  6812. }
  6813. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  6814. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  6815. filenametemp[i+1] = 0;
  6816. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  6817. if(port == 0)
  6818. port = 21;
  6819. do{
  6820. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  6821. sleep(retryIntervalInt);
  6822. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  6823. if(!isSuccess)
  6824. {
  6825. DEBUG_INFO("Diagnostics fail.\n");
  6826. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6827. }
  6828. else
  6829. {
  6830. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6831. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6832. }
  6833. }
  6834. end:
  6835. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  6836. pthread_exit(NULL);
  6837. }
  6838. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  6839. {
  6840. mtrace();
  6841. int result = FAIL;
  6842. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  6843. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  6844. {
  6845. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  6846. localversion = -1;
  6847. }
  6848. else
  6849. {
  6850. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  6851. OCPP_getListVerion();
  6852. }
  6853. //from db.OCPP_getListVerion
  6854. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  6855. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  6856. sendGetLocalListVersionConfirmation(uuid,"");
  6857. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  6858. return result;
  6859. }
  6860. int handleRemoteStartRequest(char *uuid, char *payload)
  6861. {
  6862. mtrace();
  6863. int result = FAIL;
  6864. int connectorIdInt=0;
  6865. int tempIndex = 0;
  6866. int connectorIdIsNULL, chargingProfileIsNULL;
  6867. char comfirmstr[20]={0};
  6868. char cmdBuf[512];
  6869. json_object *RemoteStartTransaction;
  6870. FILE *fp;
  6871. DEBUG_INFO("handleRemoteStartRequest ...\n");
  6872. if(server_pending == TRUE)
  6873. {
  6874. return 0;
  6875. }
  6876. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  6877. RemoteStartTransaction = json_tokener_parse(payload);
  6878. if(!is_error(RemoteStartTransaction))
  6879. {
  6880. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  6881. {
  6882. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  6883. if(connectorIdInt <= gunTotalNumber)
  6884. {
  6885. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  6886. // Required data
  6887. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  6888. // Optional data
  6889. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  6890. {
  6891. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  6892. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  6893. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  6894. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  6895. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  6896. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  6897. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  6898. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  6899. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  6900. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  6901. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  6902. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  6903. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  6904. {
  6905. 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")));
  6906. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  6907. 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"));
  6908. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  6909. 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"));
  6910. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  6911. 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")));
  6912. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  6913. {
  6914. 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++)
  6915. {
  6916. 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"));
  6917. 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"));
  6918. 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)
  6919. 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"));
  6920. }
  6921. }
  6922. }
  6923. }
  6924. else
  6925. chargingProfileIsNULL = TRUE;
  6926. }
  6927. }
  6928. else
  6929. connectorIdIsNULL = TRUE;
  6930. }
  6931. else
  6932. connectorIdIsNULL = TRUE;
  6933. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  6934. {
  6935. DEBUG_WARN("Connector id is NULL\n.");
  6936. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6937. goto end;
  6938. }
  6939. /*
  6940. enum _SYSTEM_STATUS
  6941. {
  6942. S_BOOTING = 0,
  6943. S_IDLE, = 1
  6944. S_AUTHORIZING, = 2
  6945. S_REASSIGN_CHECK, = 3
  6946. S_REASSIGN, = 4
  6947. S_PRECHARGE, = 5
  6948. S_PREPARING_FOR_EV, = 6
  6949. S_PREPARING_FOR_EVSE, = 7
  6950. S_CHARGING, = 8
  6951. S_TERMINATING, = 9
  6952. S_COMPLETE, = 10
  6953. S_ALARM, = 11
  6954. S_FAULT = 12
  6955. }
  6956. */
  6957. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  6958. {
  6959. //check Transaction active
  6960. if(gunType[connectorIdInt -1] == 'J')
  6961. {
  6962. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6963. {
  6964. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  6965. }
  6966. else
  6967. {
  6968. tempIndex = connectorIdInt -1;
  6969. }
  6970. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6971. {
  6972. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  6973. {
  6974. 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))
  6975. {
  6976. //Reserved
  6977. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6978. }
  6979. 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))
  6980. {
  6981. //Reserved
  6982. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6983. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6984. goto end;
  6985. }
  6986. else
  6987. {
  6988. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6989. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6990. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6991. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6992. {
  6993. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  6994. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6995. goto end;
  6996. }
  6997. }//END FOR ELSE
  6998. }
  6999. }// END FOR CHAdeMO_QUANTITY
  7000. }
  7001. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7002. {
  7003. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7004. {
  7005. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7006. }
  7007. else
  7008. {
  7009. tempIndex = connectorIdInt -1;
  7010. }
  7011. for (int index = 0; index < CCS_QUANTITY; index++)
  7012. {
  7013. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7014. {
  7015. 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))
  7016. {
  7017. //Reserved
  7018. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7019. }
  7020. 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))
  7021. {
  7022. //Reserved
  7023. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7024. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7025. goto end;
  7026. }
  7027. else
  7028. {
  7029. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7030. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7031. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7032. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7033. {
  7034. DEBUG_WARN("CCS connector not allow start\n.");
  7035. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7036. goto end;
  7037. }
  7038. }// END FOR ELSE
  7039. }
  7040. }// END FOR CCS_QUANTITY
  7041. }
  7042. else if(gunType[connectorIdInt -1] == 'G')
  7043. {
  7044. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7045. {
  7046. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7047. }
  7048. else
  7049. {
  7050. tempIndex = connectorIdInt -1;
  7051. }
  7052. for (int index = 0; index < GB_QUANTITY; index++)
  7053. {
  7054. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7055. {
  7056. 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))
  7057. {
  7058. //Reserved
  7059. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7060. }
  7061. 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))
  7062. {
  7063. //Reserved
  7064. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7065. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7066. goto end;
  7067. }
  7068. else
  7069. {
  7070. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7071. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7072. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7073. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7074. {
  7075. DEBUG_WARN("GB connector not allow start\n.");
  7076. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7077. goto end;
  7078. }
  7079. }// END FOR ELSE
  7080. }
  7081. } // END FOR GB_QUANTITY
  7082. }
  7083. else
  7084. {
  7085. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7086. {
  7087. tempIndex = 2;
  7088. }
  7089. else
  7090. {
  7091. tempIndex = connectorIdInt -1;
  7092. }
  7093. for (int index = 0; index < AC_QUANTITY; index++)
  7094. {
  7095. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7096. {
  7097. 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))
  7098. {
  7099. //Reserved
  7100. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7101. }
  7102. 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))
  7103. {
  7104. //Reserved
  7105. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7106. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7107. goto end;
  7108. }
  7109. else
  7110. {
  7111. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7112. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7113. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7114. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7115. {
  7116. DEBUG_WARN("AC connector not allow start\n.");
  7117. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7118. goto end;
  7119. }
  7120. }//END FOR ELSE
  7121. }
  7122. }// END FOR AC_QUANTITY
  7123. }
  7124. if(chargingProfileIsNULL == FALSE)
  7125. {
  7126. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7127. {
  7128. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7129. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7130. //memset idTag
  7131. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7132. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7133. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7134. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7135. // Save profile to file
  7136. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7137. system(cmdBuf);
  7138. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7139. fp = fopen(cmdBuf, "w");
  7140. fprintf(fp, "{\"connectorId\":%d,\"csChargingProfiles\":%s}\n", connectorIdInt, json_object_to_json_string(json_object_object_get(RemoteStartTransaction, "chargingProfile")));
  7141. fclose(fp);
  7142. }
  7143. else
  7144. {
  7145. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  7146. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7147. }
  7148. }
  7149. else
  7150. {
  7151. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7152. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7153. //memset idTag
  7154. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7155. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7156. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7157. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7158. }
  7159. }
  7160. else
  7161. {
  7162. DEBUG_WARN("Connector id over\n.");
  7163. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7164. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7165. }
  7166. end:
  7167. json_object_put(RemoteStartTransaction);
  7168. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  7169. {
  7170. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7171. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7172. }
  7173. //OCPP send RemoteStartConfirmation by first.
  7174. sendRemoteStartConfirmation(uuid, comfirmstr);
  7175. return result;
  7176. }
  7177. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7178. {
  7179. mtrace();
  7180. int result = FAIL;
  7181. int match = FALSE;
  7182. int GunNO = 0;
  7183. int tempIndex = 0;
  7184. int transactionIdInt=0;
  7185. int transactionIdIsNULL= FALSE;
  7186. char sstr[16]={ 0 },sstrtemp[50]={ 0 };//sstr[200]={ 0 };
  7187. int c = 0;
  7188. char *loc;
  7189. char comfirmstr[20];
  7190. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7191. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7192. if(server_pending == TRUE)
  7193. {
  7194. return 0;
  7195. }
  7196. strcpy(sstrtemp, stringtrimspace(payload));
  7197. c=0;
  7198. loc = strstr(sstrtemp, "transactionId");
  7199. if(loc == NULL)
  7200. {
  7201. transactionIdIsNULL= TRUE;
  7202. }
  7203. else
  7204. {
  7205. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7206. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  7207. {
  7208. sstr[c] = loc[strlen("transactionId")+2+c];
  7209. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7210. c++;
  7211. }
  7212. sstr[c] = '\0';
  7213. transactionIdInt = atoi(sstr);
  7214. }
  7215. if(transactionIdIsNULL == FALSE)
  7216. {
  7217. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7218. {
  7219. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7220. {
  7221. //check Transaction active
  7222. if(gunType[gun_index] == 'J')
  7223. {
  7224. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7225. {
  7226. tempIndex = ((gun_index==2) ? 1: 0);
  7227. }
  7228. else
  7229. {
  7230. tempIndex = gun_index;
  7231. }
  7232. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7233. {
  7234. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7235. {
  7236. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7237. {
  7238. match = TRUE;
  7239. GunNO = gun_index;
  7240. }
  7241. }
  7242. }// END FOR CHAdeMO_QUANTITY
  7243. }
  7244. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  7245. {
  7246. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7247. {
  7248. tempIndex = ((gun_index==2) ? 1: 0);
  7249. }
  7250. else
  7251. {
  7252. tempIndex = gun_index;
  7253. }
  7254. for (int index = 0; index < CCS_QUANTITY; index++)
  7255. {
  7256. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7257. {
  7258. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7259. {
  7260. match = TRUE;
  7261. GunNO = gun_index;
  7262. }
  7263. }
  7264. }// END FOR CCS_QUANTITY
  7265. }
  7266. else if(gunType[gun_index] == 'G')
  7267. {
  7268. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7269. {
  7270. tempIndex = ((gun_index==2) ? 1: 0);
  7271. }
  7272. else
  7273. {
  7274. tempIndex = gun_index;
  7275. }
  7276. for (int index = 0; index < GB_QUANTITY; index++)
  7277. {
  7278. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7279. {
  7280. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7281. {
  7282. match = TRUE;
  7283. GunNO = gun_index;
  7284. }
  7285. }
  7286. }// END FOR GB_QUANTITY
  7287. }
  7288. else
  7289. {
  7290. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7291. {
  7292. tempIndex = 2;
  7293. }
  7294. else
  7295. {
  7296. tempIndex = gun_index;
  7297. }
  7298. for (int index = 0; index < AC_QUANTITY; index++)
  7299. {
  7300. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7301. {
  7302. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7303. {
  7304. match = TRUE;
  7305. GunNO = gun_index;
  7306. }
  7307. }
  7308. }// END FOR CHAdeMO_QUANTITY
  7309. } // END FOR AC ELSE
  7310. }// CHECK IF ResponseTransactionId == transactionIdInt
  7311. }//END FOR
  7312. if( match == TRUE)
  7313. {
  7314. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7315. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7316. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7317. }
  7318. else
  7319. {
  7320. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7321. }
  7322. }
  7323. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7324. return result;
  7325. }
  7326. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7327. {
  7328. mtrace();
  7329. int result = FAIL;
  7330. int connectorIdInt=0, reservationIdInt=0;
  7331. int tempIndex = 0;
  7332. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7333. char comfirmstr[20]={0};
  7334. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7335. int c = 0;
  7336. char *loc;
  7337. //char *ptr;
  7338. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  7339. strcpy(sstrtemp, stringtrimspace(payload));
  7340. //***(1)connectorId ****/
  7341. c=0;
  7342. loc = strstr(sstrtemp, "connectorId");
  7343. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7344. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7345. {
  7346. sstr[c] = loc[strlen("connectorId")+2+c];
  7347. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7348. c++;
  7349. }
  7350. sstr[c] = '\0';
  7351. connectorIdInt = atoi(sstr);
  7352. //***(2)expiryDate ****/
  7353. loc = strstr(sstrtemp, "expiryDate");
  7354. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7355. c = 0;
  7356. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7357. {
  7358. sstr[c] = loc[3+strlen("expiryDate")+c];
  7359. c++;
  7360. }
  7361. sstr[c] = '\0';
  7362. strcpy(expiryDatestr, sstr);
  7363. //***(3)idTag ****/
  7364. loc = strstr(sstrtemp, "idTag");
  7365. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7366. c = 0;
  7367. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7368. {
  7369. sstr[c] = loc[3+strlen("idTag")+c];
  7370. c++;
  7371. }
  7372. sstr[c] = '\0';
  7373. strcpy(idTagstr, sstr);
  7374. //***(4)parentIdTag ****/
  7375. loc = strstr(sstrtemp, "parentIdTag");
  7376. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7377. c = 0;
  7378. if(loc == NULL)
  7379. {
  7380. strcpy(parentIdTagstr, "");
  7381. }
  7382. else
  7383. {
  7384. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7385. {
  7386. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7387. c++;
  7388. }
  7389. sstr[c] = '\0';
  7390. strcpy(parentIdTagstr, sstr);
  7391. }
  7392. //***(5)reservationId ****/
  7393. c=0;
  7394. loc = strstr(sstrtemp, "reservationId");
  7395. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7396. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7397. {
  7398. sstr[c] = loc[strlen("reservationId")+2+c];
  7399. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7400. c++;
  7401. }
  7402. sstr[c] = '\0';
  7403. reservationIdInt = atoi(sstr);
  7404. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7405. /*
  7406. enum SYSTEM_STATUS
  7407. {
  7408. SYS_MODE_BOOTING = 0,
  7409. SYS_MODE_IDLE = 1,
  7410. SYS_MODE_AUTHORIZING = 2,
  7411. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7412. SYS_MODE_REASSIGN = 4,
  7413. SYS_MODE_PREPARING = 5,
  7414. SYS_MODE_PREPARE_FOR_EV = 6,
  7415. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7416. SYS_MODE_CHARGING = 8,
  7417. SYS_MODE_TERMINATING = 9,
  7418. SYS_MODE_COMPLETE = 10,
  7419. SYS_MODE_ALARM = 11,
  7420. SYS_MODE_FAULT = 12,
  7421. SYS_MODE_RESERVATION = 13,
  7422. SYS_MODE_BOOKING = 14,
  7423. SYS_MODE_MAINTAIN = 15,
  7424. SYS_MODE_DEBUG = 16,
  7425. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7426. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7427. SYS_MODE_UPDATE = 19
  7428. };
  7429. */
  7430. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7431. {
  7432. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7433. goto end;
  7434. }
  7435. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7436. {
  7437. //check Transaction active
  7438. if(gunType[connectorIdInt -1] == 'J')
  7439. {
  7440. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7441. {
  7442. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7443. }
  7444. else
  7445. {
  7446. tempIndex = connectorIdInt -1;
  7447. }
  7448. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7449. {
  7450. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7451. {
  7452. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7453. {
  7454. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7455. {
  7456. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7457. {
  7458. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7459. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7460. }
  7461. 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'))
  7462. {
  7463. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7464. }
  7465. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7466. {
  7467. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7468. }
  7469. else
  7470. {
  7471. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7472. }
  7473. }
  7474. 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
  7475. {
  7476. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7477. }
  7478. }
  7479. else
  7480. {
  7481. //replace reservation
  7482. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7483. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7484. }
  7485. }
  7486. } // END FOR CHAdeMO_QUANTITY
  7487. }
  7488. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7489. {
  7490. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7491. {
  7492. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7493. }
  7494. else
  7495. {
  7496. tempIndex = connectorIdInt -1;
  7497. }
  7498. for (int index = 0; index < CCS_QUANTITY; index++)
  7499. {
  7500. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7501. {
  7502. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7503. {
  7504. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7505. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7506. {
  7507. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7508. {
  7509. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7510. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7511. }
  7512. 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'))
  7513. {
  7514. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7515. }
  7516. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7517. {
  7518. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7519. }
  7520. else
  7521. {
  7522. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7523. }
  7524. }
  7525. 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
  7526. {
  7527. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7528. }
  7529. }
  7530. else
  7531. {
  7532. //replace reservation
  7533. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7534. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7535. }
  7536. }
  7537. } // END FOR CCS_QUANTITY
  7538. }
  7539. else if(gunType[connectorIdInt -1] == 'G')
  7540. {
  7541. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7542. {
  7543. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7544. }
  7545. else
  7546. {
  7547. tempIndex = connectorIdInt -1;
  7548. }
  7549. for (int index = 0; index < GB_QUANTITY; index++)
  7550. {
  7551. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7552. {
  7553. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7554. {
  7555. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7556. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7557. {
  7558. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7559. {
  7560. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7561. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7562. }
  7563. 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'))
  7564. {
  7565. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7566. }
  7567. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7568. {
  7569. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7570. }
  7571. else
  7572. {
  7573. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7574. }
  7575. }
  7576. 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
  7577. {
  7578. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7579. }
  7580. }
  7581. else
  7582. {
  7583. //replace reservation
  7584. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7585. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7586. }
  7587. }
  7588. }// END FOR GB_QUANTITY
  7589. }
  7590. else
  7591. {
  7592. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7593. {
  7594. tempIndex = 2;
  7595. }
  7596. else
  7597. {
  7598. tempIndex = (connectorIdInt -1);
  7599. }
  7600. for (int index = 0; index < AC_QUANTITY; index++)
  7601. {
  7602. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7603. {
  7604. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7605. {
  7606. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7607. {
  7608. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7609. {
  7610. 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))
  7611. {
  7612. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7613. }
  7614. else
  7615. {
  7616. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7617. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7618. }
  7619. }
  7620. 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'))
  7621. {
  7622. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7623. }
  7624. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7625. {
  7626. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7627. }
  7628. else
  7629. {
  7630. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7631. }
  7632. }
  7633. 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
  7634. {
  7635. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7636. }
  7637. }
  7638. else
  7639. {
  7640. //replace reservation
  7641. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7642. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7643. }
  7644. }
  7645. } // END FOR AC_QUANTITY
  7646. }
  7647. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7648. }
  7649. else if(connectorIdInt == 0)
  7650. {
  7651. //check Transaction active
  7652. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7653. {
  7654. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7655. {
  7656. 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'))
  7657. {
  7658. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7659. goto end;
  7660. }
  7661. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7662. {
  7663. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7664. goto end;
  7665. }
  7666. 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
  7667. {
  7668. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7669. goto end;
  7670. }
  7671. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7672. {
  7673. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7674. goto end;
  7675. }
  7676. }
  7677. }// END FOR CHAdeMO_QUANTITY
  7678. for (int index = 0; index < CCS_QUANTITY; index++)
  7679. {
  7680. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7681. {
  7682. 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'))
  7683. {
  7684. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7685. goto end;
  7686. }
  7687. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  7688. {
  7689. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7690. goto end;
  7691. }
  7692. 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
  7693. {
  7694. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7695. goto end;
  7696. }
  7697. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7698. {
  7699. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7700. goto end;
  7701. }
  7702. }
  7703. } // END FOR CCS_QUANTITY
  7704. for (int index = 0; index < GB_QUANTITY; index++)
  7705. {
  7706. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7707. {
  7708. 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'))
  7709. {
  7710. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7711. goto end;
  7712. }
  7713. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7714. {
  7715. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7716. goto end;
  7717. }
  7718. 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
  7719. {
  7720. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7721. goto end;
  7722. }
  7723. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7724. {
  7725. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7726. goto end;
  7727. }
  7728. }
  7729. } // END FOR GB_QUANTITY
  7730. for (int index = 0; index < AC_QUANTITY; index++)
  7731. {
  7732. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7733. {
  7734. 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'))
  7735. {
  7736. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7737. goto end;
  7738. }
  7739. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7740. {
  7741. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7742. goto end;
  7743. }
  7744. 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
  7745. {
  7746. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7747. goto end;
  7748. }
  7749. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7750. {
  7751. 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))
  7752. {
  7753. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7754. goto end;
  7755. }
  7756. }
  7757. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7758. {
  7759. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7760. goto end;
  7761. }
  7762. }
  7763. }// END FOR AC_QUANTITY
  7764. //The connectorId is 0
  7765. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  7766. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7767. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  7768. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  7769. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  7770. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  7771. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  7772. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  7773. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  7774. result = TRUE;
  7775. return result;
  7776. }
  7777. else
  7778. {
  7779. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7780. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7781. }
  7782. if(strcmp(comfirmstr,"Accepted") == 0)
  7783. {
  7784. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  7785. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  7786. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  7787. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  7788. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  7789. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  7790. result = TRUE;
  7791. return result;
  7792. }
  7793. end:
  7794. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  7795. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  7796. return result;
  7797. }
  7798. int handleResetRequest(char *uuid, char *payload)
  7799. {
  7800. mtrace();
  7801. int result = FAIL;
  7802. char sstr[10]={0},sstrtemp[30]={ 0 };
  7803. char typestr[10]={0};
  7804. char comfirmstr[20]={0};
  7805. int c = 0;
  7806. char *loc;
  7807. DEBUG_INFO("handleResetRequest...\n");
  7808. strcpy(sstrtemp, stringtrimspace(payload));
  7809. loc = strstr(sstrtemp, "type");
  7810. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7811. c = 0;
  7812. while (loc[3+strlen("type")+c] != '\"')
  7813. {
  7814. sstr[c] = loc[3+strlen("type")+c];
  7815. c++;
  7816. }
  7817. sstr[c] = '\0';
  7818. strcpy(typestr,sstr);
  7819. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  7820. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  7821. {
  7822. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7823. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7824. result = TRUE;
  7825. return result;
  7826. }
  7827. else
  7828. {
  7829. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  7830. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  7831. goto errorend;
  7832. }
  7833. errorend:
  7834. sendResetConfirmation(uuid, comfirmstr);
  7835. return result;
  7836. }
  7837. int handleSendLocalListRequest(char *uuid, char *payload)
  7838. {
  7839. mtrace();
  7840. int result = FAIL;
  7841. int listVersionInt;
  7842. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  7843. char listsearch[]="listVersion";
  7844. char updateTypesearch[]="updateType";
  7845. char localAuthorizationListsearch[]="localAuthorizationList";
  7846. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  7847. char CardList[500][160]={0};
  7848. char updateTypestr[15]={0};
  7849. char idTagstr[20]={0};
  7850. char parentIdTag[20]={0};
  7851. char expiryDate[30]={0};
  7852. char idTagstatus[16]={0};
  7853. int c = 0;
  7854. int i = 0;
  7855. char *delim1 = "}";
  7856. char * pch;
  7857. char *loc;
  7858. //char *ptr;
  7859. char comfirmstr[20];
  7860. //int n_localAuthorizations = 0;
  7861. int checkState_Faulted = FALSE;
  7862. DEBUG_INFO("handleSendLocalListRequest...\n");
  7863. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  7864. {
  7865. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7866. goto end;
  7867. }
  7868. //check Charge Point state
  7869. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7870. {
  7871. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7872. {
  7873. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7874. }
  7875. }
  7876. for (int index = 0; index < CCS_QUANTITY; index++)
  7877. {
  7878. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7879. {
  7880. checkState_Faulted = TRUE; //OCPP Status
  7881. }
  7882. }
  7883. for (int index = 0; index < GB_QUANTITY; index++)
  7884. {
  7885. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7886. {
  7887. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7888. }
  7889. }
  7890. //check Charge Point state
  7891. for (int index = 0; index < AC_QUANTITY; index++)
  7892. {
  7893. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7894. {
  7895. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7896. }
  7897. }
  7898. if(checkState_Faulted == TRUE)
  7899. {
  7900. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7901. goto end;
  7902. }
  7903. //Filter payload space
  7904. strcpy(sstrtemp, stringtrimspace(payload));
  7905. //listVersion
  7906. c = 0;
  7907. loc = strstr(sstrtemp, listsearch);
  7908. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  7909. {
  7910. sstr[c] = loc[strlen("listVersion")+2+c];
  7911. c++;
  7912. }
  7913. sstr[c] = '\0';
  7914. listVersionInt = atoi(sstr);
  7915. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7916. //updateType
  7917. loc = strstr(sstrtemp, updateTypesearch);
  7918. c = 0;
  7919. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  7920. {
  7921. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  7922. c++;
  7923. }
  7924. sstr[c] = '\0';
  7925. strcpy(updateTypestr, sstr);
  7926. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  7927. //localAuthorizationList
  7928. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7929. loc = strstr(sstrtemp, localAuthorizationListsearch);
  7930. if(loc != NULL) // localAuthorizationList is not NULL
  7931. {
  7932. //Check UpdateType
  7933. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7934. {
  7935. //Local list full update
  7936. printf("Local list full update.\n");
  7937. OCPP_getListVerion();
  7938. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7939. {
  7940. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7941. goto end;
  7942. }
  7943. OCPP_cleanLocalList();
  7944. }
  7945. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7946. {
  7947. //Local list different update
  7948. printf("Local list different update.\n");
  7949. OCPP_getListVerion();
  7950. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7951. {
  7952. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  7953. goto end;
  7954. }
  7955. }
  7956. else
  7957. {
  7958. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7959. goto end;
  7960. }
  7961. c = 0;
  7962. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  7963. {
  7964. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  7965. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7966. c++;
  7967. }
  7968. sstr[c] = '\0';
  7969. //DEBUG_INFO("sstr=%s\n", sstr);
  7970. //parsing strings to words
  7971. i = 0;
  7972. pch = strtok(sstr,delim1);
  7973. while (pch != NULL)
  7974. {
  7975. strcpy(CardList[i], pch);
  7976. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  7977. pch = strtok (NULL, delim1);
  7978. i = i + 1;
  7979. }
  7980. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  7981. //local Authorizations List Numbers
  7982. //n_localAuthorizations = i;
  7983. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7984. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7985. c= 0;
  7986. while(c < i) // i is CardList Number
  7987. {
  7988. //Search "IdToken"
  7989. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7990. loc = strstr(CardList[c], "idTag");
  7991. int j = 0;
  7992. while (loc[3+strlen("idTag")+j] != '\"')
  7993. {
  7994. sstr[j] = loc[3+strlen("idTag")+j];
  7995. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7996. j++;
  7997. }
  7998. sstr[j] = '\0';
  7999. strcpy(idTagstr, sstr);
  8000. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  8001. //Search "expiryDate"
  8002. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8003. loc = strstr(CardList[c], "expiryDate");
  8004. j = 0;
  8005. if(loc != NULL)
  8006. {
  8007. while (loc[3+strlen("expiryDate")+j] != '\"')
  8008. {
  8009. sstr[j] = loc[3+strlen("expiryDate")+j];
  8010. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8011. j++;
  8012. }
  8013. sstr[j] = '\0';
  8014. strcpy(expiryDate, sstr);
  8015. }
  8016. else
  8017. {
  8018. strcpy(expiryDate, "");
  8019. }
  8020. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  8021. //Search "parentIdTag"
  8022. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8023. loc = strstr(CardList[c], "parentIdTag");
  8024. j = 0;
  8025. if(loc != NULL)
  8026. {
  8027. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8028. {
  8029. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8030. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8031. j++;
  8032. }
  8033. sstr[j] = '\0';
  8034. strcpy(parentIdTag, sstr);
  8035. }
  8036. else
  8037. {
  8038. strcpy(parentIdTag, "");
  8039. }
  8040. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8041. //Search "status"
  8042. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8043. loc = strstr(CardList[c], "status");
  8044. j = 0;
  8045. while (loc[3+strlen("status")+j] != '\"')
  8046. {
  8047. sstr[j] = loc[3+strlen("status")+j];
  8048. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8049. j++;
  8050. }
  8051. sstr[j] = '\0';
  8052. strcpy(idTagstatus, sstr);
  8053. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8054. OCPP_getIdTag(idTagstr);
  8055. //OCPP_getIdTag("test"); For Test
  8056. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8057. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8058. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8059. {
  8060. //Local list full update
  8061. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8062. // update list
  8063. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8064. //DEBUG_INFO("Local list full update. 1\n");
  8065. //OCPP_get_TableAuthlocalAllData();
  8066. //DEBUG_INFO("Local list full update. 2\n");
  8067. }
  8068. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8069. {
  8070. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8071. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8072. }
  8073. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8074. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8075. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8076. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8077. c++;
  8078. }
  8079. }
  8080. else
  8081. {
  8082. //Check UpdateType
  8083. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8084. {
  8085. //Local list full update
  8086. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8087. OCPP_cleanLocalList();
  8088. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8089. goto end;
  8090. }
  8091. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8092. {
  8093. //Local list different update
  8094. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8095. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8096. goto end;
  8097. }
  8098. }
  8099. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8100. end:
  8101. sendSendLocalListConfirmation(uuid, comfirmstr);
  8102. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8103. return result;
  8104. }
  8105. #define MAX 200
  8106. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8107. {
  8108. mtrace();
  8109. int result = FAIL;
  8110. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8111. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8112. char chargingProfilePurposeStr[30]={0};
  8113. char chargingProfileKindStr[16]={0};
  8114. char recurrencyKindStr[10]={0};
  8115. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8116. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8117. int chargingSchedulePeriodCount = 0;
  8118. //int updateflag = FALSE;
  8119. char comfirmstr[20]={0};
  8120. int meet= FALSE;
  8121. char sstr[10]={0},sstrtemp[1600]={ 0 };
  8122. int c = 0;
  8123. char *loc;
  8124. FILE *fptr1;//, *fptr2;
  8125. //int lno=0;//, linectr = 0;
  8126. //int modifyflag = FALSE;
  8127. char filename[MAX]={0};
  8128. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8129. //int resultRename=0;
  8130. char rmFileCmd[50]={0};
  8131. char tempchargingProfilePurposeStr[30]={0};
  8132. char word[1600]={0};
  8133. int n_chargingProfile = 0;
  8134. //[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}}}]
  8135. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8136. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8137. //Filter string space
  8138. strcpy(sstrtemp, stringtrimspace(payload));
  8139. //*********************connectorId***************************/
  8140. loc = strstr(sstrtemp, "connectorId");
  8141. c = 0;
  8142. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8143. while (loc[strlen("connectorId")+2+c] != ',')
  8144. {
  8145. sstr[c] = loc[strlen("connectorId")+2+c];
  8146. c++;
  8147. }
  8148. sstr[c] = '\0';
  8149. connectorIdInt = atoi(sstr);
  8150. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8151. {
  8152. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8153. }
  8154. else
  8155. {
  8156. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  8157. }
  8158. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  8159. //*********************chargingProfileId***************************/
  8160. loc = strstr(sstrtemp, "chargingProfileId");
  8161. c = 0;
  8162. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8163. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8164. {
  8165. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8166. c++;
  8167. }
  8168. sstr[c] = '\0';
  8169. chargingProfileIdInt = atoi(sstr);
  8170. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8171. {
  8172. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8173. }
  8174. else
  8175. {
  8176. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8177. }
  8178. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  8179. //*********************transactionId***************************/
  8180. loc = strstr(sstrtemp, "transactionId");
  8181. if(loc != NULL)
  8182. {
  8183. c = 0;
  8184. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8185. while (loc[strlen("transactionId")+2+c] != ',')
  8186. {
  8187. sstr[c] = loc[strlen("transactionId")+2+c];
  8188. c++;
  8189. }
  8190. sstr[c] = '\0';
  8191. transactionIdInt = atoi(sstr);
  8192. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8193. {
  8194. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  8195. }
  8196. else
  8197. {
  8198. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  8199. }
  8200. }
  8201. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  8202. //*********************stackLevel***************************/
  8203. loc = strstr(sstrtemp, "stackLevel");
  8204. c = 0;
  8205. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8206. while (loc[strlen("stackLevel")+2+c] != ',')
  8207. {
  8208. sstr[c] = loc[strlen("stackLevel")+2+c];
  8209. c++;
  8210. }
  8211. sstr[c] = '\0';
  8212. stackLevelInt = atoi(sstr);
  8213. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8214. {
  8215. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8216. }
  8217. else
  8218. {
  8219. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8220. }
  8221. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  8222. //*********************chargingProfilePurpose***************************/
  8223. loc = strstr(sstrtemp, "chargingProfilePurpose");
  8224. c = 0;
  8225. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8226. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8227. {
  8228. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8229. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8230. c++;
  8231. }
  8232. sstr[c] = '\0';
  8233. strcpy(chargingProfilePurposeStr,sstr);
  8234. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  8235. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8236. {
  8237. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8238. }
  8239. else
  8240. {
  8241. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8242. }
  8243. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  8244. //*********************chargingProfileKind***************************/
  8245. loc = strstr(sstrtemp, "chargingProfileKind");
  8246. c = 0;
  8247. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8248. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  8249. {
  8250. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  8251. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8252. c++;
  8253. }
  8254. sstr[c] = '\0';
  8255. strcpy(chargingProfileKindStr,sstr);
  8256. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8257. {
  8258. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8259. }
  8260. else
  8261. {
  8262. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8263. }
  8264. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  8265. //*********************recurrencyKind***************************/
  8266. loc = strstr(sstrtemp, "recurrencyKind");
  8267. if(loc != NULL)
  8268. {
  8269. c = 0;
  8270. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8271. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  8272. {
  8273. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  8274. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8275. c++;
  8276. }
  8277. sstr[c] = '\0';
  8278. strcpy(recurrencyKindStr,sstr);
  8279. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8280. {
  8281. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8282. }
  8283. else
  8284. {
  8285. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8286. }
  8287. }
  8288. else
  8289. {
  8290. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8291. {
  8292. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  8293. }
  8294. else
  8295. {
  8296. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  8297. }
  8298. }
  8299. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  8300. //*********************validFrom***************************/
  8301. loc = strstr(sstrtemp, "validFrom");
  8302. if(loc != NULL)
  8303. {
  8304. c = 0;
  8305. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8306. while (loc[3+strlen("validFrom")+c] != '\"')
  8307. {
  8308. sstr[c] = loc[3+strlen("validFrom")+c];
  8309. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8310. c++;
  8311. }
  8312. sstr[c] = '\0';
  8313. strcpy(validFromStr,sstr);
  8314. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8315. {
  8316. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8317. }
  8318. else
  8319. {
  8320. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8321. }
  8322. }
  8323. else
  8324. {
  8325. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8326. {
  8327. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  8328. }
  8329. else
  8330. {
  8331. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  8332. }
  8333. }
  8334. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  8335. //*********************validTo***************************/
  8336. loc = strstr(sstrtemp, "validTo");
  8337. if(loc != NULL)
  8338. {
  8339. c = 0;
  8340. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8341. while (loc[3+strlen("validTo")+c] != '\"')
  8342. {
  8343. sstr[c] = loc[3+strlen("validTo")+c];
  8344. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8345. c++;
  8346. }
  8347. sstr[c] = '\0';
  8348. strcpy(validToStr,sstr);
  8349. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8350. {
  8351. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8352. }
  8353. else
  8354. {
  8355. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8356. }
  8357. }
  8358. else
  8359. {
  8360. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8361. {
  8362. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  8363. }
  8364. else
  8365. {
  8366. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  8367. }
  8368. }
  8369. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  8370. //*********************duration***************************/
  8371. loc = strstr(sstrtemp, "duration");
  8372. if(loc != NULL)
  8373. {
  8374. c = 0;
  8375. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8376. while (loc[strlen("duration")+2+c] != ',')
  8377. {
  8378. sstr[c] = loc[strlen("duration")+2+c];
  8379. c++;
  8380. }
  8381. sstr[c] = '\0';
  8382. durationInt = atoi(sstr);
  8383. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8384. {
  8385. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8386. }
  8387. else
  8388. {
  8389. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8390. }
  8391. }
  8392. else
  8393. {
  8394. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8395. {
  8396. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  8397. }
  8398. else
  8399. {
  8400. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  8401. }
  8402. }
  8403. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  8404. //*********************startSchedule***************************/
  8405. loc = strstr(sstrtemp, "startSchedule");
  8406. if(loc != NULL)
  8407. {
  8408. c = 0;
  8409. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8410. while (loc[3+strlen("startSchedule")+c] != '\"')
  8411. {
  8412. sstr[c] = loc[3+strlen("startSchedule")+c];
  8413. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8414. c++;
  8415. }
  8416. sstr[c] = '\0';
  8417. strcpy(startScheduleStr,sstr);
  8418. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8419. {
  8420. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8421. }
  8422. else
  8423. {
  8424. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8425. }
  8426. }
  8427. else
  8428. {
  8429. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8430. {
  8431. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8432. }
  8433. else
  8434. {
  8435. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8436. }
  8437. }
  8438. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  8439. //*********************chargingRateUnit***************************/
  8440. loc = strstr(sstrtemp, "chargingRateUnit");
  8441. if(loc != NULL)
  8442. {
  8443. c = 0;
  8444. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8445. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  8446. {
  8447. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  8448. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8449. c++;
  8450. }
  8451. sstr[c] = '\0';
  8452. strcpy(chargingRateUnitStr,sstr);
  8453. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8454. {
  8455. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8456. }
  8457. else
  8458. {
  8459. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8460. }
  8461. }
  8462. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  8463. //****************chargingSchedulePeriod count start*******************/
  8464. int what_len = strlen("startPeriod");
  8465. char tempChargingProfile[1600]={0};
  8466. strcpy(tempChargingProfile,(const char*)sstrtemp);
  8467. char *where = tempChargingProfile;
  8468. if (what_len)
  8469. {
  8470. while ((where = strstr(where, "startPeriod"))) {
  8471. where += what_len;
  8472. chargingSchedulePeriodCount++;
  8473. }
  8474. }
  8475. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8476. {
  8477. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8478. goto end;
  8479. }
  8480. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  8481. //where = payload;
  8482. int templength = 0;
  8483. //int searchstart = 0;
  8484. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  8485. {
  8486. //****************startPeriod*******************/
  8487. c=0;
  8488. loc = strstr(tempChargingProfile + templength, "startPeriod");
  8489. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8490. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  8491. {
  8492. sstr[c] = loc[strlen("startPeriod")+2+c];
  8493. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8494. c++;
  8495. }
  8496. sstr[c] = '\0';
  8497. startPeriodInt[periodNums] = atoi(sstr);
  8498. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  8499. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  8500. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8501. {
  8502. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8503. }
  8504. else
  8505. {
  8506. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8507. }
  8508. templength = strlen("startPeriod")+2+c;
  8509. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  8510. //****************limit*******************/
  8511. c=0;
  8512. loc = strstr(tempChargingProfile + templength, "limit");
  8513. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8514. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  8515. {
  8516. sstr[c] = loc[strlen("limit")+2+c];
  8517. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8518. c++;
  8519. }
  8520. sstr[c] = '\0';
  8521. limitflaot[periodNums] = atof(sstr);
  8522. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8523. {
  8524. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8525. }
  8526. else
  8527. {
  8528. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8529. }
  8530. templength = templength + strlen("limit")+2+c;
  8531. //****************numberPhases*******************/
  8532. loc = strstr(tempChargingProfile + templength, "numberPhases");
  8533. if(loc != NULL)
  8534. {
  8535. c=0;
  8536. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8537. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  8538. {
  8539. sstr[c] = loc[strlen("numberPhases")+2+c];
  8540. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8541. c++;
  8542. }
  8543. sstr[c] = '\0';
  8544. numberPhasesInt[periodNums] = atoi(sstr);
  8545. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8546. {
  8547. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8548. }
  8549. else
  8550. {
  8551. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8552. }
  8553. templength = templength + strlen("numberPhases")+2+c;
  8554. }
  8555. //where = loc;
  8556. }
  8557. //****************chargingSchedulePeriod count end*******************/
  8558. //*********************minChargingRate***************************/
  8559. loc = strstr(sstrtemp, "minChargingRate");
  8560. if(loc != NULL)
  8561. {
  8562. c = 0;
  8563. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8564. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  8565. {
  8566. sstr[c] = loc[strlen("minChargingRate")+2+c];
  8567. c++;
  8568. }
  8569. sstr[c] = '\0';
  8570. minChargingRateFloat = atof(sstr);
  8571. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8572. {
  8573. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8574. }
  8575. else
  8576. {
  8577. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8578. }
  8579. }
  8580. else
  8581. {
  8582. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8583. {
  8584. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8585. }
  8586. else
  8587. {
  8588. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8589. }
  8590. }
  8591. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8592. {
  8593. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8594. if(connectorIdInt != 0)
  8595. {
  8596. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8597. goto end;
  8598. }
  8599. strcpy(filename, ChargePointMaxProfile_JSON );
  8600. fptr1 = fopen(filename, "r");
  8601. if (!fptr1)
  8602. {
  8603. //file not exist
  8604. DEBUG_INFO("Unable to open the input file!!\n");
  8605. fptr1 = fopen(filename, "w+");
  8606. }
  8607. else
  8608. {
  8609. //Check Charging Profile Count
  8610. while(fscanf(fptr1, "%s", word) != EOF)
  8611. {
  8612. //DEBUG_INFO("word=%s\n",word);
  8613. if(strstr(word, "chargingProfileId")!= NULL)
  8614. {
  8615. //DEBUG_INFO("test chargingProfileId \n");
  8616. n_chargingProfile = n_chargingProfile + 1;
  8617. //DEBUG_INFO("chargingProfileId Found\n");
  8618. }
  8619. }
  8620. }
  8621. fclose(fptr1);
  8622. }
  8623. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8624. {
  8625. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8626. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8627. {
  8628. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8629. goto end;
  8630. }
  8631. memset(filename, 0, ARRAY_SIZE(filename));
  8632. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8633. fptr1 = fopen(filename, "r");
  8634. if (!fptr1)
  8635. {
  8636. //file not exist
  8637. //DEBUG_INFO("Unable to open the input file!!\n");
  8638. fptr1 = fopen(filename, "w+");
  8639. }
  8640. else
  8641. {
  8642. //Check Charging Profile Count
  8643. while(fscanf(fptr1, "%s", word) != EOF)
  8644. {
  8645. //DEBUG_INFO("word=%s\n",word);
  8646. if(strstr(word, "chargingProfileId")!= NULL)
  8647. {
  8648. //DEBUG_INFO("test chargingProfileId \n");
  8649. n_chargingProfile = n_chargingProfile + 1;
  8650. //DEBUG_INFO("chargingProfileId Found\n");
  8651. }
  8652. }
  8653. }
  8654. fclose(fptr1);
  8655. }
  8656. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8657. {
  8658. //printf("set chargingProfile 1-4\n");
  8659. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8660. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  8661. if(connectorIdInt == 0)
  8662. {
  8663. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8664. goto end;
  8665. }
  8666. int tempIndex = 0;
  8667. //check Transaction active
  8668. if(gunType[connectorIdInt -1] == 'J')
  8669. {
  8670. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8671. {
  8672. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8673. }
  8674. else
  8675. {
  8676. tempIndex = connectorIdInt -1;
  8677. }
  8678. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8679. {
  8680. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8681. {
  8682. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8683. {
  8684. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8685. {
  8686. meet = TRUE;
  8687. break;
  8688. }
  8689. }
  8690. }
  8691. }
  8692. }
  8693. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  8694. {
  8695. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8696. {
  8697. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8698. }
  8699. else
  8700. {
  8701. tempIndex = connectorIdInt -1;
  8702. }
  8703. for (int index = 0; index < CCS_QUANTITY; index++)
  8704. {
  8705. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8706. {
  8707. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8708. {
  8709. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8710. {
  8711. meet = TRUE;
  8712. break;
  8713. }
  8714. }
  8715. }
  8716. }
  8717. }
  8718. else if(gunType[connectorIdInt -1] == 'G')
  8719. {
  8720. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8721. {
  8722. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8723. }
  8724. else
  8725. {
  8726. tempIndex = connectorIdInt -1;
  8727. }
  8728. for (int index = 0; index < GB_QUANTITY; index++)
  8729. {
  8730. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8731. {
  8732. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8733. {
  8734. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8735. {
  8736. meet = TRUE;
  8737. break;
  8738. }
  8739. }
  8740. }
  8741. }
  8742. }
  8743. else
  8744. {
  8745. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8746. {
  8747. tempIndex = 2;
  8748. }
  8749. else
  8750. {
  8751. tempIndex = (connectorIdInt -1);
  8752. }
  8753. for (int index = 0; index < AC_QUANTITY; index++)
  8754. {
  8755. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8756. {
  8757. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8758. {
  8759. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8760. {
  8761. meet = TRUE;
  8762. break;
  8763. }
  8764. }
  8765. }
  8766. }
  8767. }
  8768. //check Transaction active
  8769. if(meet == FALSE)
  8770. {
  8771. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8772. goto end;
  8773. }
  8774. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8775. {
  8776. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8777. goto end;
  8778. }
  8779. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8780. fptr1 = fopen(filename, "r");
  8781. if (!fptr1)
  8782. {
  8783. //file not exist
  8784. DEBUG_INFO("Unable to open the input file!!\n");
  8785. fptr1 = fopen(filename, "w+");
  8786. }
  8787. else
  8788. {
  8789. //Check Charging Profile Count
  8790. while(fscanf(fptr1, "%s", word) != EOF)
  8791. {
  8792. //DEBUG_INFO("word=%s\n",word);
  8793. if(strstr(word, "chargingProfileId")!= NULL)
  8794. {
  8795. //DEBUG_INFO("test chargingProfileId \n");
  8796. n_chargingProfile = n_chargingProfile + 1;
  8797. //DEBUG_INFO("chargingProfileId Found\n");
  8798. }
  8799. }
  8800. }
  8801. fclose(fptr1);
  8802. }
  8803. // Check ChargeProfileMaxStackLevel
  8804. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8805. {
  8806. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8807. goto end;
  8808. }
  8809. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8810. {
  8811. int i = 0;
  8812. char fnametemp[200]={0};
  8813. n_chargingProfile = 0;
  8814. //Check ChargePointMaxProfile.json exit
  8815. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8816. {
  8817. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8818. //Check Charging Profile Count
  8819. while(fscanf(fptr1, "%s", word) != EOF)
  8820. {
  8821. //DEBUG_INFO("word=%s\n",word);
  8822. if(strstr(word, "chargingProfileId")!= NULL)
  8823. {
  8824. //DEBUG_INFO("test chargingProfileId \n");
  8825. n_chargingProfile = n_chargingProfile + 1;
  8826. i = i + 1;
  8827. //DEBUG_INFO("chargingProfileId Found\n");
  8828. }
  8829. memset(word, 0, ARRAY_SIZE(word));
  8830. }
  8831. fclose(fptr1);
  8832. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8833. }
  8834. //Check TxDefaultProfile_0.json exit
  8835. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8836. {
  8837. i = 0;
  8838. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8839. //Check Charging Profile Count
  8840. while(fscanf(fptr1, "%s", word) != EOF)
  8841. {
  8842. //DEBUG_INFO("word=%s\n",word);
  8843. if(strstr(word, "chargingProfileId")!= NULL)
  8844. {
  8845. //DEBUG_INFO("test chargingProfileId \n");
  8846. n_chargingProfile = n_chargingProfile + 1;
  8847. i = i + 1;
  8848. //DEBUG_INFO("chargingProfileId Found\n");
  8849. }
  8850. memset(word, 0, ARRAY_SIZE(word));
  8851. }
  8852. fclose(fptr1);
  8853. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  8854. }
  8855. //Check TxDefaultProfile_%d.json
  8856. for(int j=1; j <= gunTotalNumber; j++)
  8857. {
  8858. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8859. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8860. if((access(fnametemp,F_OK))!=-1)
  8861. {
  8862. i = 0;
  8863. fptr1 = fopen(fnametemp, "r");
  8864. //Check Charging Profile Count
  8865. while(fscanf(fptr1, "%s", word) != EOF)
  8866. {
  8867. //DEBUG_INFO("word=%s\n",word);
  8868. if(strstr(word, "chargingProfileId")!= NULL)
  8869. {
  8870. //DEBUG_INFO("test chargingProfileId \n");
  8871. n_chargingProfile = n_chargingProfile + 1;
  8872. i = i + 1;
  8873. //DEBUG_INFO("chargingProfileId Found\n");
  8874. }
  8875. memset(word, 0, ARRAY_SIZE(word));
  8876. }
  8877. fclose(fptr1);
  8878. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8879. }
  8880. }
  8881. //Check TxProfile_%d.json
  8882. for(int j=1; j <= gunTotalNumber; j++)
  8883. {
  8884. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8885. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8886. if((access(fnametemp,F_OK))!=-1)
  8887. {
  8888. i = 0;
  8889. fptr1 = fopen(fnametemp, "r");
  8890. //Check Charging Profile Count
  8891. while(fscanf(fptr1, "%s", word) != EOF)
  8892. {
  8893. //DEBUG_INFO("word=%s\n",word);
  8894. if(strstr(word, "chargingProfileId")!= NULL)
  8895. {
  8896. //DEBUG_INFO("test chargingProfileId \n");
  8897. n_chargingProfile = n_chargingProfile + 1;
  8898. i = i + 1;
  8899. //DEBUG_INFO("chargingProfileId Found\n");
  8900. }
  8901. memset(word, 0, ARRAY_SIZE(word));
  8902. }
  8903. fclose(fptr1);
  8904. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8905. }
  8906. }
  8907. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  8908. {
  8909. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8910. goto end;
  8911. }
  8912. }
  8913. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8914. //**********************************Write to File********************************************************/
  8915. FILE *infile;
  8916. FILE *outfile;
  8917. // open file for writing
  8918. infile = fopen (filename, "r");
  8919. outfile = fopen (tempfile, "w");
  8920. int d =0;
  8921. d = fgetc(infile);
  8922. //DEBUG_INFO("d:%d\n",d);
  8923. rewind(infile);
  8924. //*璉 瘚 辣蝏     1嚗   0 */
  8925. if(d == EOF)
  8926. {
  8927. //DEBUG_INFO("ChargingProfile content is NULL\n");
  8928. fprintf(outfile,"%s\n",payload);
  8929. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8930. fclose(infile);
  8931. fclose(outfile);
  8932. sprintf(rmFileCmd,"rm -f %s",filename);
  8933. system(rmFileCmd);
  8934. rename(tempfile, filename);
  8935. sleep(1);
  8936. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  8937. //system(rmFileCmd);
  8938. }
  8939. else
  8940. {
  8941. char buf[1000]={0};
  8942. int ChargingProfileAdded = FALSE;
  8943. while (fgets(buf, sizeof(buf), infile) != NULL)
  8944. {
  8945. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8946. //*************************tempconnectorIdInt*********************************/
  8947. loc = strstr(buf, "connectorId");
  8948. c = 0;
  8949. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8950. while (loc[strlen("connectorId")+2+c] != ',')
  8951. {
  8952. sstr[c] = loc[strlen("connectorId")+2+c];
  8953. c++;
  8954. }
  8955. sstr[c] = '\0';
  8956. tempconnectorIdInt = atoi(sstr);
  8957. //*************************tempchargingProfileIdInt*********************************/
  8958. loc = strstr(buf, "chargingProfileId");
  8959. c = 0;
  8960. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8961. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8962. {
  8963. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8964. c++;
  8965. }
  8966. sstr[c] = '\0';
  8967. tempchargingProfileIdInt = atoi(sstr);
  8968. //*************************tempstackLevelInt*********************************/
  8969. loc = strstr(buf, "stackLevel");
  8970. c = 0;
  8971. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8972. while (loc[strlen("stackLevel")+2+c] != ',')
  8973. {
  8974. sstr[c] = loc[strlen("stackLevel")+2+c];
  8975. c++;
  8976. }
  8977. sstr[c] = '\0';
  8978. tempstackLevelInt = atoi(sstr);
  8979. //*************************tempchargingProfilePurposeStr*********************************/
  8980. loc = strstr(payload, "chargingProfilePurpose");
  8981. c = 0;
  8982. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8983. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8984. {
  8985. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8986. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8987. c++;
  8988. }
  8989. sstr[c] = '\0';
  8990. strcpy(tempchargingProfilePurposeStr,sstr);
  8991. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  8992. {
  8993. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8994. {
  8995. //DEBUG_INFO("update set chargingProfile to file -0\n");
  8996. if(ChargingProfileAdded == FALSE)
  8997. {
  8998. fprintf(outfile,"%s\n",payload);
  8999. ChargingProfileAdded = TRUE;
  9000. }
  9001. }
  9002. else
  9003. {
  9004. if(tempstackLevelInt < stackLevelInt)
  9005. {
  9006. if(ChargingProfileAdded == FALSE)
  9007. {
  9008. fprintf(outfile,"%s\n",payload);
  9009. ChargingProfileAdded = TRUE;
  9010. fprintf(outfile,"%s\n",buf);
  9011. }
  9012. else
  9013. {
  9014. fprintf(outfile,"%s\n",buf);
  9015. }
  9016. }
  9017. else
  9018. {
  9019. if(ChargingProfileAdded == FALSE)
  9020. {
  9021. fprintf(outfile,"%s\n",buf);
  9022. fprintf(outfile,"%s\n",payload);
  9023. ChargingProfileAdded = TRUE;
  9024. }
  9025. else
  9026. {
  9027. fprintf(outfile,"%s\n",buf);
  9028. }
  9029. }
  9030. }
  9031. }
  9032. else
  9033. {
  9034. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9035. {
  9036. if(ChargingProfileAdded == FALSE)
  9037. {
  9038. fprintf(outfile,"%s\n",payload);
  9039. ChargingProfileAdded = TRUE;
  9040. fprintf(outfile,"%s\n",buf);
  9041. }
  9042. else
  9043. {
  9044. fprintf(outfile,"%s\n",buf);
  9045. }
  9046. }
  9047. else if(tempstackLevelInt < stackLevelInt)
  9048. {
  9049. if(ChargingProfileAdded == FALSE)
  9050. {
  9051. fprintf(outfile,"%s\n",payload);
  9052. ChargingProfileAdded = TRUE;
  9053. fprintf(outfile,"%s\n",buf);
  9054. }
  9055. else
  9056. {
  9057. fprintf(outfile,"%s\n",buf);
  9058. }
  9059. }
  9060. else
  9061. {
  9062. if(ChargingProfileAdded == FALSE)
  9063. {
  9064. fprintf(outfile,"%s\n",buf);
  9065. fprintf(outfile,"%s\n",payload);
  9066. ChargingProfileAdded = TRUE;
  9067. }
  9068. else
  9069. {
  9070. fprintf(outfile,"%s\n",buf);
  9071. }
  9072. }
  9073. }
  9074. } // end of while loop
  9075. fclose(infile);
  9076. fclose(outfile);
  9077. sprintf(rmFileCmd,"rm -f %s",filename);
  9078. system(rmFileCmd);
  9079. rename(tempfile, filename);
  9080. sleep(1);
  9081. result = TRUE;
  9082. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9083. }
  9084. end:
  9085. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  9086. return result;
  9087. return result;
  9088. }
  9089. int handleTriggerMessageRequest(char *uuid, char *payload)
  9090. {
  9091. mtrace();
  9092. int result = FAIL;
  9093. int connectorIdIsNULL = FALSE;
  9094. int connectorIdInt =0;
  9095. char sstr[40]={0},sstrtemp[100]={ 0 };
  9096. char requestedMessagestr[40]={0};
  9097. char comfirmstr[20]={0};
  9098. int c = 0;
  9099. char *loc;
  9100. DEBUG_INFO("handleTriggerMessageRequest\n");
  9101. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  9102. strcpy(sstrtemp, stringtrimspace(payload));
  9103. c = 0;
  9104. loc = strstr(sstrtemp, "requestedMessage");
  9105. while (loc[3+strlen("requestedMessage")+c] != '\"')
  9106. {
  9107. sstr[c] = loc[3+strlen("requestedMessage")+c];
  9108. c++;
  9109. }
  9110. sstr[c] = '\0';
  9111. strcpy(requestedMessagestr, sstr);
  9112. c = 0;
  9113. loc = strstr(sstrtemp, "connectorId");
  9114. if(loc == NULL)
  9115. {
  9116. connectorIdIsNULL = TRUE;
  9117. }
  9118. else
  9119. {
  9120. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9121. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  9122. {
  9123. sstr[c] = loc[strlen("connectorId")+2+c];
  9124. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9125. c++;
  9126. }
  9127. sstr[c] = '\0';
  9128. connectorIdInt = atoi(sstr);
  9129. }
  9130. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  9131. {
  9132. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  9133. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  9134. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  9135. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  9136. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  9137. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  9138. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  9139. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  9140. {
  9141. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  9142. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9143. return TRUE;
  9144. }
  9145. else
  9146. {
  9147. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9148. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9149. }
  9150. }
  9151. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  9152. {
  9153. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  9154. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9155. return TRUE;
  9156. }
  9157. //==========================
  9158. // Trigger message
  9159. //==========================
  9160. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  9161. {
  9162. if((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) &&
  9163. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) &&
  9164. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) &&
  9165. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING) )
  9166. {
  9167. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  9168. }
  9169. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  9170. }
  9171. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  9172. {
  9173. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  9174. }
  9175. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  9176. {
  9177. //sendBootNotificationRequest();
  9178. server_sign = FALSE;
  9179. }
  9180. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  9181. {
  9182. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  9183. }
  9184. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  9185. {
  9186. if(connectorIdIsNULL == FALSE)
  9187. {
  9188. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9189. {
  9190. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  9191. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  9192. }
  9193. }
  9194. else
  9195. {
  9196. for(int idx=0;idx< gunTotalNumber;idx++)
  9197. {
  9198. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  9199. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  9200. }
  9201. }
  9202. }
  9203. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  9204. {
  9205. if(connectorIdIsNULL == FALSE)
  9206. {
  9207. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9208. {
  9209. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  9210. }
  9211. }
  9212. else
  9213. {
  9214. for(int idx=0;idx< gunTotalNumber;idx++)
  9215. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  9216. }
  9217. }
  9218. return result;
  9219. }
  9220. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9221. {
  9222. mtrace();
  9223. int result = FAIL;
  9224. char sstr[6]={0},sstrtemp[50]={ 0 };
  9225. int connectorIdInt =0;
  9226. char comfirmstr[20]={0};
  9227. int c = 0;
  9228. int tempIndex = 0;
  9229. char *loc;
  9230. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9231. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9232. strcpy(sstrtemp, stringtrimspace(payload));
  9233. c = 0;
  9234. loc = strstr(sstrtemp, "connectorId");
  9235. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9236. while (loc[strlen("connectorId")+2+c] != '}')
  9237. {
  9238. sstr[c] = loc[strlen("connectorId")+2+c];
  9239. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9240. c++;
  9241. }
  9242. sstr[c] = '\0';
  9243. connectorIdInt = atoi(sstr);
  9244. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  9245. if(gunTotalNumber == 0)
  9246. {
  9247. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9248. goto end;
  9249. }
  9250. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9251. {
  9252. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9253. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9254. goto end;
  9255. }
  9256. else
  9257. {
  9258. //check Transaction active
  9259. if(gunType[connectorIdInt-1] == 'J')
  9260. {
  9261. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9262. {
  9263. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9264. }
  9265. else
  9266. {
  9267. tempIndex = connectorIdInt -1;
  9268. }
  9269. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9270. {
  9271. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9272. {
  9273. //stop Transaction
  9274. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9275. }
  9276. }
  9277. }
  9278. else if((gunType[connectorIdInt-1] == 'U')||(gunType[connectorIdInt-1] == 'E'))
  9279. {
  9280. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9281. {
  9282. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9283. }
  9284. else
  9285. {
  9286. tempIndex = connectorIdInt -1;
  9287. }
  9288. for (int index = 0; index < CCS_QUANTITY; index++)
  9289. {
  9290. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9291. {
  9292. //stop Transaction
  9293. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9294. }
  9295. }
  9296. }
  9297. else if(gunType[connectorIdInt-1] == 'G')
  9298. {
  9299. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9300. {
  9301. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9302. }
  9303. else
  9304. {
  9305. tempIndex = connectorIdInt -1;
  9306. }
  9307. for (int index = 0; index < GB_QUANTITY; index++)
  9308. {
  9309. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9310. {
  9311. //stop Transaction
  9312. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9313. }
  9314. }
  9315. }
  9316. else
  9317. {
  9318. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9319. {
  9320. tempIndex = 2;
  9321. }
  9322. else
  9323. {
  9324. tempIndex = connectorIdInt-1;
  9325. }
  9326. for (int index = 0; index < AC_QUANTITY; index++)
  9327. {
  9328. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9329. {
  9330. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9331. }
  9332. }
  9333. }
  9334. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9335. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9336. result = TRUE;
  9337. return result;
  9338. }
  9339. end:
  9340. //json_object_put(obj); --- remove temporally
  9341. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9342. return result;
  9343. }
  9344. static char UpdateFirmwarepayloadData[300]={0};
  9345. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9346. {
  9347. mtrace();
  9348. int result = FAIL;
  9349. pthread_t t;
  9350. sendUpdateFirmwareConfirmation(uuid);
  9351. memset(UpdateFirmwarepayloadData, 0, 300);
  9352. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9353. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9354. ////pthread_join(t, NULL); //
  9355. //pthread_detach(t);
  9356. //sendUpdateFirmwareConfirmation(uuid);
  9357. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9358. return result;
  9359. }
  9360. void *UpdateFirmwareProcess(void *data)
  9361. {
  9362. pthread_detach(pthread_self());
  9363. mtrace();
  9364. int retriesInt =0, retryIntervalInt=0;
  9365. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9366. int port=0;
  9367. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9368. int isSuccess = 0;
  9369. char ftpbuf[200];
  9370. char temp[100];
  9371. char * pch;
  9372. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9373. json_object *UpdateFirmware;
  9374. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  9375. if(!is_error(UpdateFirmware))
  9376. {
  9377. // Required data
  9378. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  9379. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  9380. // Optional data
  9381. if(json_object_object_get(UpdateFirmware, "retries"))
  9382. {
  9383. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  9384. }
  9385. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  9386. {
  9387. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  9388. }
  9389. }
  9390. json_object_put(UpdateFirmware);
  9391. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9392. memset(path, 0, ARRAY_SIZE(path));
  9393. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9394. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9395. if(strncmp(locationstr,"http", 4) == 0)
  9396. {
  9397. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9398. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9399. // protocol, user, password, host, path);
  9400. sprintf(ftppath,"/%s", path);
  9401. DEBUG_INFO("locationstr: %s\n", locationstr);
  9402. DEBUG_INFO("protocol: %s\n",protocol);
  9403. DEBUG_INFO("host: %s\n",host);
  9404. DEBUG_INFO("path: %s\n",path);
  9405. DEBUG_INFO("ftppath: %s\n",ftppath);
  9406. int ftppathlen=strlen(ftppath);
  9407. int i=1;
  9408. char filenametemp[50];
  9409. while(i < ftppathlen)
  9410. {
  9411. int len=ftppathlen-i;
  9412. if(ftppath[len]== 47) // '/' ascll code: 47
  9413. {
  9414. DEBUG_INFO("compare '/' all right\n");
  9415. break;
  9416. }
  9417. i=i+1;
  9418. }
  9419. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9420. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9421. filenametemp[i+1] = 0;
  9422. do
  9423. {
  9424. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9425. sleep(retryIntervalInt);
  9426. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9427. if(!isSuccess)
  9428. {
  9429. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9430. }
  9431. else
  9432. {
  9433. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9434. }
  9435. }
  9436. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9437. {
  9438. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9439. memset(temp, 0, ARRAY_SIZE(temp));
  9440. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9441. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9442. int ftppathlen=strlen(ftpbuf);
  9443. int i=1;
  9444. char filenametemp[50];
  9445. while(i < ftppathlen)
  9446. {
  9447. int len=ftppathlen-i;
  9448. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9449. {
  9450. DEBUG_INFO(" compare '/' all right\n");
  9451. break;
  9452. }
  9453. i=i+1;
  9454. }
  9455. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9456. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9457. filenametemp[i+1] = 0;
  9458. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9459. pch=strchr(temp,'@');
  9460. if(pch==NULL)
  9461. {
  9462. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9463. protocol, host, &port, path);
  9464. strcpy(user,"anonymous");
  9465. strcpy(password,"");
  9466. }
  9467. else
  9468. {
  9469. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9470. protocol, user, password, host, &port, path);
  9471. }
  9472. sscanf(host,"%[^/]%s",host1, path1);
  9473. sprintf(ftppath,"%s", path1);
  9474. //DEBUG_INFO("protocol =%s\n",protocol);
  9475. //DEBUG_INFO("user =%s\n",user);
  9476. //DEBUG_INFO("password =%s\n",password);
  9477. //DEBUG_INFO("host1 =%s\n",host1);
  9478. //DEBUG_INFO("port =%d\n",port);
  9479. //DEBUG_INFO("path1 =%s\n",path1);
  9480. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9481. //ftpFile(host, user, password, port, ftppath, fname);
  9482. //download firmware pthred
  9483. if(port == 0)
  9484. {
  9485. port = 21;
  9486. }
  9487. do
  9488. {
  9489. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9490. sleep(retryIntervalInt);
  9491. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9492. if(!isSuccess)
  9493. {
  9494. //BulldogUtil.sleepMs(interval*1000);
  9495. DEBUG_INFO("Update firmware request and download file fail.\n");
  9496. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9497. }
  9498. else
  9499. {
  9500. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9501. }
  9502. }
  9503. else
  9504. {
  9505. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9506. }
  9507. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9508. pthread_exit(NULL);
  9509. }
  9510. //==========================================
  9511. // Handle server response routine
  9512. //==========================================
  9513. void handleAuthorizeResponse(char *payload, int gun_index)
  9514. {
  9515. mtrace();
  9516. char expiryDatestr[30]={0};
  9517. char parentIdTagstr[20]={0};
  9518. char statusstr[20]={0};
  9519. char expiryDatestrtemp[30]={0};
  9520. char parentIdTagstrtemp[20]={0};
  9521. char IdTagstrtemp[20]={0};
  9522. char statusstrtemp[20]={0};
  9523. int expiryDateISNULL=FALSE;
  9524. int parentIdTagISNULL=FALSE;
  9525. char sstr[160]={0};
  9526. char* filename = AuthorizationCache_JSON;
  9527. char tempfile[] = "/Storage/OCPP/Authorizetemp.json";
  9528. char *loc;
  9529. int resultRename=0;
  9530. int responseIdTagInfoAsZero= 0;
  9531. char rmFileCmd[50]={0};
  9532. DEBUG_INFO("handleAuthorizeResponse...\n");
  9533. json_object *Authorize;
  9534. Authorize = json_tokener_parse(payload);
  9535. if(!is_error(Authorize))
  9536. {
  9537. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  9538. {
  9539. // Required data
  9540. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  9541. // Optional data
  9542. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  9543. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  9544. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  9545. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  9546. }
  9547. }
  9548. json_object_put(Authorize);
  9549. if(expiryDateISNULL == FALSE)
  9550. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9551. if(parentIdTagISNULL == FALSE)
  9552. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9553. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9554. //Update idTag information to authorization cache if supproted
  9555. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9556. {
  9557. if((access(filename,F_OK))!=-1)
  9558. {
  9559. printf("AuthorizationCache exist.\n");
  9560. }
  9561. else
  9562. {
  9563. printf("AuthorizationCache not exist\n");
  9564. FILE *log = fopen(filename, "w+");
  9565. if(log == NULL)
  9566. {
  9567. printf("log is NULL\n");
  9568. goto out;
  9569. }
  9570. else
  9571. {
  9572. fclose(log);
  9573. }
  9574. }
  9575. FILE *infile;
  9576. FILE *outfile;
  9577. // open file for writing
  9578. infile = fopen (filename, "r");
  9579. outfile = fopen (tempfile, "w");
  9580. int c;
  9581. c = fgetc(infile);
  9582. //DEBUG_INFO("c:%d\n",c);
  9583. rewind(infile);
  9584. if(c == EOF)
  9585. {
  9586. DEBUG_INFO("Orignal File is NULL\n");
  9587. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9588. {
  9589. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9590. }
  9591. else
  9592. {
  9593. strcpy(expiryDatestrtemp, "");
  9594. }
  9595. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9596. {
  9597. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9598. }
  9599. else
  9600. {
  9601. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9602. }
  9603. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9604. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9605. fclose(infile);
  9606. fclose(outfile);
  9607. sprintf(rmFileCmd,"rm -f %s",filename);
  9608. system(rmFileCmd);
  9609. resultRename = rename(tempfile, filename);
  9610. if(resultRename == 0)
  9611. {
  9612. printf("File renamed successfully");
  9613. }
  9614. else
  9615. {
  9616. printf("Error: unable to rename the file");
  9617. }
  9618. }
  9619. else
  9620. {
  9621. char buf[160]={0};
  9622. while (fgets(buf, ARRAY_SIZE(buf), infile) != NULL)
  9623. {
  9624. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9625. memset(expiryDatestr, 0, ARRAY_SIZE(expiryDatestrtemp));
  9626. memset(parentIdTagstr,0, ARRAY_SIZE(parentIdTagstrtemp));
  9627. memset(statusstr, 0, ARRAY_SIZE(statusstrtemp));
  9628. memset(IdTagstrtemp, 0, ARRAY_SIZE(IdTagstrtemp));
  9629. memset(expiryDatestrtemp, 0, ARRAY_SIZE(expiryDatestrtemp));
  9630. memset(parentIdTagstrtemp, 0, ARRAY_SIZE(parentIdTagstrtemp));
  9631. memset(statusstrtemp, 0, ARRAY_SIZE(statusstrtemp));
  9632. //------------------IdTag-----------------------
  9633. loc = strstr(buf, "idTag");
  9634. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9635. c = 0;
  9636. while (loc[3+strlen("idTag")+c] != '\"')
  9637. {
  9638. sstr[c] = loc[3+strlen("idTag")+c];
  9639. c++;
  9640. }
  9641. sstr[c] = '\0';
  9642. strcpy(IdTagstrtemp,sstr);
  9643. //*********************expiryDate***************/
  9644. loc = strstr(buf, "expiryDate");
  9645. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9646. c = 0;
  9647. while (loc[3+strlen("expiryDate")+c] != '\"')
  9648. {
  9649. sstr[c] = loc[3+strlen("expiryDate")+c];
  9650. c++;
  9651. }
  9652. sstr[c] = '\0';
  9653. strcpy(expiryDatestr,sstr);
  9654. //*********************parentIdTag***************/
  9655. loc = strstr(buf, "parentIdTag");
  9656. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9657. c = 0;
  9658. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9659. {
  9660. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9661. c++;
  9662. }
  9663. sstr[c] = '\0';
  9664. strcpy(parentIdTagstr,sstr);
  9665. //*********************status***************/
  9666. loc = strstr(buf, "status");
  9667. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9668. c = 0;
  9669. while (loc[3+strlen("status")+c] != '\"')
  9670. {
  9671. sstr[c] = loc[3+strlen("status")+c];
  9672. c++;
  9673. }
  9674. sstr[c] = '\0';
  9675. strcpy(statusstr,sstr);
  9676. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9677. {
  9678. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9679. responseIdTagInfoAsZero = 1;
  9680. }
  9681. else
  9682. {
  9683. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9684. }
  9685. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9686. {
  9687. //modify item
  9688. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9689. {
  9690. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9691. }
  9692. else
  9693. {
  9694. strcpy(expiryDatestrtemp, "");
  9695. }
  9696. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9697. {
  9698. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9699. }
  9700. else
  9701. {
  9702. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9703. }
  9704. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9705. }
  9706. else
  9707. {
  9708. //wrie original item
  9709. strcpy(expiryDatestrtemp, expiryDatestr);
  9710. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9711. strcpy(statusstrtemp, statusstr);
  9712. }
  9713. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9714. }
  9715. fclose(infile);
  9716. fclose(outfile);
  9717. sprintf(rmFileCmd,"rm -f %s",filename);
  9718. system(rmFileCmd);
  9719. resultRename = rename(tempfile, filename);
  9720. if(resultRename == 0)
  9721. {
  9722. DEBUG_INFO("File renamed successfully");
  9723. }
  9724. else
  9725. {
  9726. DEBUG_INFO("Error: unable to rename the file");
  9727. }
  9728. }
  9729. }
  9730. out:
  9731. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9732. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9733. authorizeRetryTimes = 0;
  9734. }
  9735. char * strtrimc( char * s )
  9736. {
  9737. char * p1 = s;
  9738. char * p2 = s;
  9739. while(*p1 != '\0')
  9740. {
  9741. while(*p1 == ' ' || *p1 == '\t' || *p1 == '\"' || *p1 == '\n' || *p1 == '}' || *p1 == '\r')
  9742. {
  9743. if(*p1 != ',')
  9744. {
  9745. p1 ++;
  9746. }
  9747. else
  9748. {
  9749. break;
  9750. }
  9751. }
  9752. if(*p1 != ',')
  9753. {
  9754. * p2 ++ = *p1 ++;
  9755. //printf("p2=%s\n",p2);
  9756. }
  9757. else
  9758. {
  9759. break;
  9760. }
  9761. }
  9762. *p2 = '\0';
  9763. return (s);
  9764. }
  9765. void handleBootNotificationResponse(char *payload, int gun_index)
  9766. {
  9767. mtrace();
  9768. char statusStr[12]={0};
  9769. char currentTimeStr[30]={0};
  9770. int intervalInt = 0;
  9771. struct tm tp;
  9772. char buf[28]={0};
  9773. char timebuf[50]={0};
  9774. DEBUG_INFO("handleBootNotificationResponse...\n");
  9775. json_object *BootNotification;
  9776. BootNotification = json_tokener_parse(payload);
  9777. if(!is_error(BootNotification))
  9778. {
  9779. // Required data
  9780. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  9781. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  9782. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  9783. }
  9784. json_object_put(BootNotification);
  9785. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9786. BootNotificationInterval = intervalInt;
  9787. HeartBeatWaitTime = intervalInt;
  9788. //write back to ShmOCPP16Data->BootNotification
  9789. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9790. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9791. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9792. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  9793. {
  9794. server_sign = TRUE;
  9795. server_pending =FALSE;
  9796. }
  9797. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9798. {
  9799. server_pending = TRUE;
  9800. }
  9801. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9802. tp.tm_isdst = -1;
  9803. //time_t utc = mktime(&tp);
  9804. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9805. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9806. sprintf(timebuf,"date -s '%s'",buf);
  9807. system(timebuf);
  9808. srand(time(NULL));
  9809. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  9810. //==============================================
  9811. // RTC sync
  9812. //==============================================
  9813. system("/sbin/hwclock -w --systohc");
  9814. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  9815. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9816. }
  9817. void handleDataTransferResponse(char *payload, int gun_index)
  9818. {
  9819. char sstr[160]={0};//sstr[200]={ 0 };
  9820. int c = 0;
  9821. char *loc;
  9822. DEBUG_INFO("handleDataTransferResponse ...\n");
  9823. loc = strstr(payload, "status");
  9824. printf("loc=%s\n",loc);
  9825. c = 0;
  9826. while (loc[3+strlen("status")+c] != '\"')
  9827. {
  9828. sstr[c] = loc[3+strlen("status")+c];
  9829. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9830. c++;
  9831. }
  9832. sstr[c] = '\0';
  9833. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  9834. }
  9835. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  9836. {
  9837. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  9838. //struct json_object *obj;
  9839. // obj = json_tokener_parse(payload);
  9840. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  9841. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  9842. //No fields are defined.
  9843. }
  9844. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  9845. {
  9846. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  9847. //struct json_object *obj;
  9848. // obj = json_tokener_parse(payload);
  9849. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  9850. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  9851. //No fields are defined.
  9852. }
  9853. void handleHeartbeatResponse(char *payload, int gun_index)
  9854. {
  9855. mtrace();
  9856. struct tm tp;
  9857. char buf[28]={0};
  9858. char timebuf[50]={0};
  9859. DEBUG_INFO("handleHeartbeatResponse...\n");
  9860. json_object *Heartbeat;
  9861. Heartbeat = json_tokener_parse(payload);
  9862. if(!is_error(Heartbeat))
  9863. {
  9864. // Required data
  9865. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  9866. }
  9867. json_object_put(BootNotification);
  9868. if(FirstHeartBeat == 0)
  9869. {
  9870. FirstHeartBeat = 1;
  9871. DEBUG_INFO("FirstHeartBeat \n");
  9872. }
  9873. HeartBeatWithNOResponse = 0;
  9874. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9875. tp.tm_isdst = -1;
  9876. //time_t utc = mktime(&tp);
  9877. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9878. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9879. sprintf(timebuf,"date -s '%s'",buf);
  9880. system(timebuf);
  9881. //==============================================
  9882. // RTC sync
  9883. //==============================================
  9884. system("/sbin/hwclock -w --systohc");
  9885. //===============================================
  9886. //Print Out HeartBeat log
  9887. //===============================================
  9888. {
  9889. double diff_t;
  9890. struct tm tp,tp1;
  9891. // BootNotification Receive Time
  9892. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9893. tp.tm_isdst = -1;
  9894. time_t BootNotificationReceiveTime = mktime(&tp);
  9895. //HeartBeat Receive Time
  9896. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp1);
  9897. tp1.tm_isdst = -1;
  9898. time_t HeartBeatReceiveTime = mktime(&tp1);
  9899. diff_t = difftime(HeartBeatReceiveTime, BootNotificationReceiveTime);
  9900. printf("handleHeartbeatResponse differnt time=%f..\n",diff_t);
  9901. if(((int)diff_t / 3600) > HeartBeatCountPerHour)
  9902. {
  9903. HeartBeatCountPerHour = (int)diff_t / 3600;
  9904. DEBUG_INFO("handleHeartbeatResponse ...\n");
  9905. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  9906. }
  9907. }
  9908. }
  9909. void handleMeterValuesResponse(char *payload, int gun_index)
  9910. {
  9911. mtrace();
  9912. DEBUG_INFO("handleMeterValuesResponse...\n");
  9913. }
  9914. void handleStartTransactionResponse(char *payload, int gun_index)
  9915. {
  9916. mtrace();
  9917. //int transactionIdInt = 0;
  9918. FILE *outfile;
  9919. char data[100]={0};
  9920. DEBUG_INFO("handleStartTransactionResponse...\n");
  9921. json_object *StartTransaction;
  9922. StartTransaction = json_tokener_parse(payload);
  9923. if(!is_error(StartTransaction))
  9924. {
  9925. // Required data
  9926. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  9927. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  9928. // Optional data
  9929. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  9930. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  9931. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  9932. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  9933. }
  9934. json_object_put(StartTransaction);
  9935. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  9936. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  9937. //-----------Start : write to the Queue TransactionId file -----------------//
  9938. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  9939. {}
  9940. else
  9941. {
  9942. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  9943. if(log == NULL)
  9944. {
  9945. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  9946. return ;
  9947. }
  9948. else
  9949. {
  9950. fclose(log);
  9951. }
  9952. }
  9953. // open file for writing
  9954. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  9955. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  9956. {
  9957. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  9958. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  9959. fputs(data, outfile);
  9960. fclose (outfile);
  9961. }
  9962. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9963. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9964. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  9965. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  9966. }
  9967. void handleStatusNotificationResponse(char *payload, int gun_index)
  9968. {
  9969. mtrace();
  9970. DEBUG_INFO("handleStatusNotificationResponse...\n");
  9971. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  9972. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  9973. }
  9974. void handleStopTransactionnResponse(char *payload, int gun_index)
  9975. {
  9976. mtrace();
  9977. DEBUG_INFO("handleStopTransactionnResponse...\n");
  9978. json_object *StopTransaction;
  9979. StopTransaction = json_tokener_parse(payload);
  9980. if(!is_error(StopTransaction))
  9981. {
  9982. // Optional data
  9983. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  9984. {
  9985. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  9986. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  9987. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  9988. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  9989. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  9990. }
  9991. }
  9992. json_object_put(StopTransaction);
  9993. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  9994. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  9995. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9996. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9997. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  9998. }
  9999. //==========================================
  10000. // Handle Error routine
  10001. //==========================================
  10002. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  10003. {
  10004. mtrace();
  10005. #ifdef SystemLogMessage
  10006. DEBUG_INFO("errorCode: %s\n", errorCode);
  10007. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  10008. DEBUG_INFO("errorDetails: %s\n", payload);
  10009. #endif
  10010. }
  10011. //===============================================
  10012. // Common routine
  10013. //===============================================
  10014. int initialConfigurationTable(void)
  10015. {
  10016. //clock_t start_t, end_t, total_t;
  10017. FILE *fp;
  10018. FILE *outfile;
  10019. char str[200]={0};
  10020. char sstr[100]={0};
  10021. int c = 0;
  10022. char *loc;
  10023. DEBUG_INFO("initialConfigurationTable...\n");
  10024. //start_t = clock();
  10025. //printf("Starting of the program, start_t = %ld\n", start_t);
  10026. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  10027. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  10028. {
  10029. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10030. if(outfile == NULL)
  10031. {
  10032. DEBUG_INFO("Error opening file\n");
  10033. return FALSE;
  10034. }
  10035. /*Core Profile*/
  10036. //AllowOfflineTxForUnknownId
  10037. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10038. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10039. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  10040. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10041. //AuthorizationCacheEnabled
  10042. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10043. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10044. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10045. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10046. //AuthorizeRemoteTxRequests
  10047. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10048. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10049. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  10050. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10051. //BlinkRepeat
  10052. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10053. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10054. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10055. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10056. //ClockAlignedDataInterval
  10057. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10058. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10059. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10060. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10061. //ConnectionTimeOut
  10062. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10063. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10064. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10065. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10066. //GetConfigurationMaxKeys
  10067. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10068. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "44" );
  10070. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10071. // HeartbeatInterval
  10072. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10073. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10074. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  10075. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10076. // LightIntensity
  10077. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10078. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10079. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10080. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10081. // LocalAuthorizeOffline
  10082. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10085. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10086. // LocalPreAuthorize
  10087. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10088. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10089. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10090. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10091. // MaxEnergyOnInvalidId
  10092. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10093. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10094. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10095. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10096. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10097. // MeterValuesAlignedData
  10098. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  10099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10100. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10101. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10102. else
  10103. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10104. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10105. // MeterValuesAlignedDataMaxLength
  10106. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10107. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10108. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10109. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  10110. else
  10111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10112. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10113. // MeterValuesSampledData
  10114. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  10115. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10116. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10117. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10118. else
  10119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10120. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10121. // MeterValuesSampledDataMaxLength
  10122. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10123. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10124. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  10126. else
  10127. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10128. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10129. // MeterValueSampleInterval
  10130. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10131. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10132. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  10133. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10134. // MinimumStatusDuration
  10135. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10136. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10137. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  10138. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  10139. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10140. // NumberOfConnectors
  10141. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10142. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10143. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10144. {
  10145. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10146. }
  10147. else
  10148. {
  10149. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10150. }
  10151. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10152. // ResetRetries
  10153. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10154. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10155. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10156. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10157. // ConnectorPhaseRotation
  10158. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10159. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10160. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10161. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10162. // ConnectorPhaseRotationMaxLength
  10163. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10164. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10165. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10166. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10167. // StopTransactionOnEVSideDisconnect
  10168. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10169. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10170. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10171. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10172. // StopTransactionOnInvalidId
  10173. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  10174. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10175. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10176. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10177. // StopTxnAlignedData
  10178. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10179. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10180. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10181. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10182. // StopTxnAlignedDataMaxLength
  10183. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10184. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10185. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10186. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10187. // StopTxnSampledData
  10188. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  10189. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10190. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10191. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10192. else
  10193. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10194. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10195. // StopTxnSampledDataMaxLength
  10196. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10197. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10198. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10199. {
  10200. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  10201. }
  10202. else
  10203. {
  10204. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  10205. }
  10206. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10207. // SupportedFeatureProfiles
  10208. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10209. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10211. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10212. // SupportedFeatureProfilesMaxLength
  10213. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10214. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10215. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10216. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10217. // TransactionMessageAttempts
  10218. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10219. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10220. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10221. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10222. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10223. // TransactionMessageRetryInterval
  10224. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10225. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10226. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10227. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10228. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10229. // UnlockConnectorOnEVSideDisconnect
  10230. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10231. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10232. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10233. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10234. // WebSocketPingInterval
  10235. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10236. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10237. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10238. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10239. // QueueOffLineStartTransactionMessage
  10240. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  10241. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10242. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10243. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10244. //* Local Auth List Management Profile*/
  10245. #if 0
  10246. //For OCTT Test Case
  10247. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10248. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10249. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10250. #endif
  10251. #if 1
  10252. //LocalAuthListEnabled
  10253. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10254. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10255. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10256. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10257. #endif
  10258. //LocalAuthListMaxLength
  10259. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10260. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10261. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10262. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10263. //SendLocalListMaxLength
  10264. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10265. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10266. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  10267. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10268. //ReserveConnectorZeroSupported
  10269. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10270. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10271. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10272. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10273. //* Smart Charging Profile */
  10274. //ChargeProfileMaxStackLevel
  10275. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10276. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10277. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10278. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10279. // ChargingScheduleAllowedChargingRateUnit
  10280. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10281. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10282. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10283. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10284. // ChargingScheduleMaxPeriods
  10285. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10286. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10287. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10288. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10289. // ConnectorSwitch3to1PhaseSupported
  10290. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10291. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10292. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10293. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10294. // MaxChargingProfilesInstalled
  10295. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10296. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10297. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10298. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10299. fclose(outfile);
  10300. }
  10301. else
  10302. {
  10303. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10304. char keystr[60]={0};
  10305. char readonlystr[10]={0};
  10306. char valuestr[100]={0};
  10307. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10308. if(fp == NULL) {
  10309. DEBUG_INFO("Error opening file");
  10310. return FALSE;
  10311. }
  10312. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  10313. {
  10314. //DEBUG_INFO("Get Configuration \n");
  10315. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10316. //*************************key*********************************/
  10317. loc = strstr(str, "key");
  10318. c = 0;
  10319. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10320. while (loc[strlen("key")+3+c] != '\"')
  10321. {
  10322. sstr[c] = loc[strlen("key")+3+c];
  10323. c++;
  10324. }
  10325. sstr[c] = '\0';
  10326. strcpy(keystr,sstr);
  10327. //*************************readonly*********************************/
  10328. loc = strstr(str, "readonly");
  10329. c = 0;
  10330. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10331. while (loc[strlen("readonly")+2+c] != ',')
  10332. {
  10333. sstr[c] = loc[strlen("readonly")+2+c];
  10334. c++;
  10335. }
  10336. sstr[c] = '\0';
  10337. strcpy(readonlystr,sstr);
  10338. //*************************value*********************************/
  10339. loc = strstr(str, "value");
  10340. c = 0;
  10341. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10342. while (loc[strlen("value")+3+c] != '\"')
  10343. {
  10344. sstr[c] = loc[strlen("value")+3+c];
  10345. c++;
  10346. }
  10347. sstr[c] = '\0';
  10348. strcpy(valuestr,sstr);
  10349. // DEBUG_INFO("keystr=%s\n",keystr);
  10350. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10351. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10352. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10353. {
  10354. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10355. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10356. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10357. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10358. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10359. }
  10360. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10361. {
  10362. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10363. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10364. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10365. }
  10366. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10367. {
  10368. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10369. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10370. }
  10371. if(strcmp(keystr, "BlinkRepeat") == 0)
  10372. {
  10373. //Charger.BlinkRepeat = Integer.parseInt(value);
  10374. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10375. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10376. }
  10377. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10378. {
  10379. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10380. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10381. }
  10382. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10383. {
  10384. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10385. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10386. }
  10387. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10388. {
  10389. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10390. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  10391. }
  10392. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10393. {
  10394. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10395. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10396. HeartBeatWaitTime = atoi(valuestr);
  10397. }
  10398. if(strcmp(keystr, "LightIntensity") == 0)
  10399. {
  10400. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10401. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10402. }
  10403. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10404. {
  10405. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10406. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10407. }
  10408. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10409. {
  10410. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10411. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10412. }
  10413. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10414. {
  10415. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10416. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10417. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10418. }
  10419. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10420. {
  10421. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10422. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10423. }
  10424. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10425. {
  10426. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10427. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10428. }
  10429. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10430. {
  10431. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10432. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10433. }
  10434. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10435. {
  10436. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10437. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10438. }
  10439. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10440. {
  10441. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10442. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10443. }
  10444. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10445. {
  10446. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10447. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10448. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10449. }
  10450. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10451. {
  10452. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10453. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10454. }
  10455. if(strcmp(keystr, "ResetRetries") == 0)
  10456. {
  10457. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10458. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10459. }
  10460. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10461. {
  10462. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10463. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10464. }
  10465. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10466. {
  10467. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10468. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10469. }
  10470. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10471. {
  10472. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10473. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10474. }
  10475. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10476. {
  10477. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10478. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10479. }
  10480. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10481. {
  10482. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10483. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10484. }
  10485. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10486. {
  10487. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10488. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10489. }
  10490. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10491. {
  10492. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10493. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10494. }
  10495. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10496. {
  10497. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10498. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10499. }
  10500. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10501. {
  10502. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10503. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10504. }
  10505. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10506. {
  10507. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10508. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10509. }
  10510. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10511. {
  10512. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10513. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10514. TransactionMessageAttemptsValue = atoi(valuestr);
  10515. }
  10516. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10517. {
  10518. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10519. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10520. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10521. }
  10522. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10523. {
  10524. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10525. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10526. }
  10527. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10528. {
  10529. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10530. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10531. }
  10532. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  10533. {
  10534. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10535. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  10536. }
  10537. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10538. {
  10539. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10540. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10541. }
  10542. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10543. {
  10544. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10545. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10546. }
  10547. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10548. {
  10549. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10550. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10551. }
  10552. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10553. {
  10554. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10555. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10556. }
  10557. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10558. {
  10559. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10560. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10561. }
  10562. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10563. {
  10564. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10565. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10566. }
  10567. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10568. {
  10569. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10570. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10571. }
  10572. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10573. {
  10574. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10575. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10576. }
  10577. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10578. {
  10579. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10580. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10581. }
  10582. }
  10583. fclose(fp);
  10584. }
  10585. return 0;
  10586. }
  10587. void StoreConfigurationTable(void)
  10588. {
  10589. FILE *outfile;
  10590. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10591. if(outfile == NULL)
  10592. {
  10593. DEBUG_INFO("Error opening file");
  10594. return ;
  10595. }
  10596. /*Core Profile*/
  10597. //AllowOfflineTxForUnknownId
  10598. /*
  10599. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10600. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10601. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10602. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10603. */
  10604. //DEBUG_INFO("data=%s\n",data);
  10605. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10606. //AuthorizationCacheEnabled
  10607. /*
  10608. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10609. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10610. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10611. */
  10612. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10613. //AuthorizeRemoteTxRequests
  10614. /*
  10615. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10616. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10617. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10618. */
  10619. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10620. //BlinkRepeat
  10621. /*
  10622. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10623. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10624. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10625. */
  10626. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10627. //ClockAlignedDataInterval
  10628. /*
  10629. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10630. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10631. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10632. */
  10633. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10634. //ConnectionTimeOut
  10635. /*
  10636. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10637. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10638. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10639. */
  10640. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10641. //GetConfigurationMaxKeys
  10642. /*
  10643. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10644. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10645. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10646. */
  10647. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10648. // HeartbeatInterval
  10649. /*
  10650. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10651. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10652. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10653. */
  10654. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10655. // LightIntensity
  10656. /*
  10657. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10658. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10659. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10660. */
  10661. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10662. // LocalAuthorizeOffline
  10663. /*
  10664. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10665. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10666. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10667. */
  10668. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10669. // LocalPreAuthorize
  10670. /*
  10671. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10672. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10673. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10674. */
  10675. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10676. // MaxEnergyOnInvalidId
  10677. /*
  10678. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10679. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10680. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10681. */
  10682. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10683. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10684. // MeterValuesAlignedData
  10685. /*
  10686. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10687. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10688. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10689. */
  10690. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10691. // MeterValuesAlignedDataMaxLength
  10692. /*
  10693. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10694. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10695. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10696. */
  10697. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10698. // MeterValuesSampledData
  10699. /*
  10700. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10701. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10702. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10703. */
  10704. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10705. // MeterValuesSampledDataMaxLength
  10706. /*
  10707. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10708. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10709. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10710. */
  10711. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10712. // MeterValueSampleInterval
  10713. /*
  10714. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10715. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10716. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10717. */
  10718. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10719. // MinimumStatusDuration
  10720. /*
  10721. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10722. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10723. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10724. */
  10725. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10726. // NumberOfConnectors
  10727. /*
  10728. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10729. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10730. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10731. {
  10732. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10733. }
  10734. else
  10735. {
  10736. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10737. }
  10738. */
  10739. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10740. // ResetRetries
  10741. /*
  10742. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10743. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10744. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10745. */
  10746. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10747. // ConnectorPhaseRotation
  10748. /*
  10749. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10750. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10751. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10752. */
  10753. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10754. // ConnectorPhaseRotationMaxLength
  10755. /*
  10756. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10757. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10758. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10759. */
  10760. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10761. // StopTransactionOnEVSideDisconnect
  10762. /*
  10763. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10764. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10765. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10766. */
  10767. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10768. // StopTransactionOnInvalidId
  10769. /*
  10770. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  10771. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10772. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10773. */
  10774. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10775. // StopTxnAlignedData
  10776. /*
  10777. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10778. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10779. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10780. */
  10781. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10782. // StopTxnAlignedDataMaxLength
  10783. /*
  10784. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10785. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10786. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10787. */
  10788. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10789. // StopTxnSampledData
  10790. /*
  10791. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10792. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  10794. */
  10795. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10796. // StopTxnSampledDataMaxLength
  10797. /*
  10798. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10799. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10801. */
  10802. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10803. // SupportedFeatureProfiles
  10804. /*
  10805. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10806. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10807. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10808. */
  10809. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10810. // SupportedFeatureProfilesMaxLength
  10811. /*
  10812. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10813. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10814. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10815. */
  10816. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10817. // TransactionMessageAttempts
  10818. /*
  10819. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10820. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10821. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10822. */
  10823. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10824. // TransactionMessageRetryInterval
  10825. /*
  10826. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10827. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10828. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10829. */
  10830. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10831. // UnlockConnectorOnEVSideDisconnect
  10832. /*
  10833. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10834. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10835. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10836. */
  10837. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10838. // WebSocketPingInterval
  10839. /*
  10840. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10841. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10842. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10843. */
  10844. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10845. // QueueOffLineStartTransactionMessage
  10846. /*
  10847. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  10848. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10849. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10850. */
  10851. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10852. //* Local Auth List Management Profile*/
  10853. //LocalAuthListEnabled
  10854. /*
  10855. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10856. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10857. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10858. */
  10859. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10860. //LocalAuthListMaxLength
  10861. /*
  10862. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10863. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10864. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10865. */
  10866. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10867. //SendLocalListMaxLength
  10868. /*
  10869. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10870. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10871. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10872. */
  10873. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10874. //ReserveConnectorZeroSupported
  10875. /*
  10876. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10877. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10878. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10879. */
  10880. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10881. //* Smart Charging Profile */
  10882. //ChargeProfileMaxStackLevel
  10883. /*
  10884. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10885. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10886. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10887. */
  10888. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10889. // ChargingScheduleAllowedChargingRateUnit
  10890. /*
  10891. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10892. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10893. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10894. */
  10895. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10896. // ChargingScheduleMaxPeriods
  10897. /*
  10898. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10899. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10900. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10901. */
  10902. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10903. // ConnectorSwitch3to1PhaseSupported
  10904. /*
  10905. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10906. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10907. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10908. */
  10909. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10910. // MaxChargingProfilesInstalled
  10911. /*
  10912. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10913. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10914. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10915. */
  10916. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10917. fclose(outfile);
  10918. }
  10919. void getKeyValue(char *keyReq)
  10920. {
  10921. int isEmpty = FALSE;
  10922. int isKnowKey = FALSE;
  10923. DEBUG_INFO("keyReq = %s\n", keyReq);
  10924. if((keyReq == NULL) || (strlen(keyReq) == 0))
  10925. isEmpty = TRUE;
  10926. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  10927. {
  10928. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  10929. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  10930. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  10931. {
  10932. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  10933. }
  10934. else
  10935. {
  10936. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  10937. }
  10938. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  10939. isKnowKey = TRUE;
  10940. }
  10941. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  10942. {
  10943. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  10944. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  10945. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  10946. {
  10947. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  10948. }
  10949. else
  10950. {
  10951. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  10952. }
  10953. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  10954. isKnowKey = TRUE;
  10955. }
  10956. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  10957. {
  10958. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  10959. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  10960. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  10961. {
  10962. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  10963. }
  10964. else
  10965. {
  10966. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  10967. }
  10968. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  10969. isKnowKey = TRUE;
  10970. }
  10971. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  10972. {
  10973. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  10974. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  10975. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  10976. {
  10977. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  10978. }
  10979. else
  10980. {
  10981. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  10982. }
  10983. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  10984. isKnowKey = TRUE;
  10985. }
  10986. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  10987. {
  10988. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  10989. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  10990. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  10991. {
  10992. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  10993. }
  10994. else
  10995. {
  10996. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  10997. }
  10998. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  10999. isKnowKey = TRUE;
  11000. }
  11001. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  11002. {
  11003. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  11004. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  11005. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11006. {
  11007. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  11008. }
  11009. else
  11010. {
  11011. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  11012. }
  11013. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  11014. isKnowKey = TRUE;
  11015. }
  11016. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  11017. {
  11018. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  11019. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  11020. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11021. {
  11022. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  11023. }
  11024. else
  11025. {
  11026. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  11027. }
  11028. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  11029. isKnowKey = TRUE;
  11030. }
  11031. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  11032. {
  11033. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  11034. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  11035. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11036. {
  11037. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  11038. }
  11039. else
  11040. {
  11041. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  11042. }
  11043. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  11044. isKnowKey = TRUE;
  11045. }
  11046. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  11047. {
  11048. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  11049. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  11050. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11051. {
  11052. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  11053. }
  11054. else
  11055. {
  11056. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  11057. }
  11058. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  11059. isKnowKey = TRUE;
  11060. }
  11061. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  11062. {
  11063. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  11064. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  11065. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11066. {
  11067. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  11068. }
  11069. else
  11070. {
  11071. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  11072. }
  11073. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  11074. isKnowKey = TRUE;
  11075. }
  11076. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  11077. {
  11078. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  11079. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  11080. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11081. {
  11082. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  11083. }
  11084. else
  11085. {
  11086. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  11087. }
  11088. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  11089. isKnowKey = TRUE;
  11090. }
  11091. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  11092. {
  11093. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  11094. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  11095. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11096. {
  11097. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11098. }
  11099. else
  11100. {
  11101. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11102. }
  11103. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  11104. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  11105. isKnowKey = TRUE;
  11106. }
  11107. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  11108. {
  11109. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  11110. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11111. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11112. {
  11113. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11114. }
  11115. else
  11116. {
  11117. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11118. }
  11119. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11120. isKnowKey = TRUE;
  11121. }
  11122. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11123. {
  11124. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11125. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11126. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11127. {
  11128. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11129. }
  11130. else
  11131. {
  11132. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11133. }
  11134. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11135. isKnowKey = TRUE;
  11136. }
  11137. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11138. {
  11139. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11141. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11142. {
  11143. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11144. }
  11145. else
  11146. {
  11147. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11148. }
  11149. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11150. isKnowKey = TRUE;
  11151. }
  11152. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11153. {
  11154. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11156. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11157. {
  11158. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11159. }
  11160. else
  11161. {
  11162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11163. }
  11164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11165. isKnowKey = TRUE;
  11166. }
  11167. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11168. {
  11169. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11170. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11171. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11172. {
  11173. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11174. }
  11175. else
  11176. {
  11177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11178. }
  11179. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11180. isKnowKey = TRUE;
  11181. }
  11182. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11183. {
  11184. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11186. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11187. {
  11188. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11189. }
  11190. else
  11191. {
  11192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11193. }
  11194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11195. isKnowKey = TRUE;
  11196. }
  11197. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11198. {
  11199. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11201. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11202. {
  11203. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11204. }
  11205. else
  11206. {
  11207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11208. }
  11209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11210. isKnowKey = TRUE;
  11211. }
  11212. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11213. {
  11214. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11216. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11217. {
  11218. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11219. }
  11220. else
  11221. {
  11222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11223. }
  11224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11225. isKnowKey = TRUE;
  11226. }
  11227. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11228. {
  11229. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11231. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11232. {
  11233. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11234. }
  11235. else
  11236. {
  11237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11238. }
  11239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11240. isKnowKey = TRUE;
  11241. }
  11242. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11243. {
  11244. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11245. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11246. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11247. {
  11248. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11249. }
  11250. else
  11251. {
  11252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11253. }
  11254. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11255. isKnowKey = TRUE;
  11256. }
  11257. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11258. {
  11259. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11260. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11261. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11262. {
  11263. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11264. }
  11265. else
  11266. {
  11267. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11268. }
  11269. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11270. isKnowKey = TRUE;
  11271. }
  11272. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11273. {
  11274. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11275. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11276. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11277. {
  11278. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11279. }
  11280. else
  11281. {
  11282. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11283. }
  11284. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11285. isKnowKey = TRUE;
  11286. }
  11287. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11288. {
  11289. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11290. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11291. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11292. {
  11293. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11294. }
  11295. else
  11296. {
  11297. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11298. }
  11299. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11300. isKnowKey = TRUE;
  11301. }
  11302. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11303. {
  11304. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11305. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11306. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11307. {
  11308. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11309. }
  11310. else
  11311. {
  11312. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11313. }
  11314. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11315. isKnowKey = TRUE;
  11316. }
  11317. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11318. {
  11319. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11320. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11321. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11322. {
  11323. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11324. }
  11325. else
  11326. {
  11327. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11328. }
  11329. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11330. isKnowKey = TRUE;
  11331. }
  11332. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11333. {
  11334. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11335. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11336. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11337. {
  11338. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11339. }
  11340. else
  11341. {
  11342. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11343. }
  11344. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11345. isKnowKey = TRUE;
  11346. }
  11347. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11348. {
  11349. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11350. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11351. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11352. {
  11353. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11354. }
  11355. else
  11356. {
  11357. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11358. }
  11359. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11360. isKnowKey = TRUE;
  11361. }
  11362. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11363. {
  11364. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11365. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11366. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11367. {
  11368. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11369. }
  11370. else
  11371. {
  11372. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11373. }
  11374. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11375. isKnowKey = TRUE;
  11376. }
  11377. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11378. {
  11379. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11380. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11381. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11382. {
  11383. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11384. }
  11385. else
  11386. {
  11387. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11388. }
  11389. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11390. isKnowKey = TRUE;
  11391. }
  11392. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11393. {
  11394. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11395. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11396. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11397. {
  11398. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11399. }
  11400. else
  11401. {
  11402. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11403. }
  11404. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11405. isKnowKey = TRUE;
  11406. }
  11407. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11408. {
  11409. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11410. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11411. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11412. {
  11413. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11414. }
  11415. else
  11416. {
  11417. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11418. }
  11419. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11420. isKnowKey = TRUE;
  11421. }
  11422. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11423. {
  11424. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11425. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11426. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11427. {
  11428. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11429. }
  11430. else
  11431. {
  11432. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11433. }
  11434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11435. isKnowKey = TRUE;
  11436. }
  11437. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  11438. {
  11439. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  11440. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  11441. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  11442. {
  11443. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  11444. }
  11445. else
  11446. {
  11447. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  11448. }
  11449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  11450. isKnowKey = TRUE;
  11451. }
  11452. #if 1
  11453. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11454. {
  11455. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11457. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11458. {
  11459. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11460. }
  11461. else
  11462. {
  11463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11464. }
  11465. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11466. isKnowKey = TRUE;
  11467. }
  11468. #endif
  11469. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11470. {
  11471. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11473. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11474. {
  11475. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11476. }
  11477. else
  11478. {
  11479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11480. }
  11481. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11482. isKnowKey = TRUE;
  11483. }
  11484. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11485. {
  11486. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11487. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11488. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11489. {
  11490. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11491. }
  11492. else
  11493. {
  11494. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11495. }
  11496. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11497. isKnowKey = TRUE;
  11498. }
  11499. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11500. {
  11501. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11502. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11503. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11504. {
  11505. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11506. }
  11507. else
  11508. {
  11509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11510. }
  11511. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11512. isKnowKey = TRUE;
  11513. }
  11514. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11515. {
  11516. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11517. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11518. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11519. {
  11520. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11521. }
  11522. else
  11523. {
  11524. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11525. }
  11526. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11527. isKnowKey = TRUE;
  11528. }
  11529. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11530. {
  11531. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11532. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11533. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11534. {
  11535. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11536. }
  11537. else
  11538. {
  11539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11540. }
  11541. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11542. isKnowKey = TRUE;
  11543. }
  11544. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11545. {
  11546. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11547. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11548. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11549. {
  11550. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11551. }
  11552. else
  11553. {
  11554. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11555. }
  11556. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11557. isKnowKey = TRUE;
  11558. }
  11559. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11560. {
  11561. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11562. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11563. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11564. {
  11565. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11566. }
  11567. else
  11568. {
  11569. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11570. }
  11571. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11572. isKnowKey = TRUE;
  11573. }
  11574. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11575. {
  11576. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11577. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11578. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11579. {
  11580. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11581. }
  11582. else
  11583. {
  11584. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11585. }
  11586. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11587. isKnowKey = TRUE;
  11588. }
  11589. //=========================================================
  11590. if(!isEmpty && !isKnowKey)
  11591. {
  11592. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11593. strcpy(unknownkey[UnknownKeynum], keyReq);
  11594. UnknownKeynum = UnknownKeynum + 1;
  11595. }
  11596. }
  11597. void processUnkownKey(void)
  11598. {
  11599. DEBUG_INFO("processUnkownKey...\n");
  11600. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11601. for(int index=0; index < UnknownKeynum; index++)
  11602. {
  11603. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11604. {
  11605. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11606. }
  11607. }
  11608. }
  11609. int setKeyValue(char *key, char *value)
  11610. {
  11611. int isSuccess = NotSupported;
  11612. int check_ascii=0;
  11613. char str[10]={0};
  11614. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  11615. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11616. {
  11617. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11618. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11619. {
  11620. strcpy(str, (const char*)value);
  11621. for(int i = 0; str[i]; i++){
  11622. str[i] = tolower(str[i]);
  11623. }
  11624. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11625. isSuccess = ConfigurationStatus_Accepted;
  11626. }
  11627. else
  11628. {
  11629. isSuccess = ConfigurationStatus_Rejected;
  11630. }
  11631. }
  11632. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11633. {
  11634. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11635. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11636. {
  11637. strcpy(str, (const char*)value);
  11638. for(int i = 0; str[i]; i++){
  11639. str[i] = tolower(str[i]);
  11640. }
  11641. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11642. isSuccess = ConfigurationStatus_Accepted;
  11643. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11644. }
  11645. else
  11646. {
  11647. isSuccess = ConfigurationStatus_Rejected;
  11648. }
  11649. }
  11650. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11651. {
  11652. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11653. {
  11654. strcpy(str, (const char*)value);
  11655. for(int i = 0; str[i]; i++)
  11656. {
  11657. str[i] = tolower(str[i]);
  11658. }
  11659. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11660. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11661. isSuccess = ConfigurationStatus_Accepted;
  11662. }
  11663. else
  11664. {
  11665. isSuccess = ConfigurationStatus_Rejected;
  11666. }
  11667. }
  11668. if(strcmp(key, "BlinkRepeat") == 0)
  11669. {
  11670. //Charger.BlinkRepeat = Integer.parseInt(value);
  11671. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11672. {
  11673. check_ascii = value[0];
  11674. if( (check_ascii < 48) || (check_ascii > 57) )
  11675. {
  11676. isSuccess = ConfigurationStatus_Rejected;
  11677. }
  11678. else
  11679. {
  11680. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11681. isSuccess = ConfigurationStatus_Accepted;
  11682. }
  11683. }
  11684. else
  11685. {
  11686. isSuccess = ConfigurationStatus_Rejected;
  11687. }
  11688. }
  11689. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11690. {
  11691. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11692. {
  11693. check_ascii = value[0];
  11694. if( (check_ascii < 48) || (check_ascii > 57) )
  11695. {
  11696. isSuccess = ConfigurationStatus_Rejected;
  11697. }
  11698. else
  11699. {
  11700. if((atoi(value) == 0) || (atoi(value) >= 10))
  11701. {
  11702. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11703. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11704. isSuccess = ConfigurationStatus_Accepted;
  11705. }
  11706. else
  11707. isSuccess = ConfigurationStatus_Rejected;
  11708. }
  11709. }
  11710. else
  11711. {
  11712. isSuccess = ConfigurationStatus_Rejected;
  11713. }
  11714. }
  11715. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11716. {
  11717. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11718. {
  11719. check_ascii = value[0];
  11720. if( (check_ascii < 48) || (check_ascii > 57) )
  11721. {
  11722. isSuccess = ConfigurationStatus_Rejected;
  11723. }
  11724. else
  11725. {
  11726. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11727. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11728. isSuccess = ConfigurationStatus_Accepted;
  11729. }
  11730. }
  11731. else
  11732. {
  11733. isSuccess = ConfigurationStatus_Rejected;
  11734. }
  11735. }
  11736. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11737. {
  11738. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11739. {
  11740. check_ascii = value[0];
  11741. if( (check_ascii < 48) || (check_ascii > 57) )
  11742. {
  11743. isSuccess = ConfigurationStatus_Rejected;
  11744. }
  11745. else
  11746. {
  11747. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11748. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11749. isSuccess = ConfigurationStatus_Accepted;
  11750. }
  11751. }
  11752. else
  11753. {
  11754. isSuccess = ConfigurationStatus_Rejected;
  11755. }
  11756. }
  11757. if(strcmp(key, "HeartbeatInterval") == 0)
  11758. {
  11759. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11760. {
  11761. check_ascii = value[0];
  11762. if( (check_ascii < 48) || (check_ascii > 57) )
  11763. {
  11764. isSuccess = ConfigurationStatus_Rejected;
  11765. }
  11766. else
  11767. {
  11768. if((atoi(value) == 0) || (atoi(value) >= 10))
  11769. {
  11770. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11771. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11772. HeartBeatWaitTime = atoi(value);
  11773. isSuccess = ConfigurationStatus_Accepted;
  11774. }
  11775. else
  11776. {
  11777. isSuccess = ConfigurationStatus_Rejected;
  11778. }
  11779. }
  11780. }
  11781. else
  11782. {
  11783. isSuccess = ConfigurationStatus_Rejected;
  11784. }
  11785. }
  11786. if(strcmp(key, "LightIntensity") == 0)
  11787. {
  11788. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11789. {
  11790. check_ascii = value[0];
  11791. if( (check_ascii < 48) || (check_ascii > 57) )
  11792. {
  11793. isSuccess = ConfigurationStatus_Rejected;
  11794. }
  11795. else
  11796. {
  11797. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  11798. isSuccess = ConfigurationStatus_Accepted;
  11799. }
  11800. }
  11801. else
  11802. {
  11803. isSuccess = ConfigurationStatus_Rejected;
  11804. }
  11805. }
  11806. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  11807. {
  11808. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11809. {
  11810. strcpy(str, (const char*)value);
  11811. for(int i = 0; str[i]; i++)
  11812. {
  11813. str[i] = tolower(str[i]);
  11814. }
  11815. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11816. isSuccess = ConfigurationStatus_Accepted;
  11817. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11818. }
  11819. else
  11820. {
  11821. isSuccess = ConfigurationStatus_Rejected;
  11822. }
  11823. }
  11824. if(strcmp(key, "LocalPreAuthorize") == 0)
  11825. {
  11826. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11827. {
  11828. strcpy(str, (const char*)value);
  11829. for(int i = 0; str[i]; i++)
  11830. {
  11831. str[i] = tolower(str[i]);
  11832. }
  11833. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11834. isSuccess = ConfigurationStatus_Accepted;
  11835. }
  11836. else
  11837. {
  11838. isSuccess = ConfigurationStatus_Rejected;
  11839. }
  11840. }
  11841. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  11842. {
  11843. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11844. {
  11845. check_ascii = value[0];
  11846. if( (check_ascii < 48) || (check_ascii > 57) )
  11847. {
  11848. isSuccess = ConfigurationStatus_Rejected;
  11849. }
  11850. else
  11851. {
  11852. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  11853. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  11854. isSuccess = ConfigurationStatus_Accepted;
  11855. }
  11856. }
  11857. else
  11858. {
  11859. isSuccess = ConfigurationStatus_Rejected;
  11860. }
  11861. }
  11862. if(strcmp(key, "MeterValuesAlignedData") == 0)
  11863. {
  11864. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11865. {
  11866. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  11867. isSuccess = ConfigurationStatus_Accepted;
  11868. }
  11869. else
  11870. {
  11871. isSuccess = ConfigurationStatus_Rejected;
  11872. }
  11873. }
  11874. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  11875. {
  11876. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11877. {
  11878. check_ascii = value[0];
  11879. if( (check_ascii < 48) || (check_ascii > 57) )
  11880. {
  11881. isSuccess = ConfigurationStatus_Rejected;
  11882. }
  11883. else
  11884. {
  11885. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11886. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  11887. isSuccess = ConfigurationStatus_Accepted;
  11888. }
  11889. }
  11890. else
  11891. {
  11892. isSuccess = ConfigurationStatus_Rejected;
  11893. }
  11894. }
  11895. if(strcmp(key, "MeterValuesSampledData") == 0 )
  11896. {
  11897. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11898. {
  11899. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  11900. isSuccess = ConfigurationStatus_Accepted;
  11901. }
  11902. else
  11903. {
  11904. isSuccess = ConfigurationStatus_Rejected;
  11905. }
  11906. }
  11907. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  11908. {
  11909. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11910. {
  11911. check_ascii = value[0];
  11912. if( (check_ascii < 48) || (check_ascii > 57) )
  11913. {
  11914. isSuccess = ConfigurationStatus_Rejected;
  11915. }
  11916. else
  11917. {
  11918. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11919. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  11920. isSuccess = ConfigurationStatus_Accepted;
  11921. }
  11922. }
  11923. else
  11924. {
  11925. isSuccess = ConfigurationStatus_Rejected;
  11926. }
  11927. }
  11928. if(strcmp(key, "MeterValueSampleInterval") == 0)
  11929. {
  11930. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11931. {
  11932. check_ascii = value[0];
  11933. if( (check_ascii < 48) || (check_ascii > 57) )
  11934. {
  11935. isSuccess = ConfigurationStatus_Rejected;
  11936. }
  11937. else
  11938. {
  11939. if((atoi(value) == 0) || (atoi(value) >= 10))
  11940. {
  11941. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11942. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  11943. isSuccess = ConfigurationStatus_Accepted;
  11944. }
  11945. else
  11946. {
  11947. isSuccess = ConfigurationStatus_Rejected;
  11948. }
  11949. }
  11950. }
  11951. else
  11952. {
  11953. isSuccess = ConfigurationStatus_Rejected;
  11954. }
  11955. }
  11956. if(strcmp(key, "MinimumStatusDuration") == 0)
  11957. {
  11958. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11959. {
  11960. check_ascii = value[0];
  11961. if( (check_ascii < 48) || (check_ascii > 57) )
  11962. {
  11963. isSuccess = ConfigurationStatus_Rejected;
  11964. }
  11965. else
  11966. {
  11967. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  11968. {
  11969. isSuccess = ConfigurationStatus_Rejected;
  11970. }
  11971. else
  11972. {
  11973. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  11974. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  11975. server_cycle_Status = atoi(value); //StatusNotification Cycle
  11976. isSuccess = ConfigurationStatus_Accepted;
  11977. }
  11978. }
  11979. }
  11980. else
  11981. {
  11982. isSuccess = ConfigurationStatus_Rejected;
  11983. }
  11984. }
  11985. if(strcmp(key, "NumberOfConnectors") == 0)
  11986. {
  11987. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11988. {
  11989. check_ascii = value[0];
  11990. if( (check_ascii < 48) || (check_ascii > 57) )
  11991. {
  11992. isSuccess = ConfigurationStatus_Rejected;
  11993. }
  11994. else
  11995. {
  11996. //Charger.ResetRetries = Integer.parseInt(value);
  11997. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  11998. isSuccess = ConfigurationStatus_Accepted;
  11999. }
  12000. }
  12001. else
  12002. {
  12003. isSuccess = ConfigurationStatus_Rejected;
  12004. }
  12005. }
  12006. if(strcmp(key, "ResetRetries") == 0)
  12007. {
  12008. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12009. {
  12010. check_ascii = value[0];
  12011. if( (check_ascii < 48) || (check_ascii > 57) )
  12012. {
  12013. isSuccess = ConfigurationStatus_Rejected;
  12014. }
  12015. else
  12016. {
  12017. //Charger.ResetRetries = Integer.parseInt(value);
  12018. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  12019. isSuccess = ConfigurationStatus_Accepted;
  12020. }
  12021. }
  12022. else
  12023. {
  12024. isSuccess = ConfigurationStatus_Rejected;
  12025. }
  12026. }
  12027. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  12028. {
  12029. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12030. {
  12031. strcpy(str, (const char*)value);
  12032. for(int i = 0; str[i]; i++)
  12033. {
  12034. str[i] = tolower(str[i]);
  12035. }
  12036. if(strcmp(str, "notapplicable")== 0)
  12037. {
  12038. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12039. isSuccess = ConfigurationStatus_Accepted;
  12040. }
  12041. else if(strcmp(str, "unknown")== 0)
  12042. {
  12043. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12044. isSuccess = ConfigurationStatus_Accepted;
  12045. }
  12046. else if(strcmp(str, "rst")== 0)
  12047. {
  12048. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12049. isSuccess = ConfigurationStatus_Accepted;
  12050. }
  12051. else if(strcmp(str, "rts")== 0)
  12052. {
  12053. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12054. isSuccess = ConfigurationStatus_Accepted;
  12055. }
  12056. else if(strcmp(str, "srt")== 0)
  12057. {
  12058. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12059. isSuccess = ConfigurationStatus_Accepted;
  12060. }
  12061. else if(strcmp(str, "str")== 0)
  12062. {
  12063. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12064. isSuccess = ConfigurationStatus_Accepted;
  12065. }
  12066. else if(strcmp(str, "trs")== 0)
  12067. {
  12068. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12069. isSuccess = ConfigurationStatus_Accepted;
  12070. }
  12071. else if(strcmp(str, "tsr")== 0)
  12072. {
  12073. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12074. isSuccess = ConfigurationStatus_Accepted;
  12075. }
  12076. else
  12077. {
  12078. isSuccess = ConfigurationStatus_Rejected;
  12079. }
  12080. }
  12081. else
  12082. {
  12083. isSuccess = ConfigurationStatus_Rejected;
  12084. }
  12085. }
  12086. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12087. {
  12088. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12089. {
  12090. check_ascii = value[0];
  12091. if( (check_ascii < 48) || (check_ascii > 57) )
  12092. {
  12093. isSuccess = ConfigurationStatus_Rejected;
  12094. }
  12095. else
  12096. {
  12097. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12098. isSuccess = ConfigurationStatus_Accepted;
  12099. }
  12100. }
  12101. else
  12102. {
  12103. isSuccess = ConfigurationStatus_Rejected;
  12104. }
  12105. }
  12106. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12107. {
  12108. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12109. {
  12110. strcpy(str, (const char*)value);
  12111. for(int i = 0; str[i]; i++)
  12112. {
  12113. str[i] = tolower(str[i]);
  12114. }
  12115. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12116. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12117. isSuccess = ConfigurationStatus_Accepted;
  12118. }
  12119. else
  12120. {
  12121. isSuccess = ConfigurationStatus_Rejected;
  12122. }
  12123. }
  12124. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12125. {
  12126. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12127. {
  12128. strcpy(str, (const char*)value);
  12129. for(int i = 0; str[i]; i++)
  12130. {
  12131. str[i] = tolower(str[i]);
  12132. }
  12133. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12134. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12135. isSuccess = ConfigurationStatus_Accepted;
  12136. }
  12137. else
  12138. {
  12139. isSuccess = ConfigurationStatus_Rejected;
  12140. }
  12141. }
  12142. if(strcmp(key, "StopTxnAlignedData") == 0)
  12143. {
  12144. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12145. {
  12146. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12147. isSuccess = ConfigurationStatus_Accepted;
  12148. }
  12149. else
  12150. {
  12151. isSuccess = ConfigurationStatus_Rejected;
  12152. }
  12153. }
  12154. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12155. {
  12156. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12157. {
  12158. check_ascii = value[0];
  12159. if( (check_ascii < 48) || (check_ascii > 57) )
  12160. {
  12161. isSuccess = ConfigurationStatus_Rejected;
  12162. }
  12163. else
  12164. {
  12165. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12166. isSuccess = ConfigurationStatus_Accepted;
  12167. }
  12168. }
  12169. else
  12170. {
  12171. isSuccess = ConfigurationStatus_Rejected;
  12172. }
  12173. }
  12174. if(strcmp(key, "StopTxnSampledData") == 0)
  12175. {
  12176. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12177. {
  12178. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12179. isSuccess = ConfigurationStatus_Accepted;
  12180. }
  12181. else
  12182. {
  12183. isSuccess = ConfigurationStatus_Rejected;
  12184. }
  12185. }
  12186. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12187. {
  12188. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12189. {
  12190. check_ascii = value[0];
  12191. if( (check_ascii < 48) || (check_ascii > 57) )
  12192. {
  12193. isSuccess = ConfigurationStatus_Rejected;
  12194. }
  12195. else
  12196. {
  12197. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12198. isSuccess = ConfigurationStatus_Accepted;
  12199. }
  12200. }
  12201. else
  12202. {
  12203. isSuccess = ConfigurationStatus_Rejected;
  12204. }
  12205. }
  12206. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12207. {
  12208. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12209. {
  12210. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12211. isSuccess = ConfigurationStatus_Accepted;
  12212. }
  12213. else
  12214. {
  12215. isSuccess = ConfigurationStatus_Rejected;
  12216. }
  12217. }
  12218. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12219. {
  12220. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12221. {
  12222. check_ascii = value[0];
  12223. if( (check_ascii < 48) || (check_ascii > 57) )
  12224. {
  12225. isSuccess = ConfigurationStatus_Rejected;
  12226. }
  12227. else
  12228. {
  12229. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12230. isSuccess = ConfigurationStatus_Accepted;
  12231. }
  12232. }
  12233. else
  12234. {
  12235. isSuccess = ConfigurationStatus_Rejected;
  12236. }
  12237. }
  12238. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12239. {
  12240. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12241. {
  12242. check_ascii = value[0];
  12243. if( (check_ascii < 48) || (check_ascii > 57) )
  12244. {
  12245. isSuccess = ConfigurationStatus_Rejected;
  12246. }
  12247. else
  12248. {
  12249. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12250. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12251. TransactionMessageAttemptsValue = atoi(value);
  12252. isSuccess = ConfigurationStatus_Accepted;
  12253. }
  12254. }
  12255. else
  12256. {
  12257. isSuccess = ConfigurationStatus_Rejected;
  12258. }
  12259. }
  12260. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12261. {
  12262. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12263. {
  12264. check_ascii = value[0];
  12265. if( (check_ascii < 48) || (check_ascii > 57) )
  12266. {
  12267. isSuccess = ConfigurationStatus_Rejected;
  12268. }
  12269. else
  12270. {
  12271. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12272. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12273. TransactionMessageRetryIntervalValue = atoi(value);
  12274. isSuccess = ConfigurationStatus_Accepted;
  12275. }
  12276. }
  12277. else
  12278. {
  12279. isSuccess = ConfigurationStatus_Rejected;
  12280. }
  12281. }
  12282. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12283. {
  12284. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12285. {
  12286. strcpy(str, (const char*)value);
  12287. for(int i = 0; str[i]; i++)
  12288. {
  12289. str[i] = tolower(str[i]);
  12290. }
  12291. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12292. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12293. isSuccess = ConfigurationStatus_Accepted;
  12294. }
  12295. else
  12296. {
  12297. isSuccess = ConfigurationStatus_Rejected;
  12298. }
  12299. }
  12300. if(strcmp(key, "WebSocketPingInterval") == 0)
  12301. {
  12302. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12303. {
  12304. check_ascii = value[0];
  12305. if( (check_ascii < 48) || (check_ascii > 57) )
  12306. {
  12307. isSuccess = ConfigurationStatus_Rejected;
  12308. }
  12309. else
  12310. {
  12311. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12312. isSuccess = ConfigurationStatus_Accepted;
  12313. }
  12314. }
  12315. else
  12316. {
  12317. isSuccess = ConfigurationStatus_Rejected;
  12318. }
  12319. }
  12320. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  12321. {
  12322. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12323. {
  12324. strcpy(str, (const char*)value);
  12325. for(int i = 0; str[i]; i++)
  12326. {
  12327. str[i] = tolower(str[i]);
  12328. }
  12329. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12330. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12331. isSuccess = ConfigurationStatus_Accepted;
  12332. }
  12333. else
  12334. {
  12335. isSuccess = ConfigurationStatus_Rejected;
  12336. }
  12337. }
  12338. #if 0
  12339. //For OCPP Test Case
  12340. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12341. {
  12342. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12343. {
  12344. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12345. isSuccess = ConfigurationStatus_Accepted;
  12346. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12347. }
  12348. else
  12349. {
  12350. isSuccess = ConfigurationStatus_Rejected;
  12351. }
  12352. }
  12353. #endif
  12354. #if 1
  12355. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12356. {
  12357. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12358. {
  12359. strcpy(str, (const char*)value);
  12360. for(int i = 0; str[i]; i++)
  12361. {
  12362. str[i] = tolower(str[i]);
  12363. }
  12364. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12365. isSuccess = ConfigurationStatus_Accepted;
  12366. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12367. }
  12368. else
  12369. {
  12370. isSuccess = ConfigurationStatus_Rejected;
  12371. }
  12372. }
  12373. #endif
  12374. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12375. {
  12376. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12377. {
  12378. check_ascii = value[0];
  12379. if( (check_ascii < 48) || (check_ascii > 57) )
  12380. {
  12381. isSuccess = ConfigurationStatus_Rejected;
  12382. }
  12383. else
  12384. {
  12385. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12386. isSuccess = ConfigurationStatus_Accepted;
  12387. }
  12388. }
  12389. else
  12390. {
  12391. isSuccess = ConfigurationStatus_Rejected;
  12392. }
  12393. }
  12394. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12395. {
  12396. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12397. {
  12398. check_ascii = value[0];
  12399. if( (check_ascii < 48) || (check_ascii > 57) )
  12400. {
  12401. isSuccess = ConfigurationStatus_Rejected;
  12402. }
  12403. else
  12404. {
  12405. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12406. isSuccess = ConfigurationStatus_Accepted;
  12407. }
  12408. }
  12409. else
  12410. {
  12411. isSuccess = ConfigurationStatus_Rejected;
  12412. }
  12413. }
  12414. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12415. {
  12416. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12417. {
  12418. strcpy(str, (const char*)value);
  12419. for(int i = 0; str[i]; i++)
  12420. {
  12421. str[i] = tolower(str[i]);
  12422. }
  12423. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12424. isSuccess = ConfigurationStatus_Accepted;
  12425. }
  12426. else
  12427. {
  12428. isSuccess = ConfigurationStatus_Rejected;
  12429. }
  12430. }
  12431. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12432. {
  12433. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12434. {
  12435. check_ascii = value[0];
  12436. if( (check_ascii < 48) || (check_ascii > 57) )
  12437. {
  12438. isSuccess = ConfigurationStatus_Rejected;
  12439. }
  12440. else
  12441. {
  12442. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12443. isSuccess = ConfigurationStatus_Accepted;
  12444. }
  12445. }
  12446. else
  12447. {
  12448. isSuccess = ConfigurationStatus_Rejected;
  12449. }
  12450. }
  12451. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12452. {
  12453. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12454. {
  12455. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12456. isSuccess = ConfigurationStatus_Accepted;
  12457. }
  12458. else
  12459. {
  12460. isSuccess = ConfigurationStatus_Rejected;
  12461. }
  12462. }
  12463. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12464. {
  12465. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12466. {
  12467. check_ascii = value[0];
  12468. if( (check_ascii < 48) || (check_ascii > 57) )
  12469. {
  12470. isSuccess = ConfigurationStatus_Rejected;
  12471. }
  12472. else
  12473. {
  12474. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12475. isSuccess = ConfigurationStatus_Accepted;
  12476. }
  12477. }
  12478. else
  12479. {
  12480. isSuccess = ConfigurationStatus_Rejected;
  12481. }
  12482. }
  12483. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12484. {
  12485. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12486. {
  12487. strcpy(str, (const char*)value);
  12488. for(int i = 0; str[i]; i++)
  12489. {
  12490. str[i] = tolower(str[i]);
  12491. }
  12492. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12493. isSuccess = ConfigurationStatus_Accepted;
  12494. }
  12495. else
  12496. {
  12497. isSuccess = ConfigurationStatus_Rejected;
  12498. }
  12499. }
  12500. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12501. {
  12502. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12503. {
  12504. check_ascii = value[0];
  12505. if( (check_ascii < 48) || (check_ascii > 57) )
  12506. {
  12507. isSuccess = ConfigurationStatus_Rejected;
  12508. }
  12509. else
  12510. {
  12511. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12512. isSuccess = ConfigurationStatus_Accepted;
  12513. }
  12514. }
  12515. else
  12516. {
  12517. isSuccess = ConfigurationStatus_Rejected;
  12518. }
  12519. }
  12520. return isSuccess;
  12521. }
  12522. int TransactionMessageAttemptsGet(void)
  12523. {
  12524. return TransactionMessageAttemptsValue;
  12525. }
  12526. int FirstHeartBeatResponse(void)
  12527. {
  12528. return FirstHeartBeat;
  12529. }
  12530. int TransactionMessageRetryIntervalGet(void)
  12531. {
  12532. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12533. }
  12534. int ReadHttpStatus(int sock)
  12535. {
  12536. //char c;
  12537. char buff[1024]="",*ptr=buff+1;
  12538. int bytes_received, status;
  12539. DEBUG_INFO("Begin Response ..\n");
  12540. while((bytes_received = recv(sock, ptr, 1, 0))){
  12541. if(bytes_received==-1){
  12542. perror("ReadHttpStatus");
  12543. exit(1);
  12544. }
  12545. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12546. ptr++;
  12547. }
  12548. *ptr=0;
  12549. ptr=buff+1;
  12550. sscanf(ptr,"%*s %d ", &status);
  12551. DEBUG_INFO("%s\n",ptr);
  12552. DEBUG_INFO("status=%d\n",status);
  12553. DEBUG_INFO("End Response ..\n");
  12554. return (bytes_received>0)?status:0;
  12555. }
  12556. //the only filed that it parsed is 'Content-Length'
  12557. int ParseHeader(int sock)
  12558. {
  12559. //char c;
  12560. char buff[1024]="",*ptr=buff+4;
  12561. int bytes_received;
  12562. DEBUG_INFO("Begin HEADER ..\n");
  12563. while((bytes_received = recv(sock, ptr, 1, 0))){
  12564. if(bytes_received==-1){
  12565. perror("Parse Header");
  12566. exit(1);
  12567. }
  12568. if(
  12569. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12570. (ptr[-1]=='\r') && (*ptr=='\n' )
  12571. ) break;
  12572. ptr++;
  12573. }
  12574. *ptr=0;
  12575. ptr=buff+4;
  12576. //printf("%s",ptr);
  12577. if(bytes_received){
  12578. ptr=strstr(ptr,"Content-Length:");
  12579. if(ptr){
  12580. sscanf(ptr,"%*s %d",&bytes_received);
  12581. }else
  12582. bytes_received=-1; //unknown size
  12583. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12584. }
  12585. DEBUG_INFO("End HEADER ..\n");
  12586. return bytes_received ;
  12587. }
  12588. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12589. {
  12590. char rmFileCmd[100]={0};
  12591. char FilePath[100]={0};
  12592. char ftpbuf[200];
  12593. int systemresult;
  12594. //DEBUG_INFO("filename=%s\n",filename);
  12595. //DEBUG_INFO("url=%s\n",url);
  12596. sprintf(FilePath,"/mnt/%s",filename);
  12597. if((access(FilePath,F_OK))!=-1)
  12598. {
  12599. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12600. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12601. system(rmFileCmd);
  12602. }
  12603. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12604. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12605. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12606. systemresult = system(ftpbuf);
  12607. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12608. if(systemresult != 0)
  12609. {
  12610. DEBUG_INFO("http DownLoad error!\n");
  12611. return FALSE;
  12612. }
  12613. return TRUE;
  12614. }
  12615. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12616. {
  12617. char rmFileCmd[100]={0};
  12618. char FilePath[100]={0};
  12619. char ftpbuf[200];
  12620. int systemresult;
  12621. //char temp[100];
  12622. sprintf(FilePath,"/mnt/%s",filename);
  12623. if((access(FilePath,F_OK))!=-1)
  12624. {
  12625. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12626. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12627. system(rmFileCmd);
  12628. }
  12629. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12630. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12631. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12632. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12633. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12634. systemresult = system(ftpbuf);
  12635. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12636. if(systemresult != 0)
  12637. {
  12638. printf("wget error!\n");
  12639. return FALSE;
  12640. }
  12641. return TRUE;
  12642. }
  12643. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12644. {
  12645. char rmFileCmd[100]={0};
  12646. char FilePath[100]={0};
  12647. char ftpbuf[200];
  12648. int systemresult;
  12649. //DEBUG_INFO("filename=%s\n",filename);
  12650. //DEBUG_INFO("url=%s\n",url);
  12651. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12652. if((access(FilePath,F_OK))!=-1)
  12653. {
  12654. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12655. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12656. system(rmFileCmd);
  12657. }
  12658. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12659. if(fp == NULL)
  12660. {
  12661. DEBUG_INFO("log is NULL\n");
  12662. return FALSE;
  12663. }
  12664. else
  12665. {
  12666. fprintf(fp, "%s\n", url);
  12667. fprintf(fp, "%s\n", filename);
  12668. fclose(fp);
  12669. }
  12670. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12671. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12672. systemresult = system(ftpbuf);
  12673. DEBUG_INFO("systemresult = %d\n",systemresult);
  12674. if(systemresult != 0)
  12675. {
  12676. DEBUG_INFO("http upload error!\n");
  12677. return FALSE;
  12678. }
  12679. return TRUE;
  12680. }
  12681. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12682. {
  12683. struct hostent* server;
  12684. char *IPbuffer;
  12685. char ftpbuf[200];
  12686. int systemresult;
  12687. // To retrieve host information
  12688. server = gethostbyname(location);
  12689. // To convert an Internet network
  12690. // address into ASCII string
  12691. IPbuffer = inet_ntoa(*((struct in_addr*)
  12692. server->h_addr_list[0]));
  12693. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12694. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12695. /* format : ftpput -u username -p passwd IP target source*/
  12696. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12697. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12698. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12699. systemresult = system(ftpbuf);
  12700. DEBUG_INFO("systemresult=%d\n",systemresult);
  12701. if(systemresult != 0)
  12702. {
  12703. DEBUG_INFO("ftpput error!\n");
  12704. return FALSE;
  12705. }
  12706. return TRUE;
  12707. }
  12708. /**
  12709. * Place the contents of the specified file into a memory buffer
  12710. *
  12711. * @param[in] filename The path and name of the file to read
  12712. * @param[out] filebuffer A pointer to the contents in memory
  12713. * @return status 0 success, 1 on failure
  12714. */
  12715. int get_file_contents(const char* filename, char** outbuffer) {
  12716. FILE* file = NULL;
  12717. long filesize;
  12718. const int blocksize = 1;
  12719. size_t readsize;
  12720. char* filebuffer;
  12721. // Open the file
  12722. file = fopen(filename, "r");
  12723. if (NULL == file)
  12724. {
  12725. printf("'%s' not opened\n", filename);
  12726. exit(EXIT_FAILURE);
  12727. }
  12728. // Determine the file size
  12729. fseek(file, 0, SEEK_END);
  12730. filesize = ftell(file);
  12731. rewind (file);
  12732. // Allocate memory for the file contents
  12733. filebuffer = (char*) malloc(sizeof(char) * filesize);
  12734. *outbuffer = filebuffer;
  12735. if (filebuffer == NULL)
  12736. {
  12737. fputs ("malloc out-of-memory", stderr);
  12738. exit(EXIT_FAILURE);
  12739. }
  12740. // Read in the file
  12741. readsize = fread(filebuffer, blocksize, filesize, file);
  12742. if (readsize != filesize)
  12743. {
  12744. fputs ("didn't read file completely",stderr);
  12745. exit(EXIT_FAILURE);
  12746. }
  12747. // Clean exit
  12748. fclose(file);
  12749. return EXIT_SUCCESS;
  12750. }
  12751. static int selectSqlCount = 0;
  12752. static int callback(void *data, int argc, char **argv, char **azColName){
  12753. int i;
  12754. //printf("%s: ", (const char*)data);
  12755. selectSqlCount = argc;
  12756. for(i = 0; i<argc; i++){
  12757. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  12758. }
  12759. //printf("\n");
  12760. return 0;
  12761. }
  12762. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  12763. //int i;
  12764. //printf("%s:\n", (const char*)data);
  12765. localversion = argv[5] ? atoi(argv[5]) : 0;
  12766. //printf("localversion=%d\n", localversion);
  12767. return 0;
  12768. }
  12769. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  12770. //int i;
  12771. //printf("%s:\n", (const char*)data);
  12772. //idTag
  12773. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  12774. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  12775. //parentIdTag
  12776. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  12777. //expir_date
  12778. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  12779. //status
  12780. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  12781. //version
  12782. idTagQuery.listVersionInt = atoi(argv[5]);
  12783. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  12784. return 0;
  12785. }
  12786. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  12787. {
  12788. // localversion = argv[5] ? atoi(argv[5]) : 0;
  12789. // printf("localversion=%d\n", localversion);
  12790. return 0;
  12791. }
  12792. //=========================================
  12793. // Sqlite3 related function
  12794. //=========================================
  12795. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  12796. {
  12797. for (int i = 0; i < n_columns; i++)
  12798. {
  12799. DEBUG_INFO("%s\t", col_values[i]);
  12800. }
  12801. DEBUG_INFO("\n");
  12802. return 0;
  12803. }
  12804. void OCPP_getListVerion()
  12805. {
  12806. int rc = 0;
  12807. // const char* data = "Callback function called";
  12808. char sql[100];
  12809. char zErrMsg[100];
  12810. memset(sql, 0, 100);
  12811. memset(zErrMsg, 0, 100);
  12812. strcpy(sql, "select * from ocpp_auth_local order by idx");
  12813. /* Execute SQL statement */
  12814. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  12815. if( rc != SQLITE_OK )
  12816. {
  12817. DEBUG_INFO("SQL error: %s", zErrMsg);
  12818. }
  12819. }
  12820. void OCPP_getIdTag(char idTag[])
  12821. {
  12822. int rc = 0;
  12823. // const char* data = "Callback function called";
  12824. char sql[100];
  12825. char zErrMsg[100];
  12826. memset(sql, 0, 100);
  12827. memset(zErrMsg, 0, 100);
  12828. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  12829. memset(&idTagQuery, 0, sizeof(idTagQuery));
  12830. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  12831. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12832. /* Execute SQL statement */
  12833. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  12834. if( rc != SQLITE_OK )
  12835. {
  12836. DEBUG_INFO("SQL error: %s", zErrMsg);
  12837. }
  12838. //return ver;
  12839. }
  12840. void OCPP_get_TableAuthlocalAllData(void)
  12841. {
  12842. int rc = 0;
  12843. char sql[100];
  12844. char zErrMsg[100];
  12845. memset(sql, 0, 100);
  12846. memset(zErrMsg, 0, 100);
  12847. sprintf(sql,"select * from ocpp_auth_local ");
  12848. /* Execute SQL statement */
  12849. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  12850. if( rc != SQLITE_OK )
  12851. {
  12852. DEBUG_INFO("SQL error: %s", zErrMsg);
  12853. }
  12854. //return ver;
  12855. }
  12856. int OCPP_cleanLocalList()
  12857. {
  12858. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  12859. char *errMsg = 0;
  12860. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  12861. if (SQLITE_OK != rc)
  12862. {
  12863. DEBUG_INFO("%s\n",errMsg);
  12864. return FALSE;
  12865. }
  12866. return TRUE;
  12867. }
  12868. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12869. {
  12870. int isSuccess = FALSE;
  12871. int ret = 0;
  12872. //const char* data = "Callback function called";
  12873. char sql[300];
  12874. char zErrMsg[200];
  12875. memset(sql, 0, 300);
  12876. memset(zErrMsg, 0, 200);
  12877. 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);
  12878. //* Execute SQL statement */
  12879. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  12880. if( ret != SQLITE_OK )
  12881. {
  12882. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12883. return isSuccess;
  12884. }
  12885. memset(sql, 0, 300);
  12886. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  12887. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  12888. if( ret != SQLITE_OK )
  12889. {
  12890. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12891. return isSuccess;
  12892. }
  12893. isSuccess = TRUE;
  12894. return isSuccess;
  12895. }
  12896. void OCPP_deleteIdTag(char idTag[])
  12897. {
  12898. //int ver = 0;
  12899. //int isSuccess = FALSE;
  12900. int rc = 0;
  12901. char sql[100];
  12902. char zErrMsg[100];
  12903. memset(sql, 0, 100);
  12904. memset(zErrMsg, 0, 100);
  12905. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  12906. //* Execute SQL statement */
  12907. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  12908. if( rc != SQLITE_OK )
  12909. {
  12910. DEBUG_INFO("SQL error: %s", zErrMsg);
  12911. }
  12912. }
  12913. int GetOcppServerURL()
  12914. {
  12915. int result = FALSE;
  12916. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  12917. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  12918. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  12919. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  12920. {
  12921. #if 1
  12922. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  12923. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12924. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12925. #endif
  12926. result = TRUE;
  12927. goto End;
  12928. }
  12929. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  12930. {
  12931. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  12932. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12933. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12934. result = TRUE;
  12935. goto End;
  12936. }
  12937. else
  12938. {
  12939. strcpy(OcppHost,"");
  12940. }
  12941. End:
  12942. return result;
  12943. }
  12944. int GetOcppPath()
  12945. {
  12946. int result = FALSE;
  12947. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  12948. {
  12949. if(OcppTempPath == NULL)
  12950. {
  12951. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12952. }
  12953. else
  12954. {
  12955. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12956. }
  12957. result = TRUE;
  12958. goto End;
  12959. }
  12960. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  12961. {
  12962. if(OcppTempPath == NULL)
  12963. {
  12964. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  12965. }
  12966. else
  12967. {
  12968. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  12969. }
  12970. result = TRUE;
  12971. goto End;
  12972. }
  12973. else
  12974. {
  12975. strcpy(OcppPath,"");
  12976. }
  12977. End:
  12978. return result;
  12979. }
  12980. int GetOcppPort()
  12981. {
  12982. return OcppPort;
  12983. }
  12984. int GetOcppConnStatus(void)
  12985. {
  12986. return ShmOCPP16Data->OcppConnStatus;
  12987. }
  12988. void SetOcppConnStatus(uint8_t status)
  12989. {
  12990. ShmOCPP16Data->OcppConnStatus = status;
  12991. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  12992. }
  12993. int GetHeartBeatWithNOResponse(void)
  12994. {
  12995. return HeartBeatWithNOResponse;
  12996. }
  12997. void SetHeartBeatWithNOResponse(void)
  12998. {
  12999. HeartBeatWithNOResponse = 0;
  13000. }
  13001. void GetStartTransactionIdTag(int gun_index)
  13002. {
  13003. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  13004. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13005. }
  13006. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  13007. {
  13008. char ch;
  13009. FILE *fptr1;
  13010. int temptransactionId;
  13011. char str[100]={0};
  13012. temptransactionId = 0;
  13013. if((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0'))
  13014. {
  13015. DEBUG_INFO("IdTag is empty.\n");
  13016. return temptransactionId;
  13017. }
  13018. /*------ Read the file ----------------*/
  13019. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  13020. if (!fptr1)
  13021. {
  13022. DEBUG_INFO("QueueTransactionId file open error.\n");
  13023. //printf(" File not found or unable to open the input file!!\n");
  13024. return temptransactionId;
  13025. }
  13026. ch=fgetc(fptr1);
  13027. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13028. rewind(fptr1);
  13029. if(ch!=EOF)
  13030. {
  13031. // printf("%c",ch);
  13032. while (fgets(str, 100, fptr1) != NULL)
  13033. {
  13034. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13035. if(str[0]=='\0')
  13036. {
  13037. break;
  13038. }
  13039. char *revbuf[8] = {0}; //存放分割後的子字串
  13040. int num = 0;//分割後子字串的個數
  13041. DEBUG_INFO("str: %s\n", str);
  13042. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  13043. DEBUG_INFO("revbuf[0]: %s\n", revbuf[0]);
  13044. DEBUG_INFO("revbuf[1]: %s\n", revbuf[1]);
  13045. DEBUG_INFO("revbuf[2]: %s\n", revbuf[2]);
  13046. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13047. {
  13048. if(isStopTransaction)
  13049. {
  13050. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  13051. {
  13052. temptransactionId = atoi(revbuf[2]);
  13053. break;
  13054. }
  13055. }
  13056. else
  13057. {
  13058. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13059. {
  13060. temptransactionId = atoi(revbuf[2]);
  13061. break;
  13062. }
  13063. }
  13064. }
  13065. }
  13066. }
  13067. else
  13068. DEBUG_INFO("EOF\n");
  13069. fclose(fptr1);
  13070. /*------- End of reading ---------------*/
  13071. return temptransactionId;
  13072. }
  13073. void SetTransactionIdZero(int transactionId)
  13074. {
  13075. char ch;
  13076. FILE *fptr1, *fptr2;
  13077. int temptransactionId = 0;
  13078. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13079. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13080. if (!fptr1)
  13081. {
  13082. //printf(" File not found or unable to open the input file!!\n");
  13083. return ;
  13084. }
  13085. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13086. if (!fptr2)
  13087. {
  13088. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  13089. fclose(fptr1);
  13090. return ;
  13091. }
  13092. ch=fgetc(fptr1);
  13093. rewind(fptr1);
  13094. if(ch!=EOF)
  13095. {
  13096. // copy all contents to the temporary file except the specific line
  13097. while (fgets(str, 100, fptr1) != NULL)
  13098. {
  13099. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13100. if(str[0]=='\0')
  13101. {
  13102. break;
  13103. }
  13104. char *revbuf[8] = {0};
  13105. int num = 0;
  13106. strcpy(strtemp, str);
  13107. splitstring(str,",",revbuf,&num);
  13108. if(revbuf[2][0] != '\0')
  13109. {
  13110. temptransactionId = atoi(revbuf[2]);
  13111. if(transactionId != temptransactionId)
  13112. {
  13113. fprintf(fptr2, "%s\n", strtemp);
  13114. }
  13115. }
  13116. }
  13117. }
  13118. fclose(fptr1);
  13119. fclose(fptr2);
  13120. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13121. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13122. /*------ Read the file ----------------*/
  13123. }
  13124. int InternetDisconnect(void)
  13125. {
  13126. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13127. }
  13128. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  13129. void storeTempStopTransaction(int gun_index)
  13130. {
  13131. char guid[37]={0};
  13132. int tempIndex = 0;
  13133. DEBUG_INFO("storeTempStopTransaction...\n");
  13134. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  13135. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  13136. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13137. if(gunType[gun_index] == 'J')
  13138. {
  13139. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13140. {
  13141. tempIndex = ((gun_index==2) ? 1: 0);
  13142. }
  13143. else
  13144. {
  13145. tempIndex = gun_index;
  13146. }
  13147. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13148. {
  13149. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13150. {
  13151. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  13152. }
  13153. }// END OF CHAdeMO_QUANTITY
  13154. }
  13155. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13156. {
  13157. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13158. {
  13159. tempIndex = ((gun_index==2) ? 1: 0);
  13160. }
  13161. else
  13162. {
  13163. tempIndex = gun_index;
  13164. }
  13165. for (int index = 0; index < CCS_QUANTITY; index++)
  13166. {
  13167. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13168. {
  13169. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  13170. }
  13171. }// END OF CCS_QUANTITY
  13172. }
  13173. else if(gunType[gun_index] == 'G')
  13174. {
  13175. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13176. {
  13177. tempIndex = ((gun_index==2) ? 1: 0);
  13178. }
  13179. else
  13180. {
  13181. tempIndex = gun_index;
  13182. }
  13183. for (int index = 0; index < GB_QUANTITY; index++)
  13184. {
  13185. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13186. {
  13187. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  13188. }
  13189. }// END OF GB_QUANTITY
  13190. }
  13191. else
  13192. {
  13193. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13194. {
  13195. tempIndex = 2;
  13196. }
  13197. else
  13198. {
  13199. tempIndex = gun_index;
  13200. }
  13201. for (int index = 0; index < AC_QUANTITY; index++)
  13202. {
  13203. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13204. {
  13205. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  13206. }
  13207. }// END OF AC_QUANTITY
  13208. }
  13209. //Stop Transaction Time
  13210. struct timeval tmnow;
  13211. struct tm *tm;
  13212. char buf[28];//, usec_buf[6];
  13213. gettimeofday(&tmnow, NULL);
  13214. time_t t;
  13215. t = time(NULL);
  13216. /*UTC time and date*/
  13217. tm = gmtime(&t);
  13218. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  13219. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  13220. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  13221. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13222. random_uuid(guid);
  13223. /***********************************transactionData******************************************************/
  13224. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  13225. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  13226. //=================================
  13227. //1. Transaction_Begin
  13228. //=================================
  13229. //============================== Energy.Active.Import.Interval ===========================================
  13230. //idx_sample=0;
  13231. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  13232. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  13233. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  13234. 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*/]);
  13235. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13236. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13237. {
  13238. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  13239. }
  13240. else
  13241. {
  13242. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  13243. }
  13244. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  13245. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13246. //=================================
  13247. //2. Transaction_End
  13248. //=================================
  13249. //2.1====================================== Current.Import L1 ==============================================
  13250. //idx_sample=1;
  13251. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  13252. if(gunType[gun_index] == 'J')
  13253. {
  13254. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13255. {
  13256. tempIndex = ((gun_index==2) ? 1: 0);
  13257. }
  13258. else
  13259. {
  13260. tempIndex = gun_index;
  13261. }
  13262. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13263. {
  13264. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13265. {
  13266. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13267. }
  13268. }// End of for CHAdeMO_QUANTITY
  13269. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13270. }
  13271. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13272. {
  13273. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13274. {
  13275. tempIndex = ((gun_index==2) ? 1: 0);
  13276. }
  13277. else
  13278. {
  13279. tempIndex = gun_index;
  13280. }
  13281. for (int index = 0; index < CCS_QUANTITY; index++)
  13282. {
  13283. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13284. {
  13285. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13286. }
  13287. }// End of for CCS_QUANTITY
  13288. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13289. }
  13290. else if(gunType[gun_index] == 'G')
  13291. {
  13292. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13293. {
  13294. tempIndex = ((gun_index==2) ? 1: 0);
  13295. }
  13296. else
  13297. {
  13298. tempIndex = gun_index;
  13299. }
  13300. for (int index = 0; index < GB_QUANTITY; index++)
  13301. {
  13302. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13303. {
  13304. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13305. }
  13306. }// End of for GB_QUANTITY
  13307. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13308. }
  13309. else
  13310. {
  13311. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13312. {
  13313. tempIndex = 2;
  13314. }
  13315. else
  13316. {
  13317. tempIndex = gun_index;
  13318. }
  13319. for (int index = 0; index < AC_QUANTITY; index++)
  13320. {
  13321. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13322. {
  13323. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  13324. }
  13325. }// End of for AC_QUANTITY
  13326. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13327. }
  13328. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13329. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  13330. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  13331. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13332. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  13333. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13334. //2.2===================================== Energy.Active.Import.Interval ==========================================
  13335. //idx_sample=2;
  13336. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13337. if(gunType[gun_index] == 'J')
  13338. {
  13339. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13340. {
  13341. tempIndex = ((gun_index==2) ? 1: 0);
  13342. }
  13343. else
  13344. {
  13345. tempIndex = gun_index;
  13346. }
  13347. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13348. {
  13349. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13350. {
  13351. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13352. }
  13353. }// END OF CHAdeMO_QUANTITY
  13354. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13355. }
  13356. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13357. {
  13358. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13359. {
  13360. tempIndex = ((gun_index==2) ? 1: 0);
  13361. }
  13362. else
  13363. {
  13364. tempIndex = gun_index;
  13365. }
  13366. for (int index = 0; index < CCS_QUANTITY; index++)
  13367. {
  13368. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13369. {
  13370. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13371. }
  13372. }// END OF CCS_QUANTITY
  13373. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13374. }
  13375. else if(gunType[gun_index] == 'G')
  13376. {
  13377. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13378. {
  13379. tempIndex = ((gun_index==2) ? 1: 0);
  13380. }
  13381. else
  13382. {
  13383. tempIndex = gun_index;
  13384. }
  13385. for (int index = 0; index < GB_QUANTITY; index++)
  13386. {
  13387. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13388. {
  13389. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13390. }
  13391. }// END OF GB_QUANTITY
  13392. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13393. }
  13394. else
  13395. {
  13396. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13397. {
  13398. tempIndex = 2;
  13399. }
  13400. else
  13401. {
  13402. tempIndex = gun_index;
  13403. }
  13404. for (int index = 0; index < AC_QUANTITY; index++)
  13405. {
  13406. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13407. {
  13408. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13409. }
  13410. }// END OF AC_QUANTITY
  13411. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13412. }
  13413. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13414. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  13415. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  13416. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13417. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  13418. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13419. //2.3====================================== Power.Active.Import =========================================
  13420. //idx_sample=3;
  13421. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13422. if(gunType[gun_index] == 'J')
  13423. {
  13424. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13425. {
  13426. tempIndex = ((gun_index==2) ? 1: 0);
  13427. }
  13428. else
  13429. {
  13430. tempIndex = gun_index;
  13431. }
  13432. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13433. {
  13434. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13435. {
  13436. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13437. }
  13438. } // End for CHAdeMO_QUANTITY
  13439. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13440. }
  13441. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13442. {
  13443. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13444. {
  13445. tempIndex = ((gun_index==2) ? 1: 0);
  13446. }
  13447. else
  13448. {
  13449. tempIndex = gun_index;
  13450. }
  13451. for (int index = 0; index < CCS_QUANTITY; index++)
  13452. {
  13453. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13454. {
  13455. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13456. }
  13457. } // END for CCS_QUANTITY
  13458. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13459. }
  13460. else if(gunType[gun_index] == 'G')
  13461. {
  13462. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13463. {
  13464. tempIndex = ((gun_index==2) ? 1: 0);
  13465. }
  13466. else
  13467. {
  13468. tempIndex = gun_index;
  13469. }
  13470. for (int index = 0; index < GB_QUANTITY; index++)
  13471. {
  13472. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13473. {
  13474. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13475. }
  13476. }// END for GB_QUANTITY
  13477. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13478. }
  13479. else
  13480. {
  13481. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13482. {
  13483. tempIndex = 2;
  13484. }
  13485. else
  13486. {
  13487. tempIndex = gun_index;
  13488. }
  13489. for (int index = 0; index < AC_QUANTITY; index++)
  13490. {
  13491. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13492. {
  13493. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13494. }
  13495. } // END for AC_QUANTITY
  13496. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13497. }
  13498. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13499. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  13500. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  13501. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13502. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  13503. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  13504. //2.4====================================== Voltage L1 ====================================================
  13505. //idx_sample=4;
  13506. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13507. if(gunType[gun_index] == 'J')
  13508. {
  13509. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13510. {
  13511. tempIndex = ((gun_index==2) ? 1: 0);
  13512. }
  13513. else
  13514. {
  13515. tempIndex = gun_index;
  13516. }
  13517. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13518. {
  13519. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13520. {
  13521. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13522. }
  13523. } // END OF FOR CHAdeMO_QUANTITY
  13524. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13525. }
  13526. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13527. {
  13528. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13529. {
  13530. tempIndex = ((gun_index==2) ? 1: 0);
  13531. }
  13532. else
  13533. {
  13534. tempIndex = gun_index;
  13535. }
  13536. for (int index = 0; index < CCS_QUANTITY; index++)
  13537. {
  13538. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13539. {
  13540. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13541. }
  13542. } // END OF FOR CCS_QUANTITY
  13543. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13544. }
  13545. else if(gunType[gun_index] == 'G')
  13546. {
  13547. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13548. {
  13549. tempIndex = ((gun_index==2) ? 1: 0);
  13550. }
  13551. else
  13552. {
  13553. tempIndex = gun_index;
  13554. }
  13555. for (int index = 0; index < GB_QUANTITY; index++)
  13556. {
  13557. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13558. {
  13559. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13560. }
  13561. } // END OF FOR GB_QUANTITY
  13562. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13563. }
  13564. else
  13565. {
  13566. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13567. {
  13568. tempIndex = 2;
  13569. }
  13570. else
  13571. {
  13572. tempIndex = gun_index;
  13573. }
  13574. for (int index = 0; index < AC_QUANTITY; index++)
  13575. {
  13576. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13577. {
  13578. 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
  13579. }
  13580. } // END OF FOR AC_QUANTITY
  13581. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13582. }
  13583. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13584. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  13585. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  13586. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13587. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  13588. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13589. //2.5============================================== SoC =========================================================
  13590. //idx_sample=5;
  13591. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13592. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13593. {
  13594. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13595. {
  13596. tempIndex = ((gun_index==2) ? 1: 0);
  13597. }
  13598. else
  13599. {
  13600. tempIndex = gun_index;
  13601. }
  13602. if(gunType[gun_index] == 'J')
  13603. {
  13604. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13605. {
  13606. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13607. {
  13608. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  13609. }
  13610. }
  13611. }
  13612. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13613. {
  13614. for (int index = 0; index < CCS_QUANTITY; index++)
  13615. {
  13616. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13617. {
  13618. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  13619. }
  13620. }
  13621. }
  13622. else if(gunType[gun_index] == 'G')
  13623. {
  13624. for (int index = 0; index < GB_QUANTITY; index++)
  13625. {
  13626. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13627. {
  13628. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  13629. }
  13630. }
  13631. }
  13632. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13633. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  13634. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  13635. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  13636. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  13637. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  13638. } // END FOR DC CASE
  13639. //2.6====================================== Current.Import L2 ==============================================
  13640. // idx_sample=6;
  13641. // AC 3 phase L2 current
  13642. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13643. {
  13644. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13645. {
  13646. tempIndex = 2;
  13647. }
  13648. else
  13649. {
  13650. tempIndex = gun_index;
  13651. }
  13652. for (int index = 0; index < AC_QUANTITY; index++)
  13653. {
  13654. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13655. {
  13656. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  13657. }
  13658. }// End of for AC_QUANTITY
  13659. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  13660. }
  13661. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13662. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  13663. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  13664. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  13665. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13666. //2.7====================================== Current.Import L3 ==============================================
  13667. // idx_sample=7;
  13668. // AC 3 phase L3 current
  13669. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13670. {
  13671. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13672. {
  13673. tempIndex = 2;
  13674. }
  13675. else
  13676. {
  13677. tempIndex = gun_index;
  13678. }
  13679. for (int index = 0; index < AC_QUANTITY; index++)
  13680. {
  13681. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13682. {
  13683. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  13684. }
  13685. }// End of for AC_QUANTITY
  13686. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  13687. }
  13688. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13689. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  13690. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  13691. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  13692. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13693. //2.9====================================== Voltage L2 ====================================================
  13694. //idx_sample=8;
  13695. // AC 3 phase L2 volatge
  13696. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13697. {
  13698. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13699. {
  13700. tempIndex = 2;
  13701. }
  13702. else
  13703. {
  13704. tempIndex = gun_index;
  13705. }
  13706. for (int index = 0; index < AC_QUANTITY; index++)
  13707. {
  13708. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13709. {
  13710. 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
  13711. }
  13712. } // END OF FOR AC_QUANTITY
  13713. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  13714. }
  13715. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13716. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  13717. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  13718. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  13719. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13720. //2.10====================================== Voltage L3 ====================================================
  13721. //idx_sample=9;
  13722. // AC 3 phase L3 volatge
  13723. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13724. {
  13725. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13726. {
  13727. tempIndex = 2;
  13728. }
  13729. else
  13730. {
  13731. tempIndex = gun_index;
  13732. }
  13733. for (int index = 0; index < AC_QUANTITY; index++)
  13734. {
  13735. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13736. {
  13737. 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
  13738. }
  13739. } // END OF FOR AC_QUANTITY
  13740. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  13741. }
  13742. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13743. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  13744. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  13745. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  13746. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13747. //======================================== Message create ==============================================
  13748. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13749. {
  13750. 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\"}]}]}]"
  13751. ,gun_index+1
  13752. ,MESSAGE_TYPE_CALL
  13753. ,guid
  13754. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13755. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13756. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13757. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13758. ,"PowerLoss"
  13759. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13760. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13761. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13762. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13763. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13764. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13765. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13766. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13767. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13768. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13769. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13770. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13771. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13772. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13773. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13774. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13775. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13776. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13777. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13778. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13779. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13780. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13781. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13782. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13783. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13784. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13785. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13786. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13787. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13788. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13789. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13790. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13791. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13792. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13793. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13794. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13795. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  13796. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  13797. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  13798. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  13799. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  13800. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  13801. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  13802. );
  13803. }
  13804. else
  13805. {
  13806. if(((ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'W')))
  13807. {
  13808. 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\"}]}]}]"
  13809. ,gun_index+1
  13810. ,MESSAGE_TYPE_CALL
  13811. ,guid
  13812. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13813. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13814. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13815. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13816. ,"PowerLoss"
  13817. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13818. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13819. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13820. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13821. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13822. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13823. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13824. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13825. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13826. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13827. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13828. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13829. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13830. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13831. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13832. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13833. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13834. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13835. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13836. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13837. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13838. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13839. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13840. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13841. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13842. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13843. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13844. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13845. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13846. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13847. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13848. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13849. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13850. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13851. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13852. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13853. );
  13854. }
  13855. else
  13856. {
  13857. 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\"}]}]}]"
  13858. ,gun_index+1
  13859. ,MESSAGE_TYPE_CALL
  13860. ,guid
  13861. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13862. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13863. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13864. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13865. ,"PowerLoss"
  13866. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13867. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13868. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13869. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13870. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13871. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13872. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13873. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13874. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13875. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13876. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13877. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13878. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13879. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13880. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13881. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13882. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13883. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13884. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13885. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13886. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13887. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13888. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13889. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13890. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13891. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13892. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13893. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13894. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13895. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13896. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13897. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13898. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13899. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13900. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13901. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13902. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value
  13903. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context
  13904. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format
  13905. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand
  13906. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase
  13907. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location
  13908. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit
  13909. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value
  13910. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context
  13911. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format
  13912. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand
  13913. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase
  13914. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location
  13915. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit
  13916. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value
  13917. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context
  13918. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format
  13919. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand
  13920. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase
  13921. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location
  13922. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit
  13923. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value
  13924. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context
  13925. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format
  13926. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand
  13927. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase
  13928. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location
  13929. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit
  13930. );
  13931. }
  13932. }
  13933. // Check File "TempStopTransaction" Exist
  13934. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  13935. {
  13936. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  13937. fclose(fopen("/Storage/OCPP/TempStopTransaction", "w"));
  13938. }
  13939. else
  13940. {
  13941. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  13942. FILE *log = fopen("/Storage/OCPP/TempStopTransaction", "w+");
  13943. if(log == NULL)
  13944. {
  13945. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  13946. return ;
  13947. }
  13948. else
  13949. {
  13950. fclose(log);
  13951. }
  13952. }
  13953. //Add TempStopTransaction | Update TempStopTransaction
  13954. // open file for writing
  13955. FILE *outfile;
  13956. outfile = fopen ("/Storage/OCPP/TempStopTransaction", "a");
  13957. //DEBUG_INFO("data = %s\n", queuedata);
  13958. fputs(queuedata, outfile);
  13959. fputs("\n", outfile);
  13960. fclose (outfile);
  13961. }
  13962. void checkTempStopTransaction(int gun_index)
  13963. {
  13964. FILE *fptr1;
  13965. char ch;
  13966. char str[QUEUE_MESSAGE_LENGTH]={0};
  13967. char guid[37]={0};
  13968. char tempdata[65]={0};
  13969. char connectorStr[2]={0};
  13970. fptr1 = fopen("/Storage/OCPP/TempStopTransaction", "r");
  13971. //TempStopTransaction格式: 槍號,StopTransaction封包
  13972. if (!fptr1)
  13973. {
  13974. //printf(" File not found or unable to open the input file!!\n");
  13975. return ;
  13976. }
  13977. ch=fgetc(fptr1);
  13978. //printf(" Now the content of the file %s is : \n",fname);
  13979. rewind(fptr1);
  13980. if(ch!=EOF)
  13981. {
  13982. // copy all contents to the temporary file except the specific line
  13983. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  13984. {
  13985. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13986. if(str[0]=='\0')
  13987. {
  13988. break;
  13989. }
  13990. //TempStopTransaction格式: 槍號,StopTransaction封包
  13991. strncpy(connectorStr, str, 1);
  13992. if(atoi(connectorStr) != (gun_index+1))
  13993. {
  13994. DEBUG_INFO("atoi(connectorStr) = %d\n", atoi(connectorStr));
  13995. return ;
  13996. }
  13997. //random_uuid(guid);
  13998. strncpy(guid, str+6, 36); //copy guid
  13999. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  14000. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  14001. {
  14002. DEBUG_INFO("StopTransaction mapitem pass\n");
  14003. }
  14004. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  14005. memset(str,0,ARRAY_SIZE(str));
  14006. }
  14007. }
  14008. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  14009. fclose(fptr1);
  14010. remove("/Storage/OCPP/TempStopTransaction"); // remove the original file
  14011. }
  14012. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  14013. {
  14014. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  14015. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  14016. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  14017. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  14018. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14019. }
  14020. int GetWebSocketPingInterval(void)
  14021. {
  14022. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14023. }
  14024. int GetServerSign(void)
  14025. {
  14026. return server_sign;
  14027. }
  14028. void SetServerSign(int value)
  14029. {
  14030. server_sign = value;
  14031. }
  14032. int GetBootNotificationInterval(void)
  14033. {
  14034. return BootNotificationInterval;
  14035. }
  14036. int GetInternetConn(void)
  14037. {
  14038. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  14039. }
  14040. void InitialSystemValue(void)
  14041. {
  14042. int connectorIndex = 0;
  14043. //int valueASCII = 0;
  14044. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14045. gunTotalNumber=0;
  14046. SystemInitial = 0;
  14047. localversion=0;
  14048. BootNotificationInterval = 0;
  14049. authorizeRetryTimes = 0;
  14050. GunStatusInterval = 10;
  14051. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14052. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14053. //Hear Beat
  14054. HeartBeatWithNOResponse = 0;
  14055. HeartBeatCountPerHour = 0;
  14056. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  14057. FirstHeartBeat = 0;
  14058. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  14059. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  14060. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  14061. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  14062. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  14063. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  14064. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  14065. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  14066. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  14067. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  14068. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  14069. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  14070. memset(gunType, 0, ARRAY_SIZE(gunType));
  14071. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14072. {
  14073. //check connector / socket type (index: 8, 9, 10)
  14074. for(int index=7; index <10 ; index++)
  14075. {
  14076. if(index != 8)
  14077. {
  14078. // DC Connector
  14079. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] >= 'A') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= 'Z'))
  14080. {
  14081. SystemInitial = SystemInitial + 1;
  14082. gunTotalNumber = gunTotalNumber + 1;
  14083. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14084. connectorIndex = connectorIndex + 1;
  14085. }
  14086. }
  14087. else
  14088. {
  14089. // AC Connector
  14090. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14091. {
  14092. SystemInitial = SystemInitial + 1;
  14093. gunTotalNumber = gunTotalNumber + 1;
  14094. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14095. connectorIndex = connectorIndex + 1;
  14096. }
  14097. }
  14098. }
  14099. //DEBUG_INFO("DC ...\n");
  14100. }
  14101. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  14102. {
  14103. //check connector / socket type (index: 8, 9, 10)
  14104. for(int index=7; index <10 ; index++)
  14105. {
  14106. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14107. {
  14108. SystemInitial = SystemInitial + 1;
  14109. gunTotalNumber = gunTotalNumber + 1;
  14110. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14111. connectorIndex = connectorIndex + 1;
  14112. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  14113. }
  14114. }
  14115. }
  14116. //Status && ConnectorPlugIn Setting
  14117. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14118. {
  14119. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  14120. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  14121. }
  14122. for (int index = 0; index < CCS_QUANTITY; index++)
  14123. {
  14124. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  14125. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  14126. }
  14127. for (int index = 0; index < GB_QUANTITY; index++)
  14128. {
  14129. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  14130. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  14131. }
  14132. for (int index = 0; index < AC_QUANTITY; index++)
  14133. {
  14134. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  14135. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  14136. }
  14137. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  14138. {
  14139. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14140. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  14141. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  14142. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  14143. }
  14144. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  14145. clientTime.Heartbeat=time((time_t*)NULL);
  14146. sleep(1);
  14147. }
  14148. void LWS_Send(char * str)
  14149. {
  14150. //=====================================================
  14151. // Check InternetConn 0: disconnected, 1: connected
  14152. //====================================================
  14153. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14154. {
  14155. DEBUG_INFO("offline now !!!\n");
  14156. return;
  14157. }
  14158. pthread_mutex_lock(&lock_send);
  14159. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14160. sprintf((char *)SendBuffer, "%s", str);
  14161. SendBufLen = strlen(str);
  14162. pthread_mutex_unlock(&lock_send);
  14163. lws_callback_on_writable(wsi_client);
  14164. //lws_service(context, 0);
  14165. //sleep(1);
  14166. }