MessageHandler.c 676 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251
  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, gun_index = %d\n", atoi(connectorStr), gun_index);
  13995. fclose(fptr1);
  13996. return ;
  13997. }
  13998. //random_uuid(guid);
  13999. strncpy(guid, str+6, 36); //copy guid
  14000. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  14001. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  14002. {
  14003. DEBUG_INFO("StopTransaction mapitem pass\n");
  14004. }
  14005. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  14006. memset(str,0,ARRAY_SIZE(str));
  14007. }
  14008. }
  14009. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  14010. fclose(fptr1);
  14011. remove("/Storage/OCPP/TempStopTransaction"); // remove the original file
  14012. }
  14013. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  14014. {
  14015. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  14016. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  14017. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  14018. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  14019. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14020. }
  14021. int GetWebSocketPingInterval(void)
  14022. {
  14023. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14024. }
  14025. int GetServerSign(void)
  14026. {
  14027. return server_sign;
  14028. }
  14029. void SetServerSign(int value)
  14030. {
  14031. server_sign = value;
  14032. }
  14033. int GetBootNotificationInterval(void)
  14034. {
  14035. return BootNotificationInterval;
  14036. }
  14037. int GetInternetConn(void)
  14038. {
  14039. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  14040. }
  14041. void InitialSystemValue(void)
  14042. {
  14043. int connectorIndex = 0;
  14044. //int valueASCII = 0;
  14045. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14046. gunTotalNumber=0;
  14047. SystemInitial = 0;
  14048. localversion=0;
  14049. BootNotificationInterval = 0;
  14050. authorizeRetryTimes = 0;
  14051. GunStatusInterval = 10;
  14052. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14053. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14054. //Hear Beat
  14055. HeartBeatWithNOResponse = 0;
  14056. HeartBeatCountPerHour = 0;
  14057. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  14058. FirstHeartBeat = 0;
  14059. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  14060. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  14061. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  14062. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  14063. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  14064. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  14065. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  14066. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  14067. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  14068. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  14069. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  14070. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  14071. memset(gunType, 0, ARRAY_SIZE(gunType));
  14072. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14073. {
  14074. //check connector / socket type (index: 8, 9, 10)
  14075. for(int index=7; index <10 ; index++)
  14076. {
  14077. if(index != 8)
  14078. {
  14079. // DC Connector
  14080. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] >= 'A') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= 'Z'))
  14081. {
  14082. SystemInitial = SystemInitial + 1;
  14083. gunTotalNumber = gunTotalNumber + 1;
  14084. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14085. connectorIndex = connectorIndex + 1;
  14086. }
  14087. }
  14088. else
  14089. {
  14090. // AC Connector
  14091. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14092. {
  14093. SystemInitial = SystemInitial + 1;
  14094. gunTotalNumber = gunTotalNumber + 1;
  14095. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14096. connectorIndex = connectorIndex + 1;
  14097. }
  14098. }
  14099. }
  14100. //DEBUG_INFO("DC ...\n");
  14101. }
  14102. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  14103. {
  14104. //check connector / socket type (index: 8, 9, 10)
  14105. for(int index=7; index <10 ; index++)
  14106. {
  14107. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14108. {
  14109. SystemInitial = SystemInitial + 1;
  14110. gunTotalNumber = gunTotalNumber + 1;
  14111. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14112. connectorIndex = connectorIndex + 1;
  14113. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  14114. }
  14115. }
  14116. }
  14117. //Status && ConnectorPlugIn Setting
  14118. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14119. {
  14120. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  14121. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  14122. }
  14123. for (int index = 0; index < CCS_QUANTITY; index++)
  14124. {
  14125. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  14126. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  14127. }
  14128. for (int index = 0; index < GB_QUANTITY; index++)
  14129. {
  14130. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  14131. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  14132. }
  14133. for (int index = 0; index < AC_QUANTITY; index++)
  14134. {
  14135. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  14136. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  14137. }
  14138. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  14139. {
  14140. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14141. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  14142. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  14143. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  14144. }
  14145. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  14146. clientTime.Heartbeat=time((time_t*)NULL);
  14147. sleep(1);
  14148. }
  14149. void LWS_Send(char * str)
  14150. {
  14151. //=====================================================
  14152. // Check InternetConn 0: disconnected, 1: connected
  14153. //====================================================
  14154. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14155. {
  14156. DEBUG_INFO("offline now !!!\n");
  14157. return;
  14158. }
  14159. pthread_mutex_lock(&lock_send);
  14160. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14161. sprintf((char *)SendBuffer, "%s", str);
  14162. SendBufLen = strlen(str);
  14163. pthread_mutex_unlock(&lock_send);
  14164. lws_callback_on_writable(wsi_client);
  14165. //lws_service(context, 0);
  14166. //sleep(1);
  14167. }