MessageHandler.c 676 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246
  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. system("yes|rm /tmp/*.json");
  499. system("cp /Storage/OCPP/*.json /tmp");
  500. /*
  501. * Search valid charging profile
  502. */
  503. //DEBUG_INFO("====================================\n");
  504. // Search tx profile
  505. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  506. if((access(profileFileName, F_OK))!=-1)
  507. {
  508. fp = fopen(profileFileName, "r");
  509. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  510. {
  511. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  512. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  513. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  514. }
  515. txProfile.ChargingProfileId = -1;
  516. txProfile.StackLevel = -1;
  517. while(getline(&line, &len, fp) != -1)
  518. {
  519. json_object *obj = NULL;
  520. obj = json_tokener_parse(line);
  521. if(is_error(obj))
  522. {
  523. DEBUG_ERROR("Parse txProfile from file error.\n");
  524. }
  525. else
  526. {
  527. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  528. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  529. )
  530. {
  531. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  532. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  533. )
  534. {
  535. struct tm tmFrom, tmTo;
  536. struct timeb tbFrom, tbTo;
  537. 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) &&
  538. (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))
  539. {
  540. tmFrom.tm_year -= 1900;
  541. tmFrom.tm_mon -= 1;
  542. tbFrom.time = mktime(&tmFrom);
  543. tmTo.tm_year -= 1900;
  544. tmTo.tm_mon -= 1;
  545. tbTo.time = mktime(&tmTo);
  546. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  547. {
  548. if(txProfile.ChargingProfileId == -1)
  549. DEBUG_INFO("TxProfile found.\n");
  550. else
  551. DEBUG_INFO("TxProfile updated.\n");
  552. // Required item
  553. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  554. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  555. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  556. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  557. 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++)
  558. {
  559. 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"));
  560. 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")));
  561. 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?
  562. 3:
  563. 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")));
  564. }
  565. // Optional item
  566. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  567. {
  568. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  569. }
  570. else
  571. {
  572. sprintf((char*)txProfile.ValidFrom, " ");
  573. }
  574. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  575. {
  576. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  577. }
  578. else
  579. {
  580. sprintf((char*)txProfile.ValidTo, " ");
  581. }
  582. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  583. {
  584. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  585. }
  586. else
  587. {
  588. sprintf((char*)txProfile.RecurrencyKind, " ");
  589. }
  590. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  591. {
  592. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  593. }
  594. else
  595. {
  596. txProfile.TransactionId = -1;
  597. }
  598. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  599. {
  600. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  601. }
  602. else
  603. {
  604. txProfile.ChargingSchedule.Duration = 86400;
  605. }
  606. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  607. {
  608. 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")));
  609. }
  610. else
  611. {
  612. 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));
  613. }
  614. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  615. {
  616. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  617. }
  618. else
  619. {
  620. txProfile.ChargingSchedule.MinChargingRate = -1;
  621. }
  622. }
  623. }
  624. }
  625. else
  626. {
  627. if(txProfile.ChargingProfileId == -1)
  628. DEBUG_INFO("TxProfile found.\n");
  629. else
  630. DEBUG_INFO("TxProfile updated.\n");
  631. // Required item
  632. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  633. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  634. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  635. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  636. 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++)
  637. {
  638. 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"));
  639. 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")));
  640. 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?
  641. 3:
  642. 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")));
  643. }
  644. // Optional item
  645. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  646. {
  647. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  648. }
  649. else
  650. {
  651. sprintf((char*)txProfile.ValidFrom, " ");
  652. }
  653. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  654. {
  655. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  656. }
  657. else
  658. {
  659. sprintf((char*)txProfile.ValidTo, " ");
  660. }
  661. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  662. {
  663. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  664. }
  665. else
  666. {
  667. sprintf((char*)txProfile.RecurrencyKind, " ");
  668. }
  669. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  670. {
  671. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  672. }
  673. else
  674. {
  675. txProfile.TransactionId = -1;
  676. }
  677. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  678. {
  679. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  680. }
  681. else
  682. {
  683. txProfile.ChargingSchedule.Duration = 86400;
  684. }
  685. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  686. {
  687. 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")));
  688. }
  689. else
  690. {
  691. 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));
  692. }
  693. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  694. {
  695. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  696. }
  697. else
  698. {
  699. txProfile.ChargingSchedule.MinChargingRate = -1;
  700. }
  701. }
  702. }
  703. }
  704. json_object_put(obj);
  705. }
  706. fclose(fp);
  707. /*
  708. if(txProfile.ChargingProfileId != -1)
  709. {
  710. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  711. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  712. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  713. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  714. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  715. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  716. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  717. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  718. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  719. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  720. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  721. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  722. {
  723. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  724. {
  725. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  726. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  727. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  728. }
  729. }
  730. }
  731. else
  732. DEBUG_INFO("TxProfile not found.\n");*/
  733. }
  734. // Search default tx profile
  735. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  736. if((access(profileFileName, F_OK))==-1)
  737. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  738. if((access(profileFileName, F_OK))!=-1)
  739. {
  740. fp = fopen(profileFileName, "r");
  741. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  742. {
  743. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  744. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  745. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  746. }
  747. defaultTxProfile.ChargingProfileId = -1;
  748. defaultTxProfile.StackLevel = -1;
  749. while(getline(&line, &len, fp) != -1)
  750. {
  751. json_object *obj = NULL;
  752. obj = json_tokener_parse(line);
  753. if(is_error(obj))
  754. {
  755. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  756. }
  757. else
  758. {
  759. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  760. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  761. )
  762. {
  763. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  764. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  765. )
  766. {
  767. struct tm tmFrom, tmTo;
  768. struct timeb tbFrom, tbTo;
  769. 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) &&
  770. (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))
  771. {
  772. tmFrom.tm_year -= 1900;
  773. tmFrom.tm_mon -= 1;
  774. tbFrom.time = mktime(&tmFrom);
  775. tmTo.tm_year -= 1900;
  776. tmTo.tm_mon -= 1;
  777. tbTo.time = mktime(&tmTo);
  778. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  779. {
  780. if(defaultTxProfile.ChargingProfileId == -1)
  781. DEBUG_INFO("TxDefaultProfile found.\n");
  782. else
  783. DEBUG_INFO("TxDefaultProfile updated.\n");
  784. // Required item
  785. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  786. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  787. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  788. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  789. 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++)
  790. {
  791. 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"));
  792. 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")));
  793. 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?
  794. 3:
  795. 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")));
  796. }
  797. // Optional item
  798. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  799. {
  800. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  801. }
  802. else
  803. {
  804. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  805. }
  806. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  807. {
  808. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  809. }
  810. else
  811. {
  812. sprintf((char*)defaultTxProfile.ValidTo, " ");
  813. }
  814. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  815. {
  816. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  817. }
  818. else
  819. {
  820. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  821. }
  822. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  823. {
  824. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  825. }
  826. else
  827. {
  828. defaultTxProfile.TransactionId = -1;
  829. }
  830. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  831. {
  832. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  833. }
  834. else
  835. {
  836. defaultTxProfile.ChargingSchedule.Duration = 86400;
  837. }
  838. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  839. {
  840. 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")));
  841. }
  842. else
  843. {
  844. 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));
  845. }
  846. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  847. {
  848. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  849. }
  850. else
  851. {
  852. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  853. }
  854. }
  855. }
  856. }
  857. else
  858. {
  859. if(defaultTxProfile.ChargingProfileId == -1)
  860. DEBUG_INFO("TxDefaultProfile found.\n");
  861. else
  862. DEBUG_INFO("TxDefaultProfile updated.\n");
  863. // Required item
  864. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  865. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  866. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  867. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  868. 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++)
  869. {
  870. 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"));
  871. 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")));
  872. 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?
  873. 3:
  874. 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")));
  875. }
  876. // Optional item
  877. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  878. {
  879. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  880. }
  881. else
  882. {
  883. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  884. }
  885. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  886. {
  887. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  888. }
  889. else
  890. {
  891. sprintf((char*)defaultTxProfile.ValidTo, " ");
  892. }
  893. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  894. {
  895. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  896. }
  897. else
  898. {
  899. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  900. }
  901. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  902. {
  903. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  904. }
  905. else
  906. {
  907. defaultTxProfile.TransactionId = -1;
  908. }
  909. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  910. {
  911. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  912. }
  913. else
  914. {
  915. defaultTxProfile.ChargingSchedule.Duration = 86400;
  916. }
  917. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  918. {
  919. 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")));
  920. }
  921. else
  922. {
  923. 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));
  924. }
  925. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  926. {
  927. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  928. }
  929. else
  930. {
  931. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  932. }
  933. }
  934. }
  935. }
  936. json_object_put(obj);
  937. }
  938. fclose(fp);
  939. /*
  940. if(defaultTxProfile.ChargingProfileId != -1)
  941. {
  942. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  943. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  944. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  945. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  946. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  947. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  948. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  949. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  950. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  951. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  952. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  953. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  954. {
  955. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  956. {
  957. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  958. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  959. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  960. }
  961. }
  962. }
  963. else
  964. DEBUG_INFO("TxDefaultProfile not found.\n");
  965. DEBUG_INFO("------------------------------------\n");*/
  966. }
  967. // Search max profile
  968. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  969. if((access(profileFileName, F_OK))!=-1)
  970. {
  971. fp = fopen(profileFileName, "r");
  972. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  973. {
  974. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  975. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  976. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  977. }
  978. maxProfile.ChargingProfileId = -1;
  979. maxProfile.StackLevel = -1;
  980. while(getline(&line, &len, fp) != -1)
  981. {
  982. json_object *obj = NULL;
  983. obj = json_tokener_parse(line);
  984. if(is_error(obj))
  985. {
  986. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  987. }
  988. else
  989. {
  990. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  991. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  992. )
  993. {
  994. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  995. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  996. )
  997. {
  998. struct tm tmFrom, tmTo;
  999. struct timeb tbFrom, tbTo;
  1000. 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) &&
  1001. (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))
  1002. {
  1003. tmFrom.tm_year -= 1900;
  1004. tmFrom.tm_mon -= 1;
  1005. tbFrom.time = mktime(&tmFrom);
  1006. tmTo.tm_year -= 1900;
  1007. tmTo.tm_mon -= 1;
  1008. tbTo.time = mktime(&tmTo);
  1009. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1010. {
  1011. if(maxProfile.ChargingProfileId == -1)
  1012. DEBUG_INFO("MaxProfile found.\n");
  1013. else
  1014. DEBUG_INFO("MaxProfile updated.\n");
  1015. // Required item
  1016. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1017. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1018. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1019. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1020. 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++)
  1021. {
  1022. 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"));
  1023. 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")));
  1024. 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?
  1025. 3:
  1026. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1027. }
  1028. // Optional item
  1029. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1030. {
  1031. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1032. }
  1033. else
  1034. {
  1035. sprintf((char*)maxProfile.ValidFrom, " ");
  1036. }
  1037. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1038. {
  1039. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1040. }
  1041. else
  1042. {
  1043. sprintf((char*)maxProfile.ValidTo, " ");
  1044. }
  1045. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1046. {
  1047. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1048. }
  1049. else
  1050. {
  1051. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1052. }
  1053. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1054. {
  1055. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1056. }
  1057. else
  1058. {
  1059. maxProfile.TransactionId = -1;
  1060. }
  1061. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1062. {
  1063. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1064. }
  1065. else
  1066. {
  1067. maxProfile.ChargingSchedule.Duration = 86400;
  1068. }
  1069. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1070. {
  1071. 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")));
  1072. }
  1073. else
  1074. {
  1075. 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));
  1076. }
  1077. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1078. {
  1079. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1080. }
  1081. else
  1082. {
  1083. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1084. }
  1085. }
  1086. }
  1087. }
  1088. else
  1089. {
  1090. if(maxProfile.ChargingProfileId == -1)
  1091. DEBUG_INFO("MaxProfile found.\n");
  1092. else
  1093. DEBUG_INFO("MaxProfile updated.\n");
  1094. // Required item
  1095. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1096. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1097. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1098. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1099. 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++)
  1100. {
  1101. 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"));
  1102. 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")));
  1103. 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?
  1104. 3:
  1105. 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")));
  1106. }
  1107. // Optional item
  1108. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1109. {
  1110. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1111. }
  1112. else
  1113. {
  1114. sprintf((char*)maxProfile.ValidFrom, " ");
  1115. }
  1116. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1117. {
  1118. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1119. }
  1120. else
  1121. {
  1122. sprintf((char*)maxProfile.ValidTo, " ");
  1123. }
  1124. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1125. {
  1126. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1127. }
  1128. else
  1129. {
  1130. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1131. }
  1132. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1133. {
  1134. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1135. }
  1136. else
  1137. {
  1138. maxProfile.TransactionId = -1;
  1139. }
  1140. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1141. {
  1142. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1143. }
  1144. else
  1145. {
  1146. maxProfile.ChargingSchedule.Duration = 86400;
  1147. }
  1148. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1149. {
  1150. 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")));
  1151. }
  1152. else
  1153. {
  1154. 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));
  1155. }
  1156. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1157. {
  1158. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1159. }
  1160. else
  1161. {
  1162. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1163. }
  1164. }
  1165. }
  1166. }
  1167. json_object_put(obj);
  1168. }
  1169. fclose(fp);
  1170. /*
  1171. if(maxProfile.ChargingProfileId !=-1)
  1172. {
  1173. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1174. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1175. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1176. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1177. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1178. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1179. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1180. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1181. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1182. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1183. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1184. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1185. {
  1186. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1187. {
  1188. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1189. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1190. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1191. }
  1192. }
  1193. }
  1194. else
  1195. DEBUG_INFO("MaxProfile not found.\n");
  1196. DEBUG_INFO("------------------------------------\n");*/
  1197. }
  1198. /*
  1199. * Align found profile start schedule & periods
  1200. */
  1201. //DEBUG_INFO("====================================\n");
  1202. /*
  1203. // For local test usage, force modify found profile start schedule info
  1204. 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);
  1205. 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);
  1206. 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);
  1207. */
  1208. if(txProfile.ChargingProfileId != -1)
  1209. {
  1210. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1211. {
  1212. if(txProfile.ChargingSchedule.Duration != -1)
  1213. {
  1214. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1215. 0:
  1216. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1217. }
  1218. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1219. {
  1220. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1221. {
  1222. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1223. 0:
  1224. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1225. if(idxPeriod > 0)
  1226. {
  1227. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1228. {
  1229. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1230. }
  1231. }
  1232. }
  1233. }
  1234. }
  1235. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1236. {
  1237. if(txProfile.ChargingSchedule.Duration != -1)
  1238. {
  1239. 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?
  1240. 0:
  1241. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1242. }
  1243. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1244. {
  1245. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1246. {
  1247. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (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?
  1248. 0:
  1249. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1250. if(idxPeriod > 0)
  1251. {
  1252. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1253. {
  1254. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1255. }
  1256. }
  1257. }
  1258. }
  1259. }
  1260. else
  1261. {
  1262. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1263. {
  1264. if(txProfile.ChargingSchedule.Duration != -1)
  1265. {
  1266. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1267. 0:
  1268. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1269. }
  1270. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1271. {
  1272. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1273. {
  1274. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1275. 0:
  1276. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1277. if(idxPeriod > 0)
  1278. {
  1279. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1280. {
  1281. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1282. }
  1283. }
  1284. }
  1285. }
  1286. }
  1287. else
  1288. {
  1289. if(txProfile.ChargingSchedule.Duration != -1)
  1290. {
  1291. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1292. 0:
  1293. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1294. }
  1295. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1296. {
  1297. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1298. {
  1299. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1300. 0:
  1301. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1302. if(idxPeriod > 0)
  1303. {
  1304. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1305. {
  1306. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1307. }
  1308. }
  1309. }
  1310. }
  1311. }
  1312. }
  1313. /*
  1314. DEBUG_INFO("txProfile after align.\n");
  1315. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1316. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1317. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1318. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1319. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1320. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1321. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1322. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1323. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1324. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1325. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1326. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1327. {
  1328. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1329. {
  1330. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1331. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1332. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1333. }
  1334. }*/
  1335. }
  1336. if(defaultTxProfile.ChargingProfileId != -1)
  1337. {
  1338. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1339. {
  1340. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1341. {
  1342. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1343. 0:
  1344. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1345. }
  1346. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1347. {
  1348. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1349. {
  1350. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1351. 0:
  1352. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1353. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1354. {
  1355. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1356. }
  1357. if(idxPeriod > 0)
  1358. {
  1359. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1360. {
  1361. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1362. }
  1363. }
  1364. }
  1365. }
  1366. }
  1367. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1368. {
  1369. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1370. {
  1371. 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?
  1372. 0:
  1373. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1374. }
  1375. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1376. {
  1377. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1378. {
  1379. 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?
  1380. 0:
  1381. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1382. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1383. {
  1384. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1385. }
  1386. if(idxPeriod > 0)
  1387. {
  1388. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1389. {
  1390. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1391. }
  1392. }
  1393. }
  1394. }
  1395. }
  1396. else
  1397. {
  1398. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1399. {
  1400. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1401. {
  1402. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1403. 0:
  1404. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1405. }
  1406. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1407. {
  1408. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1409. {
  1410. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1411. 0:
  1412. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1413. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1414. {
  1415. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1416. }
  1417. if(idxPeriod > 0)
  1418. {
  1419. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1420. {
  1421. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1422. }
  1423. }
  1424. }
  1425. }
  1426. }
  1427. else
  1428. {
  1429. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1430. {
  1431. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1432. 0:
  1433. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1434. }
  1435. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1436. {
  1437. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1438. {
  1439. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1440. 0:
  1441. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1442. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1443. {
  1444. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1445. }
  1446. if(idxPeriod > 0)
  1447. {
  1448. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1449. {
  1450. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1451. }
  1452. }
  1453. }
  1454. }
  1455. }
  1456. }
  1457. /*
  1458. DEBUG_INFO("defaultTxProfile after align.\n");
  1459. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1460. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1461. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1462. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1463. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1464. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1465. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1466. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1467. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1468. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1469. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1470. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1471. {
  1472. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1473. {
  1474. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1475. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1476. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1477. }
  1478. }
  1479. DEBUG_INFO("------------------------------------\n");*/
  1480. }
  1481. if(maxProfile.ChargingProfileId != -1)
  1482. {
  1483. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1484. {
  1485. if(maxProfile.ChargingSchedule.Duration != -1)
  1486. {
  1487. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1488. 0:
  1489. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1490. }
  1491. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1492. {
  1493. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1494. {
  1495. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1496. 0:
  1497. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1498. if(idxPeriod > 0)
  1499. {
  1500. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1501. {
  1502. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1503. }
  1504. }
  1505. }
  1506. }
  1507. }
  1508. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1509. {
  1510. if(maxProfile.ChargingSchedule.Duration != -1)
  1511. {
  1512. 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?
  1513. 0:
  1514. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1515. }
  1516. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1517. {
  1518. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1519. {
  1520. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (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?
  1521. 0:
  1522. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1523. if(idxPeriod > 0)
  1524. {
  1525. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1526. {
  1527. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1528. }
  1529. }
  1530. }
  1531. }
  1532. }
  1533. else
  1534. {
  1535. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1536. {
  1537. if(maxProfile.ChargingSchedule.Duration != -1)
  1538. {
  1539. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1540. 0:
  1541. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1542. }
  1543. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1544. {
  1545. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1546. {
  1547. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1548. 0:
  1549. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1550. if(idxPeriod > 0)
  1551. {
  1552. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1553. {
  1554. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1555. }
  1556. }
  1557. }
  1558. }
  1559. }
  1560. else
  1561. {
  1562. if(maxProfile.ChargingSchedule.Duration != -1)
  1563. {
  1564. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1565. 0:
  1566. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1567. }
  1568. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1569. {
  1570. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1571. {
  1572. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1573. 0:
  1574. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1575. if(idxPeriod > 0)
  1576. {
  1577. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1578. {
  1579. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1580. }
  1581. }
  1582. }
  1583. }
  1584. }
  1585. }
  1586. /*
  1587. DEBUG_INFO("MaxProfile after align.\n");
  1588. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1589. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1590. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1591. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1592. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1593. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1594. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1595. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1596. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1597. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1598. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1599. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1600. {
  1601. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1602. {
  1603. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1604. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1605. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1606. }
  1607. }
  1608. DEBUG_INFO("------------------------------------\n");*/
  1609. }
  1610. /*
  1611. * Merge to conposite schedule
  1612. */
  1613. //DEBUG_INFO("====================================\n");
  1614. // Find each profile period quantity
  1615. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1616. {
  1617. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1618. limitMax = idx+1;
  1619. }
  1620. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1621. {
  1622. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1623. limitDef = idx+1;
  1624. }
  1625. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1626. {
  1627. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1628. limitTx = idx+1;
  1629. }
  1630. // TxProfile found, composite schedule based on it
  1631. if(txProfile.ChargingProfileId != -1)
  1632. {
  1633. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  1634. {
  1635. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  1636. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  1637. (txProfile.ChargingSchedule.Duration > 0))
  1638. {
  1639. if(maxProfile.ChargingProfileId != -1)
  1640. {
  1641. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1642. {
  1643. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  1644. {
  1645. if((maxProfile.ChargingSchedule.Duration > 0))
  1646. {
  1647. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1648. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1649. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1650. }
  1651. else
  1652. {
  1653. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1654. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1655. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  1656. }
  1657. }
  1658. if(idxMaxPeriod == (limitMax-1))
  1659. {
  1660. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1661. {
  1662. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1663. {
  1664. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1665. compositePeriodIdx++;
  1666. }
  1667. else
  1668. {
  1669. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1670. }
  1671. }
  1672. }
  1673. }
  1674. }
  1675. else
  1676. {
  1677. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1678. {
  1679. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1680. compositePeriodIdx++;
  1681. }
  1682. else
  1683. {
  1684. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1685. }
  1686. }
  1687. }
  1688. if(idxTxPeriod == (limitTx-1))
  1689. {
  1690. if(defaultTxProfile.ChargingProfileId != -1)
  1691. {
  1692. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1693. {
  1694. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  1695. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  1696. (defaultTxProfile.ChargingSchedule.Duration>0))
  1697. {
  1698. if(maxProfile.ChargingProfileId != -1)
  1699. {
  1700. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1701. {
  1702. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1703. {
  1704. if((maxProfile.ChargingSchedule.Duration > 0))
  1705. {
  1706. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1707. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1708. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1709. }
  1710. else
  1711. {
  1712. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1713. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1714. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  1715. }
  1716. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1717. {
  1718. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1719. {
  1720. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1721. compositePeriodIdx++;
  1722. }
  1723. else
  1724. {
  1725. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1726. }
  1727. }
  1728. break;
  1729. }
  1730. }
  1731. }
  1732. else
  1733. {
  1734. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1735. {
  1736. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1737. compositePeriodIdx++;
  1738. }
  1739. else
  1740. {
  1741. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1742. }
  1743. }
  1744. }
  1745. }
  1746. }
  1747. }
  1748. }
  1749. }
  1750. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  1751. else if(defaultTxProfile.ChargingProfileId != -1)
  1752. {
  1753. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1754. {
  1755. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  1756. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  1757. (defaultTxProfile.ChargingSchedule.Duration > 0))
  1758. {
  1759. if(maxProfile.ChargingProfileId != -1)
  1760. {
  1761. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1762. {
  1763. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1764. {
  1765. if((maxProfile.ChargingSchedule.Duration > 0))
  1766. {
  1767. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1768. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1769. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  1770. }
  1771. else
  1772. {
  1773. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1774. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1775. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  1776. }
  1777. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1778. {
  1779. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1780. {
  1781. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1782. compositePeriodIdx++;
  1783. }
  1784. else
  1785. {
  1786. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1787. }
  1788. }
  1789. break;
  1790. }
  1791. }
  1792. }
  1793. else
  1794. {
  1795. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1796. {
  1797. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1798. compositePeriodIdx++;
  1799. }
  1800. else
  1801. {
  1802. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1803. }
  1804. }
  1805. }
  1806. }
  1807. }
  1808. // Fill other period by MaxProfile
  1809. if(maxProfile.ChargingProfileId != -1)
  1810. {
  1811. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1812. {
  1813. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1814. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1815. (maxProfile.ChargingSchedule.Duration > 0))
  1816. {
  1817. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  1818. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  1819. {
  1820. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  1821. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  1822. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1823. }
  1824. if((maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  1825. {
  1826. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.Duration;
  1827. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  1828. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1829. }
  1830. if(tmpPeriod.Limit != -1)
  1831. {
  1832. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1833. {
  1834. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1835. {
  1836. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1837. compositePeriodIdx++;
  1838. }
  1839. else
  1840. {
  1841. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1842. }
  1843. }
  1844. }
  1845. }
  1846. }
  1847. }
  1848. DEBUG_INFO("Composite schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1849. DEBUG_INFO("Composite schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1850. DEBUG_INFO("Composite rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1851. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1852. {
  1853. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1854. {
  1855. compositeProfile->ChargingProfileId = 1;
  1856. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1857. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1858. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1859. }
  1860. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1861. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1862. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1863. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1864. }
  1865. if(line)
  1866. free(line);
  1867. }
  1868. //==========================================
  1869. // Init all share memory
  1870. //==========================================
  1871. int InitShareMemory()
  1872. {
  1873. int result = PASS;
  1874. int MeterSMId;
  1875. //creat ShmSysConfigAndInfo
  1876. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  1877. {
  1878. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  1879. result = FAIL;
  1880. }
  1881. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1882. {
  1883. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  1884. result = FAIL;
  1885. }
  1886. else
  1887. {}
  1888. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  1889. {
  1890. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  1891. result = FAIL;
  1892. }
  1893. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1894. {
  1895. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  1896. result = FAIL;
  1897. }
  1898. else
  1899. {}
  1900. //creat ShmPsuData
  1901. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  1902. {
  1903. DEBUG_ERROR("shmget ShmPsuData NG\n");
  1904. result = FAIL;
  1905. }
  1906. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1907. {
  1908. DEBUG_ERROR("shmat ShmPsuData NG\n");
  1909. result = FAIL;
  1910. }
  1911. else
  1912. {}
  1913. //creat ShmOCPP16Data
  1914. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  1915. {
  1916. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  1917. result = FAIL;
  1918. }
  1919. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1920. {
  1921. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  1922. result = FAIL;
  1923. }
  1924. else
  1925. {}
  1926. /****************************** For Initial Settings************************************************/
  1927. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  1928. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  1929. // allocate Configuration memory address
  1930. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  1931. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  1932. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  1933. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  1934. //offline MeterValue Interval
  1935. TempMeterValueInterval = 0;
  1936. return result;
  1937. }
  1938. int ProcessShareMemory()
  1939. {
  1940. if(InitShareMemory() == FAIL)
  1941. {
  1942. DEBUG_ERROR("InitShareMemory NG\n");
  1943. if(ShmStatusCodeData!=NULL)
  1944. {
  1945. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  1946. }
  1947. sleep(5);
  1948. return FAIL;
  1949. }
  1950. return PASS;
  1951. }
  1952. //---------------------common routine---------------------------//
  1953. int isOFFline(void)
  1954. {
  1955. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  1956. {
  1957. if(TempMeterValueInterval >= 2 )
  1958. {
  1959. TempMeterValueInterval = 0;
  1960. return TRUE;
  1961. }
  1962. else
  1963. {
  1964. TempMeterValueInterval = TempMeterValueInterval+ 1;
  1965. return FALSE;
  1966. }
  1967. }
  1968. else
  1969. {
  1970. return FALSE;
  1971. }
  1972. }
  1973. //---------------------------------------------
  1974. // new:
  1975. // enum SYSTEM_STATUS
  1976. // {
  1977. // SYS_MODE_BOOTING = 0,
  1978. // SYS_MODE_IDLE = 1,
  1979. // SYS_MODE_AUTHORIZING = 2,
  1980. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  1981. // SYS_MODE_REASSIGN = 4,
  1982. // SYS_MODE_PREPARING = 5,
  1983. // SYS_MODE_PREPARE_FOR_EV = 6,
  1984. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  1985. // SYS_MODE_CHARGING = 8,
  1986. // SYS_MODE_TERMINATING = 9,
  1987. // SYS_MODE_COMPLETE = 10,
  1988. // SYS_MODE_ALARM = 11,
  1989. // SYS_MODE_FAULT = 12,
  1990. // SYS_MODE_RESERVATION = 13,
  1991. // SYS_MODE_BOOKING = 14,
  1992. // SYS_MODE_MAINTAIN = 15,
  1993. // SYS_MODE_DEBUG = 16,
  1994. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  1995. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  1996. // SYS_MODE_UPDATE = 19
  1997. // };
  1998. //
  1999. //
  2000. //-----------------------------------------
  2001. void CheckSystemValue(void)
  2002. {
  2003. uint8_t reqSampleMeter[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  2004. uint8_t reqClockAlignMeter[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  2005. char filenmae[100]={0};
  2006. char str[100]={0};
  2007. int tempIndex = 0;
  2008. //===============================
  2009. // send Heartbeat
  2010. //===============================
  2011. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2012. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2013. {
  2014. clientTime.Heartbeat=time((time_t*)NULL);
  2015. if(server_sign == TRUE)
  2016. {
  2017. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2018. }
  2019. else
  2020. {
  2021. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2022. }
  2023. }
  2024. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  2025. {
  2026. //parameter for test
  2027. sendHeartbeatRequest(0);
  2028. //==============================================
  2029. // Reset Waiting Time
  2030. //==============================================
  2031. clientTime.Heartbeat=time((time_t*)NULL);
  2032. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  2033. }
  2034. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2035. {
  2036. //===============================
  2037. // CSU Trigger Reset Conf
  2038. //===============================
  2039. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  2040. {
  2041. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  2042. }
  2043. //===============================
  2044. // CSU Trigger Authorize Request
  2045. //===============================
  2046. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2047. {
  2048. sendAuthorizeRequest(0);
  2049. authorizeRetryTimes = authorizeRetryTimes + 1;
  2050. if(authorizeRetryTimes < 3)
  2051. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2052. }
  2053. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  2054. {
  2055. authorizeRetryTimes = 0;
  2056. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  2057. server_sign = FALSE;
  2058. }
  2059. 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))
  2060. {
  2061. sendAuthorizeRequest(0);
  2062. }
  2063. //===============================
  2064. // CSU Trigger Smart Charging Profilw
  2065. //===============================
  2066. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2067. {
  2068. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index]);
  2069. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2070. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  2071. }
  2072. //==============================================
  2073. // Charger start transaction
  2074. //==============================================
  2075. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2076. {
  2077. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  2078. sendStartTransactionRequest(gun_index);
  2079. clientTime.StartTransaction = time((time_t*)NULL);
  2080. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2081. }
  2082. //==============================================
  2083. // Charger stop transaction
  2084. //==============================================
  2085. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2086. {
  2087. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  2088. sendStopTransactionRequest(gun_index);
  2089. clientTime.StopTransaction = time((time_t*)NULL);
  2090. }
  2091. //==============================================
  2092. // Charger status report
  2093. //==============================================
  2094. //--- Check Mode Change ---//
  2095. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2096. if(gunType[gun_index] == 'J')
  2097. {
  2098. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2099. {
  2100. tempIndex = ((gun_index==2) ? 1: 0);
  2101. }
  2102. else
  2103. {
  2104. tempIndex = gun_index;
  2105. }
  2106. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2107. {
  2108. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2109. {
  2110. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  2111. {
  2112. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2113. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2114. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2115. statusModeChage[gun_index] = TRUE;
  2116. }
  2117. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2118. {
  2119. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2120. if((access(filenmae,F_OK))!=-1)
  2121. {
  2122. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2123. sprintf(str,"rm -f %s",filenmae);
  2124. system(str);
  2125. }
  2126. }
  2127. #if 1 // for TempStopTransaction
  2128. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2129. {
  2130. checkTempStopTransaction(gun_index);
  2131. }
  2132. #endif
  2133. }
  2134. }
  2135. }
  2136. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2137. {
  2138. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2139. {
  2140. tempIndex = ((gun_index==2) ? 1: 0);
  2141. }
  2142. else
  2143. {
  2144. tempIndex = gun_index;
  2145. }
  2146. for (int index = 0; index < CCS_QUANTITY; index++)
  2147. {
  2148. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2149. {
  2150. 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]*/ )
  2151. {
  2152. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2153. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2154. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2155. statusModeChage[gun_index] = TRUE;
  2156. }
  2157. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2158. {
  2159. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2160. if((access(filenmae,F_OK))!=-1)
  2161. {
  2162. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2163. sprintf(str,"rm -f %s",filenmae);
  2164. system(str);
  2165. }
  2166. }
  2167. #if 1 // for TempStopTransaction
  2168. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2169. {
  2170. checkTempStopTransaction(gun_index);
  2171. }
  2172. #endif
  2173. }
  2174. }
  2175. }
  2176. else if(gunType[gun_index] == 'G')
  2177. {
  2178. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2179. {
  2180. tempIndex = ((gun_index==2) ? 1: 0);
  2181. }
  2182. else
  2183. {
  2184. tempIndex = gun_index;
  2185. }
  2186. for (int index = 0; index < GB_QUANTITY; index++)
  2187. {
  2188. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2189. {
  2190. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2191. {
  2192. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2193. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2194. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2195. statusModeChage[gun_index] = TRUE;
  2196. }
  2197. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2198. {
  2199. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2200. if((access(filenmae,F_OK))!=-1)
  2201. {
  2202. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2203. sprintf(str,"rm -f %s",filenmae);
  2204. system(str);
  2205. }
  2206. }
  2207. #if 1 // for TempStopTransaction
  2208. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2209. {
  2210. checkTempStopTransaction(gun_index);
  2211. }
  2212. #endif
  2213. }
  2214. }
  2215. }
  2216. else
  2217. {
  2218. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2219. {
  2220. tempIndex = 2;
  2221. }
  2222. else
  2223. {
  2224. tempIndex = gun_index;
  2225. }
  2226. for (int index = 0; index < AC_QUANTITY; index++)
  2227. {
  2228. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2229. {
  2230. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2231. {
  2232. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2233. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2234. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2235. statusModeChage[gun_index] = TRUE;
  2236. }
  2237. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2238. {
  2239. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2240. if((access(filenmae,F_OK))!=-1)
  2241. {
  2242. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2243. sprintf(str,"rm -f %s",filenmae);
  2244. system(str);
  2245. }
  2246. }
  2247. #if 1 // for TempStopTransaction
  2248. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2249. {
  2250. checkTempStopTransaction(gun_index);
  2251. }
  2252. #endif
  2253. }
  2254. }// END
  2255. }
  2256. if(isWebsocketSendable &&
  2257. (((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)))) )
  2258. {
  2259. if(SystemInitial > 0)
  2260. SystemInitial -= 1;
  2261. sendStatusNotificationRequest(gun_index);
  2262. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2263. statusModeChage[gun_index] = FALSE;
  2264. }
  2265. //==============================================
  2266. // Meter report
  2267. //==============================================
  2268. if(cpinitateMsg.bits[gun_index].TriggerMeterValue)
  2269. {
  2270. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  2271. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  2272. }
  2273. if(/*(server_sign == TRUE) &&(isOFFline() == TRUE) ||*/
  2274. (((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)))
  2275. {
  2276. //check Transaction active
  2277. if(gunType[gun_index] == 'J')
  2278. {
  2279. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2280. {
  2281. tempIndex = ((gun_index==2) ? 1: 0);
  2282. }
  2283. else
  2284. {
  2285. tempIndex = gun_index;
  2286. }
  2287. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2288. {
  2289. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2290. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2291. {
  2292. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2293. {
  2294. reqSampleMeter[gun_index] = 1;
  2295. }
  2296. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2297. {
  2298. reqClockAlignMeter[gun_index] = 1;
  2299. }
  2300. }
  2301. }// End for CHAdeMO
  2302. }
  2303. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2304. {
  2305. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2306. {
  2307. tempIndex = ((gun_index==2) ? 1: 0);
  2308. }
  2309. else
  2310. {
  2311. tempIndex = gun_index;
  2312. }
  2313. for (int index = 0; index < CCS_QUANTITY; index++)
  2314. {
  2315. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2316. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2317. {
  2318. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2319. {
  2320. reqSampleMeter[gun_index] = 1;
  2321. }
  2322. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2323. {
  2324. reqClockAlignMeter[gun_index] = 1;
  2325. }
  2326. }
  2327. } // End for CCS
  2328. }
  2329. else if(gunType[gun_index] == 'G')
  2330. {
  2331. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2332. {
  2333. tempIndex = ((gun_index==2) ? 1: 0);
  2334. }
  2335. else
  2336. {
  2337. tempIndex = gun_index;
  2338. }
  2339. for (int index = 0; index < GB_QUANTITY; index++)
  2340. {
  2341. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2342. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2343. {
  2344. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2345. {
  2346. reqSampleMeter[gun_index] = 1;
  2347. }
  2348. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2349. {
  2350. reqClockAlignMeter[gun_index] = 1;
  2351. }
  2352. }
  2353. }// End for GB
  2354. }
  2355. else
  2356. {
  2357. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2358. {
  2359. tempIndex = 2;
  2360. }
  2361. else
  2362. {
  2363. tempIndex = gun_index;
  2364. }
  2365. for (int index = 0; index < AC_QUANTITY; index++)
  2366. {
  2367. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2368. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2369. {
  2370. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2371. {
  2372. reqSampleMeter[gun_index] = 1;
  2373. }
  2374. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2375. {
  2376. reqClockAlignMeter[gun_index] = 1;
  2377. }
  2378. }
  2379. }//End for AC
  2380. }
  2381. if(reqSampleMeter[gun_index] == 1)
  2382. {
  2383. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  2384. storeTempStopTransaction(gun_index);
  2385. }
  2386. else if(reqClockAlignMeter[gun_index] == 1)
  2387. {
  2388. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2389. }
  2390. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2391. sleep(1);
  2392. }
  2393. //==============================================
  2394. // Check Connector reserved
  2395. //==============================================
  2396. //===============================
  2397. // Check if Reserve is expired
  2398. //===============================
  2399. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  2400. {
  2401. double diff_t;
  2402. struct tm tp;
  2403. // current time
  2404. time_t t = time(NULL);
  2405. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  2406. tp.tm_isdst = -1;
  2407. time_t utc = mktime(&tp);
  2408. diff_t = difftime(utc, t);
  2409. if(diff_t <= 0)
  2410. {
  2411. DEBUG_INFO("reserve expired.\n");
  2412. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  2413. }
  2414. }//END OF Check if Reserve is expired
  2415. //==========================================
  2416. // csu trigger FirmwareStatusNotificationReq
  2417. //==========================================
  2418. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  2419. {
  2420. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  2421. }
  2422. //==========================================
  2423. // csu trigger CancelReservationConf
  2424. //==========================================
  2425. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  2426. {
  2427. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  2428. }
  2429. //==========================================
  2430. // csu trigger ChangeAvailabilityConf
  2431. //==========================================
  2432. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  2433. {
  2434. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  2435. }
  2436. //==========================================
  2437. // csu trigger UnlockConnectorConf
  2438. //==========================================
  2439. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  2440. {
  2441. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  2442. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  2443. }
  2444. //==========================================
  2445. // csu trigger ReserveNowConf
  2446. //==========================================
  2447. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  2448. {
  2449. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  2450. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  2451. }
  2452. //==========================================
  2453. // csu trigger DataTransferReq
  2454. //==========================================
  2455. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2456. {
  2457. sendDataTransferRequest(gun_index);
  2458. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2459. }
  2460. }
  2461. }
  2462. //==========================================
  2463. // send request routine
  2464. //==========================================
  2465. int sendAuthorizeRequest(int gun_index)
  2466. {
  2467. mtrace();
  2468. int result = FAIL;
  2469. char message[100]={0};
  2470. char guid[37];
  2471. char tempdata[65]={0};
  2472. DEBUG_INFO("sendAuthorizeRequest...\n");
  2473. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  2474. //Local Authorize
  2475. if ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  2476. {
  2477. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  2478. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2479. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  2480. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  2481. result = PASS;
  2482. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2483. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2484. authorizeRetryTimes = 0;
  2485. return result;
  2486. }
  2487. 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))||
  2488. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  2489. {
  2490. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2491. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  2492. {
  2493. if(strcmp(idTagQuery.idTagstr,"") == 0)
  2494. {
  2495. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  2496. }
  2497. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  2498. {
  2499. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  2500. }
  2501. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  2502. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2503. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2504. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  2505. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  2506. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2507. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2508. authorizeRetryTimes = 0;
  2509. return result;
  2510. }
  2511. else
  2512. {
  2513. DEBUG_INFO("offline Local Authorization Pass !!!!\n");
  2514. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  2515. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2516. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  2517. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  2518. result = PASS;
  2519. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2520. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2521. authorizeRetryTimes = 0;
  2522. return result;
  2523. }
  2524. }
  2525. //initailize struct Authorize
  2526. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  2527. //get data from shared memory
  2528. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2529. random_uuid(guid);
  2530. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  2531. LWS_Send(message);
  2532. sprintf(tempdata, "Authorize,%d", gun_index);
  2533. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2534. {
  2535. result = PASS;
  2536. DEBUG_INFO("Authorize mapItem pass\n");
  2537. }
  2538. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2539. return result;
  2540. }
  2541. int sendBootNotificationRequest(void)
  2542. {
  2543. mtrace();
  2544. int result = FAIL;
  2545. char message[500]={0}, payload[700]={0};
  2546. char guid[37]={0};
  2547. char tempdata[65]={0};
  2548. /*
  2549. int IsGunCharging = FALSE;
  2550. //check Transaction active
  2551. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2552. {
  2553. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2554. {
  2555. IsGunCharging = TRUE;
  2556. }
  2557. }
  2558. for (int index = 0; index < CCS_QUANTITY; index++)
  2559. {
  2560. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2561. {
  2562. IsGunCharging = TRUE;
  2563. }
  2564. }
  2565. for (int index = 0; index < GB_QUANTITY; index++)
  2566. {
  2567. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2568. {
  2569. IsGunCharging = TRUE;
  2570. }
  2571. }
  2572. for (int index = 0; index < AC_QUANTITY; index++)
  2573. {
  2574. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2575. {
  2576. IsGunCharging = TRUE;
  2577. }
  2578. }
  2579. if(IsGunCharging == TRUE)
  2580. {
  2581. server_sign = TRUE;
  2582. return result;
  2583. }
  2584. */
  2585. // Fill BootNotification fields
  2586. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  2587. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  2588. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  2589. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2590. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  2591. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  2592. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  2593. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  2594. ShmOCPP16Data->ChargeBoxId
  2595. ,ShmSysConfigAndInfo->SysConfig.ModelName
  2596. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  2597. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  2598. ,ShmOCPP16Data->BootNotification.CpFwVersion
  2599. ,ShmOCPP16Data->BootNotification.CpIccid
  2600. ,ShmOCPP16Data->BootNotification.CpImsi);
  2601. random_uuid(guid);
  2602. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  2603. LWS_Send(message);
  2604. sprintf(tempdata, "BootNotification,0");
  2605. 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*/)
  2606. {
  2607. result = PASS;
  2608. }
  2609. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  2610. strcpy(queuedata,message);
  2611. return result;
  2612. }
  2613. int sendDataTransferRequest(int gun_index)
  2614. {
  2615. mtrace();
  2616. char message[1000]={0};
  2617. char guid[37]={0};
  2618. char tempdata[65]={0};
  2619. int result = FAIL;
  2620. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  2621. random_uuid(guid);
  2622. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  2623. MESSAGE_TYPE_CALL,
  2624. guid,
  2625. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  2626. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  2627. ShmOCPP16Data->DataTransfer[gun_index].Data);
  2628. LWS_Send(message);
  2629. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  2630. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2631. {
  2632. result = PASS;
  2633. DEBUG_INFO("DataTransfer mapItem pass\n");
  2634. }
  2635. return result;
  2636. }
  2637. int sendDiagnosticsStatusNotificationRequest(char *status)
  2638. {
  2639. mtrace();
  2640. int result = FAIL;
  2641. char message[110]={0};
  2642. char guid[37]={0};
  2643. char tempdata[65]={0};
  2644. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  2645. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  2646. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  2647. random_uuid(guid);
  2648. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  2649. LWS_Send(message);
  2650. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  2651. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2652. {
  2653. result = PASS;
  2654. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  2655. }
  2656. //#ifdef SystemLogMessage
  2657. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  2658. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2659. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  2660. //#endif
  2661. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  2662. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  2663. //record status
  2664. if(strcmp(status,"Idle")==0)
  2665. {
  2666. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  2667. }
  2668. else if(strcmp(status,"Uploaded")==0)
  2669. {
  2670. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  2671. }
  2672. else if(strcmp(status,"UploadFailed")==0)
  2673. {
  2674. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  2675. }
  2676. else if(strcmp(status,"Uploading")==0)
  2677. {
  2678. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  2679. }
  2680. return result;
  2681. }
  2682. int sendFirmwareStatusNotificationRequest(char *status)
  2683. {
  2684. mtrace();
  2685. int result = FAIL;
  2686. char message[110]={0};
  2687. char guid[37]={0};
  2688. char tempdata[65]={0};
  2689. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  2690. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  2691. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  2692. random_uuid(guid);
  2693. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  2694. LWS_Send(message);
  2695. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  2696. 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*/)
  2697. {
  2698. result = PASS;
  2699. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  2700. }
  2701. //#ifdef SystemLogMessage
  2702. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  2703. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2704. //#endif
  2705. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  2706. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  2707. //record status
  2708. if(strcmp(status,"Downloaded")==0)
  2709. {
  2710. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  2711. }
  2712. else if(strcmp(status,"DownloadFailed")==0)
  2713. {
  2714. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  2715. }
  2716. else if(strcmp(status,"Downloading")==0)
  2717. {
  2718. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  2719. }
  2720. else if(strcmp(status,"Idle")==0)
  2721. {
  2722. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  2723. }
  2724. else if(strcmp(status,"InstallationFailed")==0)
  2725. {
  2726. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  2727. }
  2728. else if(strcmp(status,"Installing")==0)
  2729. {
  2730. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  2731. }
  2732. else if(strcmp(status,"Installed")==0)
  2733. {
  2734. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  2735. }
  2736. return result;
  2737. }
  2738. int sendHeartbeatRequest(int gun_index)
  2739. {
  2740. mtrace();
  2741. int result = FAIL;
  2742. char message[80]={0};
  2743. char guid[37]={0};
  2744. char tempdata[65]={0};
  2745. random_uuid(guid);
  2746. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  2747. , MESSAGE_TYPE_CALL
  2748. , guid );
  2749. LWS_Send(message);
  2750. sprintf(tempdata, "Heartbeat,%d", 0);
  2751. 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*/)
  2752. {
  2753. result = PASS;
  2754. }
  2755. return result;
  2756. }
  2757. int sendStartTransactionRequest(int gun_index)
  2758. {
  2759. mtrace();
  2760. int result = FAIL;
  2761. char message[250]={0};
  2762. char guid[37]={0};
  2763. struct timeval tmnow;
  2764. struct tm *tm;
  2765. char buf[28];//, usec_buf[6];
  2766. char tempdata[65]={0};
  2767. int tempIndex = 0;
  2768. DEBUG_INFO("sendStartTransactionRequest...\n");
  2769. gettimeofday(&tmnow, NULL);
  2770. time_t t;
  2771. t = time(NULL);
  2772. /*UTC time and date*/
  2773. tm = gmtime(&t);
  2774. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2775. #if 0 // remove temporally
  2776. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2777. strcat(buf,".");
  2778. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2779. strcat(buf,usec_buf);
  2780. #endif
  2781. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  2782. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  2783. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2784. // clear StartTransaction Response
  2785. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  2786. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  2787. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  2788. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  2789. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2790. if(gunType[gun_index] == 'J')
  2791. {
  2792. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2793. {
  2794. tempIndex = ((gun_index==2) ? 1: 0);
  2795. }
  2796. else
  2797. {
  2798. tempIndex = gun_index;
  2799. }
  2800. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2801. {
  2802. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2803. {
  2804. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  2805. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  2806. }
  2807. }
  2808. }
  2809. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2810. {
  2811. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2812. {
  2813. tempIndex = ((gun_index==2) ? 1: 0);
  2814. }
  2815. else
  2816. {
  2817. tempIndex = gun_index;
  2818. }
  2819. for (int index = 0; index < CCS_QUANTITY; index++)
  2820. {
  2821. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2822. {
  2823. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  2824. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  2825. }
  2826. }
  2827. }
  2828. else if(gunType[gun_index] == 'G')
  2829. {
  2830. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2831. {
  2832. tempIndex = ((gun_index==2) ? 1: 0);
  2833. }
  2834. else
  2835. {
  2836. tempIndex = gun_index;
  2837. }
  2838. for (int index = 0; index < GB_QUANTITY; index++)
  2839. {
  2840. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2841. {
  2842. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  2843. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  2844. }
  2845. }
  2846. }
  2847. else
  2848. {
  2849. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2850. {
  2851. tempIndex = 2;
  2852. }
  2853. else
  2854. {
  2855. tempIndex = gun_index;
  2856. }
  2857. for (int index = 0; index < AC_QUANTITY; index++)
  2858. {
  2859. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2860. {
  2861. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  2862. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  2863. }
  2864. }
  2865. }
  2866. random_uuid(guid);
  2867. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  2868. {
  2869. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  2870. , gun_index +1
  2871. , MESSAGE_TYPE_CALL
  2872. , guid
  2873. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  2874. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  2875. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  2876. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  2877. }
  2878. else
  2879. {
  2880. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  2881. , gun_index +1
  2882. , MESSAGE_TYPE_CALL
  2883. , guid
  2884. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  2885. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  2886. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  2887. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  2888. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  2889. }
  2890. #if 1
  2891. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  2892. 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*/)
  2893. {
  2894. result = PASS;
  2895. }
  2896. #endif
  2897. strcpy(queuedata, message);
  2898. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2899. /*
  2900. if(GetTransactionQueueNum() == 1)
  2901. {
  2902. LWS_Send(message + 2);
  2903. }*/
  2904. return result;
  2905. }
  2906. int sendStatusNotificationRequest(int gun_index)
  2907. {
  2908. mtrace();
  2909. int result = FAIL;
  2910. char message[600]={0};
  2911. char guid[37];
  2912. int currentStatus = 0;
  2913. struct timeval tmnow;
  2914. struct tm *tm;
  2915. char buf[28];//, usec_buf[6];
  2916. char tempdata[65]={0};
  2917. int tempIndex = 0;
  2918. gettimeofday(&tmnow, NULL);
  2919. time_t t;
  2920. t = time(NULL);
  2921. /*UTC time and date*/
  2922. tm = gmtime(&t);
  2923. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2924. #if 0 // remove temporally
  2925. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2926. strcat(buf,".");
  2927. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2928. strcat(buf,usec_buf);
  2929. #endif
  2930. printf("%s",buf);
  2931. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  2932. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  2933. // it's option
  2934. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  2935. /*
  2936. enum _SYSTEM_STATUS
  2937. {
  2938. S_BOOTING = 0,
  2939. S_IDLE, = 1
  2940. S_AUTHORIZING, =2
  2941. S_REASSIGN_CHECK, =3
  2942. S_REASSIGN, =4
  2943. S_PRECHARGE, =5
  2944. S_PREPARING_FOR_EV, =6
  2945. S_PREPARING_FOR_EVSE, =7
  2946. S_CHARGING, =8
  2947. S_TERMINATING, =9
  2948. S_COMPLETE, =10
  2949. S_ALARM, =11
  2950. S_FAULT =12
  2951. }
  2952. */
  2953. //check Transaction active
  2954. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2955. if(gunType[gun_index] == 'J')
  2956. {
  2957. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2958. {
  2959. tempIndex = ((gun_index==2) ? 1: 0);
  2960. }
  2961. else
  2962. {
  2963. tempIndex = gun_index;
  2964. }
  2965. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2966. {
  2967. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  2968. {
  2969. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  2970. {
  2971. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  2972. {
  2973. currentStatus = 1; //OCPP Status: Preparing
  2974. }
  2975. else
  2976. {
  2977. currentStatus = 0; //OCPP Status: Available
  2978. }
  2979. }
  2980. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  2981. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  2982. ) //S_PRECHARGE
  2983. {
  2984. currentStatus = 1; //OCPP Status: Preparing
  2985. }
  2986. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2987. {
  2988. currentStatus = 2; //OCPP Status: Charging
  2989. }
  2990. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  2991. {
  2992. currentStatus = 5; //OCPP Status: Finishing
  2993. }
  2994. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  2995. {
  2996. currentStatus = 4; //OCPP Status: SuspendedEV
  2997. }
  2998. 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
  2999. {
  3000. currentStatus = 7; //OCPP Status: Unavailable
  3001. }
  3002. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3003. {
  3004. currentStatus = 8; //OCPP Status: Faulted
  3005. }
  3006. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3007. {
  3008. currentStatus = 6; //OCPP Status: Reserved
  3009. }
  3010. } //end of the same index
  3011. }//end of for CHAdeMO_QUANTITY
  3012. }
  3013. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3014. {
  3015. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3016. {
  3017. tempIndex = ((gun_index==2) ? 1: 0);
  3018. }
  3019. else
  3020. {
  3021. tempIndex = gun_index;
  3022. }
  3023. for (int index = 0; index < CCS_QUANTITY; index++)
  3024. {
  3025. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3026. {
  3027. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3028. {
  3029. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3030. {
  3031. currentStatus = 1; //OCPP Status: Preparing
  3032. }
  3033. else
  3034. {
  3035. currentStatus = 0; //OCPP Status: Available
  3036. }
  3037. }
  3038. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3039. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3040. ) //S_PRECHARGE
  3041. {
  3042. currentStatus = 1; //OCPP Status: Preparing
  3043. }
  3044. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3045. {
  3046. currentStatus = 2; //OCPP Status: Charging
  3047. }
  3048. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3049. {
  3050. currentStatus = 5; //OCPP Status: Finishing
  3051. }
  3052. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3053. {
  3054. currentStatus = 4; //OCPP Status: SuspendedEV
  3055. }
  3056. 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
  3057. {
  3058. currentStatus = 7; //OCPP Status : Unavailable
  3059. }
  3060. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3061. {
  3062. currentStatus = 8; //OCPP Status: Faulted
  3063. }
  3064. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3065. {
  3066. currentStatus = 6; //OCPP Status: Reserved
  3067. }
  3068. } //end of the same index
  3069. } // end of for CCS_QUANTITY
  3070. }
  3071. else if(gunType[gun_index] == 'G')
  3072. {
  3073. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3074. {
  3075. tempIndex = ((gun_index==2) ? 1: 0);
  3076. }
  3077. else
  3078. {
  3079. tempIndex = gun_index;
  3080. }
  3081. for (int index = 0; index < GB_QUANTITY; index++)
  3082. {
  3083. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3084. {
  3085. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3086. {
  3087. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3088. {
  3089. currentStatus = 1; //OCPP Status: Preparing
  3090. }
  3091. else
  3092. {
  3093. currentStatus = 0; //OCPP Status: Available
  3094. }
  3095. }
  3096. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3097. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3098. ) //S_PRECHARGE
  3099. {
  3100. currentStatus = 1; //OCPP Status: Preparing
  3101. }
  3102. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3103. {
  3104. currentStatus = 2; //OCPP Status: Charging
  3105. }
  3106. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3107. {
  3108. currentStatus = 5; //OCPP Status: Finishing
  3109. }
  3110. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3111. {
  3112. currentStatus = 4; //OCPP Status: SuspendedEV
  3113. }
  3114. 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
  3115. {
  3116. currentStatus = 7; //OCPP Status: Unavailable
  3117. }
  3118. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3119. {
  3120. currentStatus = 8; //OCPP Status: Faulted
  3121. }
  3122. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3123. {
  3124. currentStatus = 6; //OCPP Status: Reserved
  3125. }
  3126. } //end of the same index
  3127. } // end of for GB_QUANTITY
  3128. }
  3129. else
  3130. {
  3131. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3132. {
  3133. tempIndex = 2;
  3134. }
  3135. else
  3136. {
  3137. tempIndex = gun_index;
  3138. }
  3139. for (int index = 0; index < AC_QUANTITY; index++)
  3140. {
  3141. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3142. {
  3143. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3144. {
  3145. 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))
  3146. {
  3147. currentStatus = 1; //OCPP Status: Preparing
  3148. }
  3149. else
  3150. {
  3151. currentStatus = 0; //OCPP Status: Available
  3152. }
  3153. }
  3154. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3155. {
  3156. currentStatus = 1; //OCPP Status: Preparing
  3157. }
  3158. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3159. {
  3160. currentStatus = 2; //OCPP Status: Charging
  3161. }
  3162. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3163. {
  3164. currentStatus = 5; //OCPP Status: Finishing
  3165. }
  3166. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3167. {
  3168. currentStatus = 4; //OCPP Status: SuspendedEV
  3169. }
  3170. 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
  3171. {
  3172. currentStatus = 7; //OCPP Status: Unavailable
  3173. }
  3174. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3175. {
  3176. currentStatus = 8; //OCPP Status: Faulted
  3177. }
  3178. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3179. {
  3180. currentStatus = 6; //OCPP Status: Reserved
  3181. }
  3182. }//end of the same index
  3183. }//end of for AC_QUANTITY
  3184. }
  3185. //it's option
  3186. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3187. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  3188. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3189. random_uuid(guid);
  3190. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3191. , MESSAGE_TYPE_CALL
  3192. , guid
  3193. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3194. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3195. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3196. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3197. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3198. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3199. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3200. if((server_sign == TRUE))
  3201. {
  3202. LWS_Send(message);
  3203. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3204. 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*/)
  3205. {
  3206. //DEBUG_ERROR("statusNotification mapitem pass");
  3207. result = PASS;
  3208. }
  3209. }
  3210. else
  3211. {
  3212. result = PASS;
  3213. }
  3214. return result;
  3215. }
  3216. int sendStopTransactionRequest(int gun_index)
  3217. {
  3218. mtrace();
  3219. int result = FAIL;
  3220. //char message[1500]={0};
  3221. char guid[37]={0};
  3222. char tempdata[65]={0};
  3223. int tempIndex = 0;
  3224. //int idx_sample=0;
  3225. DEBUG_ERROR("sendStopTransactionRequest \n");
  3226. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3227. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3228. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3229. if(gunType[gun_index] == 'J')
  3230. {
  3231. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3232. {
  3233. tempIndex = ((gun_index==2) ? 1: 0);
  3234. }
  3235. else
  3236. {
  3237. tempIndex = gun_index;
  3238. }
  3239. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3240. {
  3241. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3242. {
  3243. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3244. }
  3245. }// END OF CHAdeMO_QUANTITY
  3246. }
  3247. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3248. {
  3249. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3250. {
  3251. tempIndex = ((gun_index==2) ? 1: 0);
  3252. }
  3253. else
  3254. {
  3255. tempIndex = gun_index;
  3256. }
  3257. for (int index = 0; index < CCS_QUANTITY; index++)
  3258. {
  3259. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3260. {
  3261. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3262. }
  3263. }// END OF CCS_QUANTITY
  3264. }
  3265. else if(gunType[gun_index] == 'G')
  3266. {
  3267. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3268. {
  3269. tempIndex = ((gun_index==2) ? 1: 0);
  3270. }
  3271. else
  3272. {
  3273. tempIndex = gun_index;
  3274. }
  3275. for (int index = 0; index < GB_QUANTITY; index++)
  3276. {
  3277. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3278. {
  3279. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3280. }
  3281. }// END OF GB_QUANTITY
  3282. }
  3283. else
  3284. {
  3285. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3286. {
  3287. tempIndex = 2;
  3288. }
  3289. else
  3290. {
  3291. tempIndex = gun_index;
  3292. }
  3293. for (int index = 0; index < AC_QUANTITY; index++)
  3294. {
  3295. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3296. {
  3297. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3298. }
  3299. }// END OF AC_QUANTITY
  3300. }
  3301. //====================================== Stop Transaction Time =====================================================
  3302. struct timeval tmnow;
  3303. struct tm *tm;
  3304. char buf[28];//, usec_buf[6];
  3305. gettimeofday(&tmnow, NULL);
  3306. time_t t;
  3307. t = time(NULL);
  3308. /*UTC time and date*/
  3309. tm = gmtime(&t);
  3310. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3311. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  3312. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  3313. random_uuid(guid);
  3314. /***********************************transactionData******************************************************/
  3315. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  3316. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  3317. //=================================
  3318. // Transaction_Begin
  3319. //=================================
  3320. //============================================ Energy.Active.Import.Interval ================================
  3321. //idx_sample=0;
  3322. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  3323. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  3324. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  3325. 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*/]);
  3326. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3327. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3328. {
  3329. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  3330. }
  3331. else
  3332. {
  3333. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  3334. }
  3335. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  3336. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3337. //=================================
  3338. // Transaction_End
  3339. //=================================
  3340. // ================================= Current.Import L1 ===============================================
  3341. //idx_sample=1;
  3342. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  3343. if(gunType[gun_index] == 'J')
  3344. {
  3345. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3346. {
  3347. tempIndex = ((gun_index==2) ? 1: 0);
  3348. }
  3349. else
  3350. {
  3351. tempIndex = gun_index;
  3352. }
  3353. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3354. {
  3355. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3356. {
  3357. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3358. }
  3359. }// End of for CHAdeMO_QUANTITY
  3360. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3361. }
  3362. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3363. {
  3364. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3365. {
  3366. tempIndex = ((gun_index==2) ? 1: 0);
  3367. }
  3368. else
  3369. {
  3370. tempIndex = gun_index;
  3371. }
  3372. for (int index = 0; index < CCS_QUANTITY; index++)
  3373. {
  3374. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3375. {
  3376. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3377. }
  3378. }// End of for CCS_QUANTITY
  3379. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3380. }
  3381. else if(gunType[gun_index] == 'G')
  3382. {
  3383. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3384. {
  3385. tempIndex = ((gun_index==2) ? 1: 0);
  3386. }
  3387. else
  3388. {
  3389. tempIndex = gun_index;
  3390. }
  3391. for (int index = 0; index < GB_QUANTITY; index++)
  3392. {
  3393. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3394. {
  3395. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3396. }
  3397. }// End of for GB_QUANTITY
  3398. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3399. }
  3400. else
  3401. {
  3402. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3403. {
  3404. tempIndex = 2;
  3405. }
  3406. else
  3407. {
  3408. tempIndex = gun_index;
  3409. }
  3410. for (int index = 0; index < AC_QUANTITY; index++)
  3411. {
  3412. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3413. {
  3414. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  3415. }
  3416. }// End of for AC_QUANTITY
  3417. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  3418. }
  3419. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3420. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  3421. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  3422. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  3423. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3424. // ================================= Energy.Active.Import.Interval ==============================================
  3425. //idx_sample=2;
  3426. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3427. if(gunType[gun_index] == 'J')
  3428. {
  3429. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3430. {
  3431. tempIndex = ((gun_index==2) ? 1: 0);
  3432. }
  3433. else
  3434. {
  3435. tempIndex = gun_index;
  3436. }
  3437. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3438. {
  3439. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3440. {
  3441. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3442. }
  3443. }// END OF CHAdeMO_QUANTITY
  3444. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3445. }
  3446. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3447. {
  3448. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3449. {
  3450. tempIndex = ((gun_index==2) ? 1: 0);
  3451. }
  3452. else
  3453. {
  3454. tempIndex = gun_index;
  3455. }
  3456. for (int index = 0; index < CCS_QUANTITY; index++)
  3457. {
  3458. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3459. {
  3460. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3461. }
  3462. }// END OF CCS_QUANTITY
  3463. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3464. }
  3465. else if(gunType[gun_index] == 'G')
  3466. {
  3467. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3468. {
  3469. tempIndex = ((gun_index==2) ? 1: 0);
  3470. }
  3471. else
  3472. {
  3473. tempIndex = gun_index;
  3474. }
  3475. for (int index = 0; index < GB_QUANTITY; index++)
  3476. {
  3477. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3478. {
  3479. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3480. }
  3481. }// END OF GB_QUANTITY
  3482. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3483. }
  3484. else
  3485. {
  3486. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3487. {
  3488. tempIndex = 2;
  3489. }
  3490. else
  3491. {
  3492. tempIndex = gun_index;
  3493. }
  3494. for (int index = 0; index < AC_QUANTITY; index++)
  3495. {
  3496. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3497. {
  3498. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3499. }
  3500. }// END OF AC_QUANTITY
  3501. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  3502. }
  3503. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3504. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  3505. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  3506. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  3507. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3508. //=================================== Power.Active.Import ==================================================
  3509. //idx_sample=3;
  3510. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3511. if(gunType[gun_index] == 'J')
  3512. {
  3513. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3514. {
  3515. tempIndex = ((gun_index==2) ? 1: 0);
  3516. }
  3517. else
  3518. {
  3519. tempIndex = gun_index;
  3520. }
  3521. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3522. {
  3523. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3524. {
  3525. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3526. }
  3527. } // End for CHAdeMO_QUANTITY
  3528. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3529. }
  3530. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3531. {
  3532. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3533. {
  3534. tempIndex = ((gun_index==2) ? 1: 0);
  3535. }
  3536. else
  3537. {
  3538. tempIndex = gun_index;
  3539. }
  3540. for (int index = 0; index < CCS_QUANTITY; index++)
  3541. {
  3542. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3543. {
  3544. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3545. }
  3546. } // END for CCS_QUANTITY
  3547. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3548. }
  3549. else if(gunType[gun_index] == 'G')
  3550. {
  3551. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3552. {
  3553. tempIndex = ((gun_index==2) ? 1: 0);
  3554. }
  3555. else
  3556. {
  3557. tempIndex = gun_index;
  3558. }
  3559. for (int index = 0; index < GB_QUANTITY; index++)
  3560. {
  3561. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3562. {
  3563. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3564. }
  3565. }// END for GB_QUANTITY
  3566. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3567. }
  3568. else
  3569. {
  3570. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3571. {
  3572. tempIndex = 2;
  3573. }
  3574. else
  3575. {
  3576. tempIndex = gun_index;
  3577. }
  3578. for (int index = 0; index < AC_QUANTITY; index++)
  3579. {
  3580. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3581. {
  3582. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3583. }
  3584. } // END for AC_QUANTITY
  3585. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  3586. }
  3587. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3588. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  3589. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  3590. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  3591. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  3592. //============================ Voltage L1 ====================================
  3593. //idx_sample=4;
  3594. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3595. if(gunType[gun_index] == 'J')
  3596. {
  3597. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3598. {
  3599. tempIndex = ((gun_index==2) ? 1: 0);
  3600. }
  3601. else
  3602. {
  3603. tempIndex = gun_index;
  3604. }
  3605. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3606. {
  3607. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3608. {
  3609. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3610. }
  3611. } // END OF FOR CHAdeMO_QUANTITY
  3612. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3613. }
  3614. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3615. {
  3616. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3617. {
  3618. tempIndex = ((gun_index==2) ? 1: 0);
  3619. }
  3620. else
  3621. {
  3622. tempIndex = gun_index;
  3623. }
  3624. for (int index = 0; index < CCS_QUANTITY; index++)
  3625. {
  3626. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3627. {
  3628. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3629. }
  3630. } // END OF FOR CCS_QUANTITY
  3631. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3632. }
  3633. else if(gunType[gun_index] == 'G')
  3634. {
  3635. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3636. {
  3637. tempIndex = ((gun_index==2) ? 1: 0);
  3638. }
  3639. else
  3640. {
  3641. tempIndex = gun_index;
  3642. }
  3643. for (int index = 0; index < GB_QUANTITY; index++)
  3644. {
  3645. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3646. {
  3647. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3648. }
  3649. } // END OF FOR GB_QUANTITY
  3650. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3651. }
  3652. else
  3653. {
  3654. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3655. {
  3656. tempIndex = 2;
  3657. }
  3658. else
  3659. {
  3660. tempIndex = gun_index;
  3661. }
  3662. for (int index = 0; index < AC_QUANTITY; index++)
  3663. {
  3664. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3665. {
  3666. 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
  3667. }
  3668. } // END OF FOR AC_QUANTITY
  3669. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  3670. }
  3671. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3672. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  3673. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  3674. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  3675. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3676. //====================== SoC ================================
  3677. //idx_sample=5;
  3678. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3679. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3680. {
  3681. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3682. {
  3683. tempIndex = ((gun_index==2) ? 1: 0);
  3684. }
  3685. else
  3686. {
  3687. tempIndex = gun_index;
  3688. }
  3689. if(gunType[gun_index] == 'J')
  3690. {
  3691. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3692. {
  3693. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3694. {
  3695. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  3696. }
  3697. }
  3698. }
  3699. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3700. {
  3701. for (int index = 0; index < CCS_QUANTITY; index++)
  3702. {
  3703. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3704. {
  3705. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  3706. }
  3707. }
  3708. }
  3709. else if(gunType[gun_index] == 'G')
  3710. {
  3711. for (int index = 0; index < GB_QUANTITY; index++)
  3712. {
  3713. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3714. {
  3715. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  3716. }
  3717. }
  3718. }
  3719. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3720. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  3721. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  3722. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  3723. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  3724. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  3725. } // END FOR DC CASE
  3726. // ================================= Current.Import L2 ===============================================
  3727. //idx_sample=6;
  3728. // AC 3 phse L2 current
  3729. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3730. {
  3731. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3732. {
  3733. tempIndex = 2;
  3734. }
  3735. else
  3736. {
  3737. tempIndex = gun_index;
  3738. }
  3739. for (int index = 0; index < AC_QUANTITY; index++)
  3740. {
  3741. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3742. {
  3743. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  3744. }
  3745. }// End of for AC_QUANTITY
  3746. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  3747. }
  3748. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3749. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  3750. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  3751. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  3752. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3753. // ================================= Current.Import L3 ===============================================
  3754. //idx_sample=7;
  3755. // AC 3 phse L3 current
  3756. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3757. {
  3758. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3759. {
  3760. tempIndex = 2;
  3761. }
  3762. else
  3763. {
  3764. tempIndex = gun_index;
  3765. }
  3766. for (int index = 0; index < AC_QUANTITY; index++)
  3767. {
  3768. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3769. {
  3770. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  3771. }
  3772. }// End of for AC_QUANTITY
  3773. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  3774. }
  3775. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3776. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  3777. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  3778. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  3779. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3780. //============================ Voltage L2 ====================================
  3781. //idx_sample=8;
  3782. // AC 3 phse L2 voltage
  3783. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3784. {
  3785. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3786. {
  3787. tempIndex = 2;
  3788. }
  3789. else
  3790. {
  3791. tempIndex = gun_index;
  3792. }
  3793. for (int index = 0; index < AC_QUANTITY; index++)
  3794. {
  3795. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3796. {
  3797. 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
  3798. }
  3799. } // END OF FOR AC_QUANTITY
  3800. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  3801. }
  3802. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3803. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  3804. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  3805. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  3806. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3807. //============================ Voltage L3 ====================================
  3808. //idx_sample=8;
  3809. // AC 3 phse L3 voltage
  3810. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3811. {
  3812. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3813. {
  3814. tempIndex = 2;
  3815. }
  3816. else
  3817. {
  3818. tempIndex = gun_index;
  3819. }
  3820. for (int index = 0; index < AC_QUANTITY; index++)
  3821. {
  3822. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3823. {
  3824. 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
  3825. }
  3826. } // END OF FOR AC_QUANTITY
  3827. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  3828. }
  3829. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3830. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  3831. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  3832. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  3833. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3834. //================================================ Message create ====================================================
  3835. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3836. {
  3837. 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\"}]}]}]"
  3838. ,gun_index+1
  3839. ,MESSAGE_TYPE_CALL
  3840. ,guid
  3841. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3842. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3843. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3844. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3845. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3846. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3847. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3848. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3849. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3850. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3851. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3852. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3853. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3854. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3855. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3856. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3857. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3858. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3859. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3860. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3861. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3862. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3863. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3864. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3865. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3866. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3867. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3868. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3869. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3870. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3871. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3872. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3873. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3874. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3875. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3876. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3877. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3878. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3879. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3880. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3881. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3882. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  3883. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  3884. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  3885. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  3886. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  3887. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  3888. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  3889. );
  3890. }
  3891. else
  3892. {
  3893. if((ShmSysConfigAndInfo->SysConfig.ModelName[2]!='Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2]!='W'))
  3894. {
  3895. 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\"}]}]}]"
  3896. ,gun_index+1
  3897. ,MESSAGE_TYPE_CALL
  3898. ,guid
  3899. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3900. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3901. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3902. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3903. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3904. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3905. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3906. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3907. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3908. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3909. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3910. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3911. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3912. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3913. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3914. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3915. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3916. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3917. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3918. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3919. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3920. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3921. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3922. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3923. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3924. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3925. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3926. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3927. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3928. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3929. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3930. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3931. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3932. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3933. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3934. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3935. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3936. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3937. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3938. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3939. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3940. );
  3941. }
  3942. else
  3943. {
  3944. 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\"}]}]}]"
  3945. ,gun_index+1
  3946. ,MESSAGE_TYPE_CALL
  3947. ,guid
  3948. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3949. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3950. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3951. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3952. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3953. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3954. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3955. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3956. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3957. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3958. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3959. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3960. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3961. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3962. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3963. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3964. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3965. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3966. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3967. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3968. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3969. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3970. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3971. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3972. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3973. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3974. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3975. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3976. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3977. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3978. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3979. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3980. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3981. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3982. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3983. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3984. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3985. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3986. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3987. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3988. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3989. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value
  3990. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context
  3991. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format
  3992. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand
  3993. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase
  3994. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location
  3995. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit
  3996. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value
  3997. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context
  3998. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format
  3999. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand
  4000. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase
  4001. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location
  4002. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit
  4003. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value
  4004. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context
  4005. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format
  4006. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand
  4007. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase
  4008. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location
  4009. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit
  4010. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value
  4011. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context
  4012. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format
  4013. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand
  4014. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase
  4015. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location
  4016. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit
  4017. );
  4018. }
  4019. }
  4020. #if 1 // for TempStopTransaction
  4021. //Delete TempStopTransaction
  4022. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  4023. {
  4024. remove("/Storage/OCPP/TempStopTransaction"); // remove file "TempStopTransaction"
  4025. }
  4026. #endif
  4027. #if 1
  4028. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4029. if(hashmap_operation(0, guid, tempdata) == 1)
  4030. {
  4031. result = PASS;
  4032. DEBUG_INFO("StopTransaction mapitem pass\n");
  4033. }
  4034. #endif
  4035. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4036. /*
  4037. if(GetTransactionQueueNum() == 1)
  4038. {
  4039. LWS_Send(queuedata+2);
  4040. }*/
  4041. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4042. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4043. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  4044. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4045. {
  4046. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4047. }
  4048. //for test
  4049. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4050. return result;
  4051. }
  4052. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4053. {
  4054. mtrace();
  4055. int result = FAIL;
  4056. char guid[37]={0};
  4057. char tempdata[65]={0};
  4058. int tempIndex = 0;
  4059. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4060. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4061. //set value
  4062. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4063. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ((strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging") != NULL) ? ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId : 0);
  4064. random_uuid(guid);
  4065. //UTC Date time
  4066. struct timeval tmnow;
  4067. struct tm *tm;
  4068. char buf[28];//, usec_buf[6];
  4069. gettimeofday(&tmnow, NULL);
  4070. time_t t;
  4071. t = time(NULL);
  4072. /*UTC time and date*/
  4073. tm = gmtime(&t);
  4074. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4075. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4076. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4077. //idx_sample=0;
  4078. //********************************(1)Current.Import L1************************************************/
  4079. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4080. if(gunType[gun_index] == 'J')
  4081. {
  4082. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4083. {
  4084. tempIndex = ((gun_index==2) ? 1: 0);
  4085. }
  4086. else
  4087. {
  4088. tempIndex = gun_index;
  4089. }
  4090. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4091. {
  4092. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4093. {
  4094. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4095. }
  4096. }
  4097. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4098. }
  4099. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4100. {
  4101. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4102. {
  4103. tempIndex = ((gun_index==2) ? 1: 0);
  4104. }
  4105. else
  4106. {
  4107. tempIndex = gun_index;
  4108. }
  4109. for (int index = 0; index < CCS_QUANTITY; index++)
  4110. {
  4111. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4112. {
  4113. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4114. }
  4115. }
  4116. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4117. }
  4118. else if(gunType[gun_index] == 'G')
  4119. {
  4120. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4121. {
  4122. tempIndex = ((gun_index==2) ? 1: 0);
  4123. }
  4124. else
  4125. {
  4126. tempIndex = gun_index;
  4127. }
  4128. for (int index = 0; index < GB_QUANTITY; index++)
  4129. {
  4130. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4131. {
  4132. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4133. }
  4134. }
  4135. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4136. }
  4137. else
  4138. {
  4139. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4140. {
  4141. tempIndex = 2;
  4142. }
  4143. else
  4144. {
  4145. tempIndex = gun_index;
  4146. }
  4147. for (int index = 0; index < AC_QUANTITY; index++)
  4148. {
  4149. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4150. {
  4151. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4152. }
  4153. }
  4154. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4155. }
  4156. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4157. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4158. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4159. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4160. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4161. //idx_sample=1;
  4162. //********************************(2)Energy.Active.Import.Register ************************************************/
  4163. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4164. if(gunType[gun_index] == 'J')
  4165. {
  4166. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4167. {
  4168. tempIndex = ((gun_index==2) ? 1: 0);
  4169. }
  4170. else
  4171. {
  4172. tempIndex = gun_index;
  4173. }
  4174. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4175. {
  4176. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4177. {
  4178. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4179. }
  4180. }
  4181. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4182. }
  4183. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4184. {
  4185. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4186. {
  4187. tempIndex = ((gun_index==2) ? 1: 0);
  4188. }
  4189. else
  4190. {
  4191. tempIndex = gun_index;
  4192. }
  4193. for (int index = 0; index < CCS_QUANTITY; index++)
  4194. {
  4195. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4196. {
  4197. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4198. }
  4199. }
  4200. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4201. }
  4202. else if(gunType[gun_index] == 'G')
  4203. {
  4204. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4205. {
  4206. tempIndex = ((gun_index==2) ? 1: 0);
  4207. }
  4208. else
  4209. {
  4210. tempIndex = gun_index;
  4211. }
  4212. for (int index = 0; index < GB_QUANTITY; index++)
  4213. {
  4214. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4215. {
  4216. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4217. }
  4218. }
  4219. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4220. }
  4221. else
  4222. {
  4223. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4224. {
  4225. tempIndex = 2;
  4226. }
  4227. else
  4228. {
  4229. tempIndex = gun_index;
  4230. }
  4231. for (int index = 0; index < AC_QUANTITY; index++)
  4232. {
  4233. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4234. {
  4235. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4236. }
  4237. }
  4238. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4239. }
  4240. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  4241. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4242. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4243. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4244. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4245. //idx_sample=2;
  4246. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  4247. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4248. if(gunType[gun_index] == 'J')
  4249. {
  4250. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4251. {
  4252. tempIndex = ((gun_index==2) ? 1: 0);
  4253. }
  4254. else
  4255. {
  4256. tempIndex = gun_index;
  4257. }
  4258. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4259. {
  4260. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4261. {
  4262. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4263. }
  4264. } // END OF FOR CHAdeMO_QUANTITY
  4265. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4266. }
  4267. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4268. {
  4269. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4270. {
  4271. tempIndex = ((gun_index==2) ? 1: 0);
  4272. }
  4273. else
  4274. {
  4275. tempIndex = gun_index;
  4276. }
  4277. for (int index = 0; index < CCS_QUANTITY; index++)
  4278. {
  4279. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4280. {
  4281. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  4282. }
  4283. } // END OF CCS_QUANTITY
  4284. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4285. }
  4286. else if(gunType[gun_index] == 'G')
  4287. {
  4288. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4289. {
  4290. tempIndex = ((gun_index==2) ? 1: 0);
  4291. }
  4292. else
  4293. {
  4294. tempIndex = gun_index;
  4295. }
  4296. for (int index = 0; index < GB_QUANTITY; index++)
  4297. {
  4298. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4299. {
  4300. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  4301. }
  4302. } // END OF GB_QUANTITY
  4303. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4304. }
  4305. else
  4306. {
  4307. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4308. {
  4309. tempIndex = 2;
  4310. }
  4311. else
  4312. {
  4313. tempIndex = gun_index;
  4314. }
  4315. for (int index = 0; index < AC_QUANTITY; index++)
  4316. {
  4317. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4318. {
  4319. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  4320. }
  4321. }
  4322. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  4323. }
  4324. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  4325. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  4326. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  4327. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  4328. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4329. //idx_sample=3;
  4330. //********************************(4)Power.Active.Import************************************************/
  4331. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4332. if(gunType[gun_index] == 'J')
  4333. {
  4334. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4335. {
  4336. tempIndex = ((gun_index==2) ? 1: 0);
  4337. }
  4338. else
  4339. {
  4340. tempIndex = gun_index;
  4341. }
  4342. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4343. {
  4344. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4345. {
  4346. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  4347. }
  4348. } // END OF FOR
  4349. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4350. }
  4351. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4352. {
  4353. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4354. {
  4355. tempIndex = ((gun_index==2) ? 1: 0);
  4356. }
  4357. else
  4358. {
  4359. tempIndex = gun_index;
  4360. }
  4361. for (int index = 0; index < CCS_QUANTITY; index++)
  4362. {
  4363. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4364. {
  4365. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  4366. }
  4367. }
  4368. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4369. }
  4370. else if(gunType[gun_index] == 'G')
  4371. {
  4372. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4373. {
  4374. tempIndex = ((gun_index==2) ? 1: 0);
  4375. }
  4376. else
  4377. {
  4378. tempIndex = gun_index;
  4379. }
  4380. for (int index = 0; index < GB_QUANTITY; index++)
  4381. {
  4382. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4383. {
  4384. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4385. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  4386. }
  4387. }
  4388. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4389. }
  4390. else
  4391. {
  4392. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4393. {
  4394. tempIndex = 2;
  4395. }
  4396. else
  4397. {
  4398. tempIndex = gun_index;
  4399. }
  4400. for (int index = 0; index < AC_QUANTITY; index++)
  4401. {
  4402. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4403. {
  4404. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  4405. }
  4406. }
  4407. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  4408. }
  4409. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  4410. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  4411. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  4412. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  4413. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  4414. //idx_sample=4;
  4415. //***********************************************(5)VOLTAGE L1******************************************************/
  4416. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4417. if(gunType[gun_index] == 'J')
  4418. {
  4419. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4420. {
  4421. tempIndex = ((gun_index==2) ? 1: 0);
  4422. }
  4423. else
  4424. {
  4425. tempIndex = gun_index;
  4426. }
  4427. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4428. {
  4429. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4430. {
  4431. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  4432. }
  4433. }
  4434. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4435. }
  4436. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4437. {
  4438. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4439. {
  4440. tempIndex = ((gun_index==2) ? 1: 0);
  4441. }
  4442. else
  4443. {
  4444. tempIndex = gun_index;
  4445. }
  4446. for (int index = 0; index < CCS_QUANTITY; index++)
  4447. {
  4448. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4449. {
  4450. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  4451. }
  4452. }
  4453. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4454. }
  4455. else if(gunType[gun_index] == 'G')
  4456. {
  4457. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4458. {
  4459. tempIndex = ((gun_index==2) ? 1: 0);
  4460. }
  4461. else
  4462. {
  4463. tempIndex = gun_index;
  4464. }
  4465. for (int index = 0; index < GB_QUANTITY; index++)
  4466. {
  4467. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4468. {
  4469. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  4470. }
  4471. }
  4472. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4473. }
  4474. else
  4475. {
  4476. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4477. {
  4478. tempIndex = 2;
  4479. }
  4480. else
  4481. {
  4482. tempIndex = gun_index;
  4483. }
  4484. for (int index = 0; index < AC_QUANTITY; index++)
  4485. {
  4486. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4487. {
  4488. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  4489. }
  4490. }
  4491. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  4492. }
  4493. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  4494. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  4495. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  4496. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  4497. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4498. //***********************************************(6)SOC******************************************************/
  4499. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  4500. {
  4501. //idx_sample=5;
  4502. //sampledValue = NULL;
  4503. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4504. {
  4505. tempIndex = ((gun_index==2) ? 1: 0);
  4506. }
  4507. else
  4508. {
  4509. tempIndex = gun_index;
  4510. }
  4511. if(gunType[gun_index] == 'J')
  4512. {
  4513. //tempIndex = ((gun_index==2) ? 1: 0);
  4514. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4515. {
  4516. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4517. {
  4518. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  4519. }
  4520. }
  4521. }
  4522. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4523. {
  4524. //tempIndex = ((gun_index==2) ? 1: 0);
  4525. for (int index = 0; index < CCS_QUANTITY; index++)
  4526. {
  4527. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4528. {
  4529. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  4530. }
  4531. }
  4532. }
  4533. else if(gunType[gun_index] == 'G')
  4534. {
  4535. //tempIndex = ((gun_index==2) ? 1: 0);
  4536. for (int index = 0; index < GB_QUANTITY; index++)
  4537. {
  4538. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4539. {
  4540. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  4541. }
  4542. }
  4543. }
  4544. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4545. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  4546. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  4547. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  4548. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_Outlet]);
  4549. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  4550. }
  4551. //********************************(7)Current.Import L2************************************************/
  4552. // Only for AC 3 phase
  4553. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4554. {
  4555. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4556. {
  4557. tempIndex = 2;
  4558. }
  4559. else
  4560. {
  4561. tempIndex = gun_index;
  4562. }
  4563. for (int index = 0; index < AC_QUANTITY; index++)
  4564. {
  4565. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4566. {
  4567. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  4568. }
  4569. }
  4570. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  4571. }
  4572. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  4573. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  4574. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  4575. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  4576. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4577. //********************************(8)Current.Import L3************************************************/
  4578. // Only for AC 3 phase
  4579. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4580. {
  4581. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4582. {
  4583. tempIndex = 2;
  4584. }
  4585. else
  4586. {
  4587. tempIndex = gun_index;
  4588. }
  4589. for (int index = 0; index < AC_QUANTITY; index++)
  4590. {
  4591. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4592. {
  4593. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  4594. }
  4595. }
  4596. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  4597. }
  4598. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  4599. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  4600. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  4601. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  4602. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4603. //***********************************************(9)VOLTAGE L2******************************************************/
  4604. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4605. {
  4606. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4607. {
  4608. tempIndex = 2;
  4609. }
  4610. else
  4611. {
  4612. tempIndex = gun_index;
  4613. }
  4614. for (int index = 0; index < AC_QUANTITY; index++)
  4615. {
  4616. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4617. {
  4618. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  4619. }
  4620. }
  4621. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  4622. }
  4623. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  4624. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  4625. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  4626. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  4627. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4628. //***********************************************(10)VOLTAGE L3******************************************************/
  4629. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4630. {
  4631. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4632. {
  4633. tempIndex = 2;
  4634. }
  4635. else
  4636. {
  4637. tempIndex = gun_index;
  4638. }
  4639. for (int index = 0; index < AC_QUANTITY; index++)
  4640. {
  4641. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4642. {
  4643. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  4644. }
  4645. }
  4646. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  4647. }
  4648. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  4649. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  4650. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  4651. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  4652. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4653. // Message create ====================================================================================================
  4654. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  4655. {
  4656. 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\"}]}]}]"
  4657. ,gun_index + 1
  4658. ,MESSAGE_TYPE_CALL
  4659. ,guid
  4660. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4661. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4662. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4663. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4664. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4665. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4666. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4667. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4668. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4669. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4670. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4671. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4672. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4673. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4674. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4675. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4676. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4677. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4678. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4679. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4680. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4681. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4682. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4683. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4684. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4685. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4686. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4687. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4688. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4689. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4690. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4691. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4692. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4693. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4694. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4695. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4696. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4697. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4698. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value
  4699. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context
  4700. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format
  4701. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand
  4702. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase
  4703. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location
  4704. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit
  4705. );
  4706. }
  4707. else
  4708. {
  4709. if((ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'W'))
  4710. {
  4711. 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\"}]}]}]"
  4712. ,gun_index + 1
  4713. ,MESSAGE_TYPE_CALL
  4714. ,guid
  4715. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4716. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4717. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4718. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4719. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4720. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4721. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4722. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4723. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4724. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4725. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4726. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4727. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4728. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4729. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4730. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4731. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4732. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4733. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4734. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4735. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4736. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4737. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4738. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4739. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4740. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4741. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4742. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4743. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4744. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4745. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4746. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4747. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4748. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4749. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4750. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4751. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4752. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4753. );
  4754. }
  4755. else
  4756. {
  4757. 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\"}]}]}]"
  4758. ,gun_index + 1
  4759. ,MESSAGE_TYPE_CALL
  4760. ,guid
  4761. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4762. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4763. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4764. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4765. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4766. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4767. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4768. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4769. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4770. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4771. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4772. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4773. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4774. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4775. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4776. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4777. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4778. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4779. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4780. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4781. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4782. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4783. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4784. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4785. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4786. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4787. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4788. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4789. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4790. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4791. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4792. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4793. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4794. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4795. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4796. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4797. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4798. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4799. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value
  4800. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context
  4801. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format
  4802. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand
  4803. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase
  4804. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location
  4805. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit
  4806. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value
  4807. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context
  4808. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format
  4809. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand
  4810. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase
  4811. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location
  4812. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit
  4813. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value
  4814. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context
  4815. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format
  4816. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand
  4817. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase
  4818. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location
  4819. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit
  4820. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value
  4821. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context
  4822. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format
  4823. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand
  4824. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase
  4825. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location
  4826. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit
  4827. );
  4828. }
  4829. }
  4830. // Put request guid to hash map
  4831. sprintf(tempdata, "MeterValues,%d", (gun_index));
  4832. 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*/)
  4833. {
  4834. result = PASS;
  4835. DEBUG_INFO("MeterValues mapitem pass\n");
  4836. }
  4837. if(dataType != ReadingContext_Trigger)
  4838. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4839. else
  4840. LWS_Send(queuedata +2);
  4841. /*
  4842. if(GetTransactionQueueNum() == 1)
  4843. {
  4844. LWS_Send(queuedata +2);
  4845. }*/
  4846. return result;
  4847. }
  4848. //==========================================
  4849. // send confirm routine
  4850. //==========================================
  4851. int sendCancelReservationConfirmation(char *uuid,char *payload)
  4852. {
  4853. mtrace();
  4854. int result = FAIL;
  4855. char message[100]={0};
  4856. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  4857. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4858. LWS_Send(message);
  4859. result = TRUE;
  4860. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  4861. return result;
  4862. }
  4863. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  4864. {
  4865. mtrace();
  4866. int result = FAIL;
  4867. char message[100]={0};
  4868. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  4869. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4870. LWS_Send(message);
  4871. result = TRUE;
  4872. return result;
  4873. }
  4874. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  4875. {
  4876. mtrace();
  4877. int result = FAIL;
  4878. char message[100]={0};
  4879. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  4880. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4881. LWS_Send(message);
  4882. result = TRUE;
  4883. return result;
  4884. }
  4885. int sendClearCacheConfirmation(char *uuid,char *payload)
  4886. {
  4887. mtrace();
  4888. int result = FAIL;
  4889. char message[500]={0};
  4890. DEBUG_INFO("sendClearCacheConfirmation...\n");
  4891. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4892. LWS_Send(message);
  4893. return result;
  4894. }
  4895. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  4896. {
  4897. mtrace();
  4898. int result = FAIL;
  4899. char message[500]={0};
  4900. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  4901. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4902. LWS_Send(message);
  4903. return result;
  4904. }
  4905. int sendDataTransferConfirmation(char *uuid,char *payload)
  4906. {
  4907. mtrace();
  4908. char statusStr[20]={0};
  4909. char dataStr[10]={0};
  4910. char sstr[20]={0};
  4911. int c = 0;
  4912. char *loc;
  4913. int result = FAIL;
  4914. DEBUG_INFO("sendDataTransferConfirmation...\n");
  4915. /**********************status**************************/
  4916. loc = strstr(payload, "status");
  4917. memset(sstr ,0, ARRAY_SIZE(sstr) );
  4918. c = 0;
  4919. while (loc[3+strlen("status")+c] != '\"')
  4920. {
  4921. sstr[c] = loc[3+strlen("status")+c];
  4922. c++;
  4923. }
  4924. sstr[c] = '\0';
  4925. strcpy(statusStr, sstr);
  4926. /**********************data**************************/
  4927. loc = strstr(payload, "data");
  4928. memset(sstr ,0, ARRAY_SIZE(sstr) );
  4929. c = 0;
  4930. while (loc[3+strlen("data")+c] != '\"')
  4931. {
  4932. sstr[c] = loc[3+strlen("data")+c];
  4933. c++;
  4934. }
  4935. sstr[c] = '\0';
  4936. strcpy(dataStr, sstr);
  4937. return result;
  4938. }
  4939. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  4940. {
  4941. mtrace();
  4942. int result = FAIL;
  4943. char message[1000]={0};
  4944. int CompositeScheduleIndex = 0;
  4945. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  4946. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  4947. if(nPeriod == 0)
  4948. {
  4949. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  4950. {
  4951. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  4952. ,MESSAGE_TYPE_CALLRESULT
  4953. ,uuid
  4954. ,payload
  4955. ,connectorIdInt);
  4956. }
  4957. else
  4958. {
  4959. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  4960. ,MESSAGE_TYPE_CALLRESULT
  4961. ,uuid
  4962. ,payload
  4963. ,connectorIdInt
  4964. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4965. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  4966. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4967. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  4968. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  4969. }
  4970. }
  4971. else
  4972. {
  4973. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  4974. ,MESSAGE_TYPE_CALLRESULT
  4975. ,uuid
  4976. ,payload
  4977. ,connectorIdInt
  4978. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4979. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  4980. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4981. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  4982. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  4983. {
  4984. if (idx_sample == 0)
  4985. {
  4986. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  4987. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  4988. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  4989. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  4990. }
  4991. else
  4992. {
  4993. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  4994. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  4995. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  4996. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  4997. }
  4998. }
  4999. sprintf(message + strlen(message), "]}}]");
  5000. }
  5001. LWS_Send(message);
  5002. result = TRUE;
  5003. return result;
  5004. }
  5005. int sendGetConfigurationConfirmation(char *uuid)
  5006. {
  5007. mtrace();
  5008. int result = FAIL;
  5009. int MaxKeySupported = 0;
  5010. int sentConfigurationNumber= 0;
  5011. int sentunConfigurationNumber= 0;
  5012. char message[4000]={0};
  5013. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5014. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5015. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5016. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5017. ,MESSAGE_TYPE_CALLRESULT
  5018. ,uuid );
  5019. //configuration key
  5020. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5021. {
  5022. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5023. {
  5024. if (sentConfigurationNumber == 0)
  5025. {
  5026. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5027. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5028. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5029. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5030. }
  5031. else
  5032. {
  5033. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5034. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5035. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5036. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5037. }
  5038. sentConfigurationNumber = sentConfigurationNumber + 1;
  5039. }
  5040. }
  5041. sprintf(message + strlen(message), "]");
  5042. if(UnknownKeynum != 0)
  5043. {
  5044. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5045. //unkown key
  5046. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5047. {
  5048. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5049. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5050. if(sentunConfigurationNumber == 0)
  5051. {
  5052. sprintf(message + strlen(message), "\"%s\""
  5053. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5054. }
  5055. else
  5056. {
  5057. sprintf(message + strlen(message), ",\"%s\""
  5058. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5059. }
  5060. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5061. }
  5062. sprintf(message + strlen(message), "]");
  5063. }
  5064. sprintf(message + strlen(message), "}]");
  5065. LWS_Send(message);
  5066. return result;
  5067. }
  5068. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5069. {
  5070. mtrace();
  5071. int result = FAIL;
  5072. char message[400]={0};
  5073. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5074. if(strcmp(payload,"")==0)
  5075. {
  5076. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5077. }
  5078. else
  5079. {
  5080. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5081. }
  5082. LWS_Send(message);
  5083. result = TRUE;
  5084. return result;
  5085. }
  5086. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5087. {
  5088. mtrace();
  5089. int result = FAIL;
  5090. char message[80]={0};
  5091. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5092. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  5093. LWS_Send(message);
  5094. result = TRUE;
  5095. return result;
  5096. }
  5097. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5098. {
  5099. mtrace();
  5100. int result = FAIL;
  5101. char message[80]={0};
  5102. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5103. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5104. LWS_Send(message);
  5105. result = TRUE;
  5106. return result;
  5107. }
  5108. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5109. {
  5110. mtrace();
  5111. int result = FAIL;
  5112. char message[80]={0};
  5113. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5114. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5115. LWS_Send(message);
  5116. result = TRUE;
  5117. return result;
  5118. }
  5119. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5120. {
  5121. mtrace();
  5122. int result = FAIL;
  5123. char message[80]={0};
  5124. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5125. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5126. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5127. LWS_Send(message);
  5128. result = TRUE;
  5129. return result;
  5130. }
  5131. int sendResetConfirmation(char *uuid,char *payload)
  5132. {
  5133. mtrace();
  5134. int result = FAIL;
  5135. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  5136. char message[80]={0};
  5137. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  5138. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5139. LWS_Send(message);
  5140. result = TRUE;
  5141. return result;
  5142. }
  5143. int sendSendLocalListConfirmation(char *uuid,char *payload)
  5144. {
  5145. mtrace();
  5146. int result = FAIL;
  5147. char message[500]={0};
  5148. // [ 3, "1571284266109", { "status": "Accepted" } ]
  5149. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5150. LWS_Send(message);
  5151. result = TRUE;
  5152. return result;
  5153. }
  5154. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  5155. {
  5156. mtrace();
  5157. int result = FAIL;
  5158. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  5159. char message[80]={0};
  5160. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  5161. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5162. LWS_Send(message);
  5163. result = TRUE;
  5164. return result;
  5165. }
  5166. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  5167. {
  5168. mtrace();
  5169. int result = FAIL;
  5170. char message[80]={0};
  5171. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  5172. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5173. LWS_Send(message);
  5174. result = TRUE;
  5175. return result;
  5176. }
  5177. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  5178. {
  5179. mtrace();
  5180. int result = FAIL;
  5181. char message[80]={0};
  5182. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5183. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  5184. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5185. LWS_Send(message);
  5186. result = TRUE;
  5187. return result;
  5188. }
  5189. int sendUpdateFirmwareConfirmation(char *uuid)
  5190. {
  5191. mtrace();
  5192. int result = FAIL;
  5193. char message[60]={0};
  5194. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5195. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  5196. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5197. LWS_Send(message);
  5198. result = TRUE;
  5199. return result;
  5200. }
  5201. //==========================================
  5202. // send CallError routine
  5203. //==========================================
  5204. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  5205. {
  5206. mtrace();
  5207. char message[220]={0};
  5208. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  5209. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  5210. LWS_Send(message);
  5211. }
  5212. //==========================================
  5213. // Handle server request routine Start
  5214. //==========================================
  5215. int handleCancelReservationRequest(char *uuid, char *payload)
  5216. {
  5217. mtrace();
  5218. int result = FAIL;
  5219. int gunNO = 0;
  5220. int reservationIdInt =0;
  5221. char comfirmstr[20];
  5222. DEBUG_INFO("handleCancelReservationRequest...\n");
  5223. json_object *CancelReservation;
  5224. CancelReservation = json_tokener_parse(payload);
  5225. if(!is_error(CancelReservation))
  5226. {
  5227. // Required data
  5228. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  5229. }
  5230. json_object_put(CancelReservation);
  5231. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5232. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  5233. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  5234. //check Transaction active
  5235. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5236. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5237. {
  5238. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  5239. {
  5240. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5241. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5242. if(gunType[2] == 'J')
  5243. {
  5244. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  5245. }
  5246. else
  5247. {
  5248. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  5249. }
  5250. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5251. goto end;
  5252. }
  5253. }
  5254. for (int index = 0; index < CCS_QUANTITY; index++)
  5255. {
  5256. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  5257. {
  5258. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5259. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5260. if((gunType[2] == 'U') || (gunType[2] == 'E'))
  5261. {
  5262. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  5263. }
  5264. else
  5265. {
  5266. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  5267. }
  5268. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5269. goto end;
  5270. }
  5271. }
  5272. for (int index = 0; index < GB_QUANTITY; index++)
  5273. {
  5274. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  5275. {
  5276. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5277. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5278. if(gunType[2] == 'G')
  5279. {
  5280. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  5281. }
  5282. else
  5283. {
  5284. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  5285. }
  5286. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5287. goto end;
  5288. }
  5289. }
  5290. for (int index = 0; index < AC_QUANTITY; index++)
  5291. {
  5292. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  5293. {
  5294. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5295. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5296. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5297. {
  5298. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  5299. }
  5300. else
  5301. {
  5302. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  5303. }
  5304. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5305. goto end;
  5306. }
  5307. }
  5308. //The reservationId does NOT match the reservationId
  5309. sendCancelReservationConfirmation(uuid, comfirmstr);
  5310. end:
  5311. // Fill in ocpp packet uuid
  5312. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  5313. return result;
  5314. }
  5315. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  5316. {
  5317. mtrace();
  5318. int result = FAIL;
  5319. int gunIndex = 0;
  5320. char typeStr[16]={0};
  5321. char comfirmstr[20];
  5322. int specificId = FALSE;
  5323. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  5324. json_object *ChangeAvailability;
  5325. ChangeAvailability = json_tokener_parse(payload);
  5326. if(!is_error(ChangeAvailability))
  5327. {
  5328. // Required data
  5329. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  5330. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  5331. }
  5332. json_object_put(ChangeAvailability);
  5333. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5334. {
  5335. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  5336. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  5337. }
  5338. else if(gunIndex == 0)
  5339. {
  5340. for(int i=0; i < gunTotalNumber; i++)
  5341. {
  5342. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  5343. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  5344. }
  5345. }
  5346. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5347. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5348. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  5349. {
  5350. specificId = TRUE;
  5351. }
  5352. if(specificId == FALSE)
  5353. goto end;
  5354. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  5355. {
  5356. //----------------------gunIndex is 0 ------------------------------------------------//
  5357. if(gunIndex == 0)
  5358. {
  5359. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5360. {
  5361. for(int i=0; i < gunTotalNumber; i++)
  5362. {
  5363. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5364. {
  5365. if ((gunType[i] == 'J')&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  5366. {
  5367. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5368. {
  5369. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5370. goto end;
  5371. }
  5372. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5373. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5374. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5375. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5376. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5377. {
  5378. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5379. goto end;
  5380. }
  5381. }
  5382. }//END FOR CHAdeMO_QUANTITY
  5383. for (int index = 0; index < CCS_QUANTITY; index++)
  5384. {
  5385. if (((gunType[i] == 'U')||(gunType[i] == 'E'))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  5386. {
  5387. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  5388. {
  5389. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5390. goto end;
  5391. }
  5392. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5393. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5394. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5395. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5396. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5397. {
  5398. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5399. goto end;
  5400. }
  5401. }
  5402. }//END FOR CCS_QUANTITY
  5403. for (int index = 0; index < GB_QUANTITY; index++)
  5404. {
  5405. if ((gunType[i] == 'G')&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  5406. {
  5407. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5408. {
  5409. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5410. goto end;
  5411. }
  5412. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5413. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5414. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5415. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5416. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5417. {
  5418. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5419. goto end;
  5420. }
  5421. }
  5422. }// END FOR GB_QUANTITY
  5423. for (int index = 0; index < AC_QUANTITY; index++)
  5424. {
  5425. if (((gunType[i] > '0')&&(gunType[i] <= '9'))&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  5426. {
  5427. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5428. {
  5429. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5430. goto end;
  5431. }
  5432. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5433. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5434. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5435. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5436. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5437. {
  5438. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5439. goto end;
  5440. }
  5441. }
  5442. }//END FOR AC_QUANTITY
  5443. }// END FOR gunTotalNumber
  5444. }
  5445. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5446. {
  5447. for(int i=0; i < gunTotalNumber; i++)
  5448. {
  5449. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5450. {
  5451. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5452. goto end;
  5453. }
  5454. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5455. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  5456. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  5457. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  5458. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5459. {
  5460. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5461. goto end;
  5462. }
  5463. }
  5464. }
  5465. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5466. goto end;
  5467. }
  5468. //----------------------gunIndex is not 0 ------------------------------------------------//
  5469. //check Transaction active
  5470. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5471. {
  5472. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J'))
  5473. {
  5474. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  5475. {
  5476. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5477. goto end;
  5478. }
  5479. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5480. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5481. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5482. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5483. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5484. {
  5485. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5486. goto end;
  5487. }
  5488. else
  5489. {
  5490. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  5491. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5492. goto end;
  5493. }
  5494. }
  5495. }//END FOR CHAdeMO_QUANTITY
  5496. for (int index = 0; index < CCS_QUANTITY; index++)
  5497. {
  5498. if ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E')))
  5499. {
  5500. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  5501. {
  5502. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5503. goto end;
  5504. }
  5505. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5506. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5507. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5508. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5509. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5510. {
  5511. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5512. goto end;
  5513. }
  5514. else
  5515. {
  5516. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  5517. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5518. goto end;
  5519. }
  5520. }
  5521. }//END FOR CCS_QUANTITY
  5522. for (int index = 0; index < GB_QUANTITY; index++)
  5523. {
  5524. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))
  5525. {
  5526. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5527. {
  5528. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5529. goto end;
  5530. }
  5531. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5532. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5533. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5534. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5535. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5536. {
  5537. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5538. goto end;
  5539. }
  5540. else
  5541. {
  5542. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  5543. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5544. goto end;
  5545. }
  5546. }
  5547. }// END FOR GB_QUANTITY
  5548. for (int index = 0; index < AC_QUANTITY; index++)
  5549. {
  5550. if ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))
  5551. {
  5552. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5553. {
  5554. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5555. goto end;
  5556. }
  5557. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5558. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5559. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5560. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5561. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5562. {
  5563. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5564. goto end;
  5565. }
  5566. else
  5567. {
  5568. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  5569. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5570. goto end;
  5571. }
  5572. }
  5573. }//END FOR AC_QUANTITY
  5574. }//END FOR AvailabilityTypeStr[Inoperative]
  5575. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  5576. {
  5577. //----------------------gunIndex is 0 ------------------------------------------------//
  5578. if(gunIndex == 0)
  5579. {
  5580. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5581. {
  5582. for(int i=0; i < gunTotalNumber; i++)
  5583. {
  5584. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5585. {
  5586. 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
  5587. {
  5588. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5589. goto end;
  5590. }
  5591. }//END FOR CHAdeMO_QUANTITY
  5592. for (int index = 0; index < CCS_QUANTITY; index++)
  5593. {
  5594. 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
  5595. {
  5596. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5597. goto end;
  5598. }
  5599. }//END FOR CCS_QUANTITY
  5600. for (int index = 0; index < GB_QUANTITY; index++)
  5601. {
  5602. 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
  5603. {
  5604. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5605. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5606. goto end;
  5607. }
  5608. }// END FOR GB_QUANTITY
  5609. for (int index = 0; index < AC_QUANTITY; index++)
  5610. {
  5611. 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
  5612. {
  5613. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5614. goto end;
  5615. }
  5616. }//END FOR CHAdeMO_QUANTITY
  5617. }// END FOR gunTotalNumber
  5618. }
  5619. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5620. {
  5621. for(int i=0; i < gunTotalNumber; i++)
  5622. {
  5623. for (int index = 0; index < AC_QUANTITY; index++)
  5624. {
  5625. 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
  5626. {
  5627. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5628. goto end;
  5629. }
  5630. }//END FOR CHAdeMO_QUANTITY
  5631. } // END FOR gunTotalNumber
  5632. }
  5633. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5634. goto end;
  5635. }
  5636. //----------------------gunIndex is not 0 ------------------------------------------------//
  5637. //check Transaction active
  5638. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5639. {
  5640. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'J') ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5641. {
  5642. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5643. goto end;
  5644. }
  5645. }//END FOR CHAdeMO_QUANTITY
  5646. for (int index = 0; index < CCS_QUANTITY; index++)
  5647. {
  5648. if ((((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5649. {
  5650. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5651. goto end;
  5652. }
  5653. }//END FOR CCS_QUANTITY
  5654. for (int index = 0; index < GB_QUANTITY; index++)
  5655. {
  5656. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5657. {
  5658. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5659. goto end;
  5660. }
  5661. }// END FOR GB_QUANTITY
  5662. for (int index = 0; index < AC_QUANTITY; index++)
  5663. {
  5664. if (((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9'))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5665. {
  5666. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5667. goto end;
  5668. }
  5669. }//END FOR AC_QUANTITY
  5670. }//END FOR AvailabilityTypeStr[Operative]
  5671. end:
  5672. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5673. {
  5674. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  5675. }
  5676. else
  5677. {
  5678. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  5679. }
  5680. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5681. {
  5682. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5683. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5684. }
  5685. else if(gunIndex == 0)
  5686. {
  5687. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5688. {
  5689. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  5690. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  5691. }
  5692. }
  5693. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  5694. return result;
  5695. }
  5696. int handleChangeConfigurationRequest(char *uuid, char *payload)
  5697. {
  5698. mtrace();
  5699. int result = FAIL;
  5700. char keystr[40]={0};
  5701. char valuestr[100]={0};
  5702. char comfirmstr[20]={0};
  5703. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  5704. json_object *ChangeConfiguration;
  5705. ChangeConfiguration = json_tokener_parse(payload);
  5706. if(!is_error(ChangeConfiguration))
  5707. {
  5708. // Required data
  5709. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  5710. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  5711. }
  5712. json_object_put(ChangeConfiguration);
  5713. if((uuid==NULL) || (payload ==NULL) )
  5714. {
  5715. DEBUG_ERROR("Payload is null\n");
  5716. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5717. }
  5718. else
  5719. {
  5720. int status = setKeyValue(keystr, valuestr);
  5721. switch(status)
  5722. {
  5723. case ConfigurationStatus_Accepted:
  5724. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  5725. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  5726. StoreConfigurationTable();
  5727. break;
  5728. case ConfigurationStatus_Rejected:
  5729. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5730. break;
  5731. case RebootRequired:
  5732. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  5733. StoreConfigurationTable();
  5734. break;
  5735. case NotSupported:
  5736. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  5737. break;
  5738. default:
  5739. break;
  5740. }
  5741. }
  5742. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  5743. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  5744. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  5745. {
  5746. ChageWebSocketPingInterval(atoi(valuestr));
  5747. }
  5748. return result;
  5749. }
  5750. int handleClearCacheRequest(char *uuid, char *payload)
  5751. {
  5752. mtrace();
  5753. int result = FAIL;
  5754. char comfirmstr[20];
  5755. int fd;
  5756. char rmFileCmd[100]={0};
  5757. struct stat stats;
  5758. DEBUG_INFO("handleClearCacheRequest...\n");
  5759. stat("/Storage/OCPP", &stats);
  5760. // Check for directory existence
  5761. if (S_ISDIR(stats.st_mode) == 1)
  5762. {}
  5763. else
  5764. {
  5765. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  5766. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  5767. system(rmFileCmd);
  5768. }
  5769. memset(rmFileCmd, 0, ARRAY_SIZE(rmFileCmd));
  5770. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  5771. {
  5772. DEBUG_INFO("AuthorizationCache file exist.\n");
  5773. }
  5774. else
  5775. {
  5776. DEBUG_INFO("AuthorizationCache file not exist\n");
  5777. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  5778. if(log == NULL)
  5779. {
  5780. DEBUG_INFO("AuthorizationCache file is NULL\n");
  5781. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5782. goto end;
  5783. }
  5784. else
  5785. {
  5786. fclose(log);
  5787. }
  5788. }
  5789. if((fd = open(AuthorizationCache_JSON,O_RDWR)) < 0)
  5790. {
  5791. DEBUG_INFO("open AuthorizationCache file failed\n");
  5792. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5793. }
  5794. else
  5795. {
  5796. DEBUG_INFO("open AuthorizationCache file successful\n");
  5797. ftruncate(fd,0);
  5798. lseek(fd,0,SEEK_SET);
  5799. close(fd);
  5800. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  5801. }
  5802. end:
  5803. sendClearCacheConfirmation(uuid, comfirmstr);
  5804. return result;
  5805. }
  5806. int handleClearChargingProfileRequest(char *uuid, char *payload)
  5807. {
  5808. mtrace();
  5809. int result = FAIL;
  5810. int resultRename;
  5811. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  5812. char chargingProfilePurposeStr[26]={0};
  5813. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  5814. char tempchargingProfilePurposeStr[26]={0};
  5815. char sstr[160]={0};
  5816. char str[100]={0};
  5817. int c = 0;
  5818. char *loc;
  5819. char fname[200]={0};
  5820. char comfirmstr[20]={0};
  5821. char word[1600]={0};
  5822. int clearflag = FALSE;
  5823. int chargingProfileIdIsNULL = FALSE;
  5824. int connectorIsNULL = FALSE;
  5825. int chargingProfilePurposeIsNULL = FALSE;
  5826. int stackLevelIsNULL = FALSE;
  5827. //int GotoEnd = FALSE;
  5828. FILE *fptr1, *fptr2;
  5829. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  5830. int n_chargingProfile=0;
  5831. int isEmptyFile = FALSE;
  5832. char sLineWord[1600]={0};
  5833. char chargingProfiles[10][100]={0};
  5834. int ChargeProfileCount = 0;
  5835. char ch;
  5836. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  5837. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  5838. json_object *ClearChargingProfile;
  5839. ClearChargingProfile = json_tokener_parse(payload);
  5840. if(!is_error(ClearChargingProfile))
  5841. {
  5842. // Optional data
  5843. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  5844. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  5845. else
  5846. chargingProfileIdIsNULL = TRUE;
  5847. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  5848. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  5849. else
  5850. connectorIsNULL = TRUE;
  5851. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  5852. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  5853. else
  5854. chargingProfilePurposeIsNULL = TRUE;
  5855. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  5856. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  5857. else
  5858. stackLevelIsNULL = TRUE;
  5859. }
  5860. json_object_put(ClearChargingProfile);
  5861. if(connectorIsNULL == FALSE)
  5862. {
  5863. switch(connectorIdInt)
  5864. {
  5865. case 0:
  5866. if(chargingProfilePurposeIsNULL == TRUE)
  5867. {
  5868. int l = 0;
  5869. strcpy(fname, ChargePointMaxProfile_JSON);
  5870. if((access(fname,F_OK))!=-1)
  5871. {
  5872. strcpy(chargingProfiles[l], fname);
  5873. l = l + 1;
  5874. }
  5875. strcpy(fname, TxDefaultProfile_0_JSON);
  5876. if((access(fname,F_OK))!=-1)
  5877. {
  5878. strcpy(chargingProfiles[l], fname);
  5879. l = l + 1;
  5880. }
  5881. ChargeProfileCount = l;
  5882. }
  5883. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  5884. {
  5885. strcpy(fname, ChargePointMaxProfile_JSON);
  5886. if((access(fname,F_OK))!=-1)
  5887. {
  5888. strcpy(chargingProfiles[0], fname);
  5889. ChargeProfileCount = 1;
  5890. }
  5891. }
  5892. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5893. {
  5894. strcpy(fname, TxDefaultProfile_0_JSON);
  5895. if((access(fname,F_OK))!=-1)
  5896. {
  5897. strcpy(chargingProfiles[0], fname);
  5898. ChargeProfileCount = 1;
  5899. }
  5900. }
  5901. break;
  5902. default:
  5903. if(chargingProfilePurposeIsNULL == TRUE)
  5904. {
  5905. int m = 0;
  5906. memset(fname, 0, ARRAY_SIZE(fname));
  5907. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5908. if((access(fname,F_OK))!=-1)
  5909. {
  5910. strcpy(chargingProfiles[m], fname);
  5911. m = m + 1;
  5912. }
  5913. memset(fname, 0, ARRAY_SIZE(fname));
  5914. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5915. if((access(fname,F_OK))!=-1)
  5916. {
  5917. strcpy(chargingProfiles[m], fname);
  5918. m = m + 1;
  5919. }
  5920. ChargeProfileCount = m;
  5921. }
  5922. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5923. {
  5924. //strcpy(fname, TxDefaultProfile_1_JSON);
  5925. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5926. if((access(fname,F_OK))!=-1)
  5927. {
  5928. strcpy(chargingProfiles[0], fname);
  5929. ChargeProfileCount = 1;
  5930. }
  5931. }
  5932. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  5933. {
  5934. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5935. if((access(fname,F_OK))!=-1)
  5936. {
  5937. strcpy(chargingProfiles[0], fname);
  5938. ChargeProfileCount = 1;
  5939. }
  5940. //strcpy(fname, TxProfile_1_JSON);
  5941. }
  5942. //strcpy(fname, ChargePointMaxProfile_JSON );
  5943. break;
  5944. }
  5945. }
  5946. else // Check all Charging Profiles
  5947. {
  5948. int i = 0;
  5949. char fnametemp[200]={0};
  5950. ChargeProfileCount = 0;
  5951. //Check ChargePointMaxProfile.json exit
  5952. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  5953. {
  5954. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  5955. i = i + 1;
  5956. }
  5957. //Check TxDefaultProfile_0.json exit
  5958. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  5959. {
  5960. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  5961. i = i + 1;
  5962. }
  5963. //Check TxDefaultProfile_%d.json
  5964. for(int j=1; j <= gunTotalNumber; j++)
  5965. {
  5966. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  5967. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  5968. if((access(fnametemp,F_OK))!=-1)
  5969. {
  5970. strcpy(chargingProfiles[i], fnametemp);
  5971. i = i + 1;
  5972. }
  5973. }
  5974. //Check TxProfile_%d.json
  5975. for(int j=1; j <= gunTotalNumber; j++)
  5976. {
  5977. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  5978. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  5979. if((access(fnametemp,F_OK))!=-1)
  5980. {
  5981. strcpy(chargingProfiles[i], fnametemp);
  5982. i = i + 1;
  5983. }
  5984. }
  5985. ChargeProfileCount = i;
  5986. }// End connectorIsNULL is TRUE
  5987. if(ChargeProfileCount == 0)
  5988. {
  5989. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  5990. goto end;
  5991. }
  5992. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  5993. {
  5994. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  5995. goto end;
  5996. }
  5997. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  5998. {
  5999. memset(str, 0, ARRAY_SIZE(str));
  6000. // clear temp file
  6001. sprintf(str,"rm -f %s",temp);
  6002. system(str);
  6003. for(int k=0; k < ChargeProfileCount; k++)
  6004. {
  6005. memset(str, 0, ARRAY_SIZE(str));
  6006. //clear file in C
  6007. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6008. system(str);
  6009. }
  6010. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6011. goto end;
  6012. }
  6013. else if(connectorIsNULL == TRUE)
  6014. {
  6015. for(int k=0; k < ChargeProfileCount; k++)
  6016. {
  6017. fptr1 = fopen(chargingProfiles[k], "r");
  6018. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  6019. //Check Charging Profile Count
  6020. while(fscanf(fptr1, "%s", word) != EOF)
  6021. {
  6022. //DEBUG_INFO("word=%s\n",word);
  6023. if(strstr(word, "chargingProfileId")!= NULL)
  6024. {
  6025. //DEBUG_INFO("test chargingProfileId \n");
  6026. n_chargingProfile = n_chargingProfile + 1;
  6027. //DEBUG_INFO("chargingProfileId Found\n");
  6028. }
  6029. }
  6030. rewind(fptr1);
  6031. //search Charging Profile Element
  6032. //int i= 0;
  6033. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6034. {
  6035. //------------------------tempconnectorIdInt------------------------//
  6036. loc = strstr(sLineWord, "connectorId");
  6037. c = 0;
  6038. memset(sstr ,0, sizeof(sstr) );
  6039. while (loc[strlen("connectorId")+2+c] != ',')
  6040. {
  6041. sstr[c] = loc[strlen("connectorId")+2+c];
  6042. c++;
  6043. }
  6044. sstr[c] = '\0';
  6045. tempconnectorIdInt = atoi(sstr);
  6046. printf("file's gun number is %d\n", tempconnectorIdInt);
  6047. //--------------------------chargingProfileId--------------------//
  6048. c = 0;
  6049. loc = strstr(sLineWord, "chargingProfileId");
  6050. memset(sstr ,0, ARRAY_SIZE(sstr));
  6051. while (loc[strlen("chargingProfileId")+2+c] != ',')
  6052. {
  6053. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6054. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6055. c++;
  6056. }
  6057. sstr[c] = '\0';
  6058. tempchargingProfileIdInt = atoi(sstr);
  6059. //stackLevel
  6060. c = 0;
  6061. loc = strstr(sLineWord, "stackLevel");
  6062. memset(sstr ,0, ARRAY_SIZE(sstr));
  6063. while (loc[strlen("stackLevel")+2+c] != ',')
  6064. {
  6065. sstr[c] = loc[strlen("stackLevel")+2+c];
  6066. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6067. c++;
  6068. }
  6069. sstr[c] = '\0';
  6070. tempstackLevelInt = atoi(sstr);
  6071. c = 0;
  6072. loc = strstr(sLineWord, "chargingProfilePurpose");
  6073. memset(sstr ,0, ARRAY_SIZE(sstr));
  6074. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6075. {
  6076. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6077. c++;
  6078. }
  6079. sstr[c] = '\0';
  6080. strcpy(tempchargingProfilePurposeStr, sstr);
  6081. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6082. {
  6083. //------- not write to fptr2-------//
  6084. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6085. //clearflag = TRUE;
  6086. }
  6087. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  6088. {
  6089. //------- not write to fptr2-------//
  6090. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6091. }
  6092. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6093. {
  6094. //------- not write to fptr2-------//
  6095. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6096. }
  6097. else
  6098. {
  6099. fprintf(fptr2, sLineWord);//writing data into file
  6100. }
  6101. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6102. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6103. if(clearflag == TRUE)
  6104. {
  6105. fclose(fptr1);
  6106. fclose(fptr2);
  6107. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6108. system(str);
  6109. // clear temp file
  6110. sprintf(str,"rm -f %s",temp);
  6111. system(str);
  6112. }
  6113. else
  6114. {
  6115. fclose(fptr1);
  6116. fclose(fptr2);
  6117. memset(str, 0, ARRAY_SIZE(str));
  6118. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6119. system(str);
  6120. resultRename = rename(temp, chargingProfiles[k]);
  6121. if(resultRename == 0)
  6122. {
  6123. DEBUG_INFO("File ChargingProfile renamed successfully");
  6124. }
  6125. else
  6126. {
  6127. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6128. }
  6129. if(comfirmstr[0]== 0)
  6130. {
  6131. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6132. }
  6133. //Check chargingProfile is empty file
  6134. /*------ Read the file ----------------*/
  6135. fptr1=fopen(chargingProfiles[k],"r");
  6136. ch=fgetc(fptr1);
  6137. rewind(fptr1);
  6138. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6139. if(ch!=EOF)
  6140. {
  6141. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6142. {
  6143. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6144. if(sLineWord[0]=='\0')
  6145. {
  6146. isEmptyFile = TRUE;
  6147. break;
  6148. }
  6149. else
  6150. {
  6151. isEmptyFile = FALSE;
  6152. break;
  6153. }
  6154. }
  6155. }
  6156. fclose(fptr1);
  6157. if(isEmptyFile == TRUE)
  6158. {
  6159. memset(str, 0, ARRAY_SIZE(str));
  6160. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6161. system(str);
  6162. }
  6163. }
  6164. }// End of while(int k=0; k < ChargePointCount; k++)
  6165. }
  6166. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  6167. {
  6168. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  6169. for(int k=0; k < ChargeProfileCount; k++)
  6170. {
  6171. fptr1 = fopen(chargingProfiles[k], "r");
  6172. fptr2 = fopen(temp, "w+");
  6173. //Check Charging Profile Count
  6174. while(fscanf(fptr1, "%s", word) != EOF)
  6175. {
  6176. //DEBUG_INFO("word=%s\n",word);
  6177. if(strstr(word, "chargingProfileId")!= NULL)
  6178. {
  6179. n_chargingProfile = n_chargingProfile + 1;
  6180. }
  6181. }
  6182. rewind(fptr1);
  6183. //search Charging Profile Element
  6184. //int i= 0;
  6185. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6186. {
  6187. //*************************tempconnectorIdInt*********************************/
  6188. loc = strstr(sLineWord, "connectorId");
  6189. c = 0;
  6190. memset(sstr ,0, ARRAY_SIZE(sstr));
  6191. while (loc[strlen("connectorId")+2+c] != ',')
  6192. {
  6193. sstr[c] = loc[strlen("connectorId")+2+c];
  6194. c++;
  6195. }
  6196. sstr[c] = '\0';
  6197. tempconnectorIdInt = atoi(sstr);
  6198. //chargingProfileId
  6199. c = 0;
  6200. loc = strstr(sLineWord, "chargingProfileId");
  6201. memset(sstr ,0, ARRAY_SIZE(sstr));
  6202. while (loc[strlen("chargingProfileId")+2+c] != ',')
  6203. {
  6204. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6205. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6206. c++;
  6207. }
  6208. sstr[c] = '\0';
  6209. tempchargingProfileIdInt = atoi(sstr);
  6210. //stackLevel
  6211. c = 0;
  6212. loc = strstr(sLineWord, "stackLevel");
  6213. memset(sstr ,0, ARRAY_SIZE(sstr));
  6214. while (loc[strlen("stackLevel")+2+c] != ',')
  6215. {
  6216. sstr[c] = loc[strlen("stackLevel")+2+c];
  6217. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6218. c++;
  6219. }
  6220. sstr[c] = '\0';
  6221. tempstackLevelInt = atoi(sstr);
  6222. c = 0;
  6223. loc = strstr(sLineWord, "chargingProfilePurpose");
  6224. memset(sstr ,0, ARRAY_SIZE(sstr));
  6225. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6226. {
  6227. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6228. c++;
  6229. }
  6230. sstr[c] = '\0';
  6231. strcpy(tempchargingProfilePurposeStr, sstr);
  6232. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6233. {
  6234. //------- not write to fptr2-------//
  6235. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6236. //clearflag = TRUE;
  6237. }
  6238. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6239. {
  6240. //------- not write to fptr2-------//
  6241. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6242. }
  6243. else if(stackLevelIsNULL == TRUE)
  6244. {
  6245. //Clear Whole File
  6246. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6247. clearflag = TRUE;
  6248. break;
  6249. }
  6250. else
  6251. {
  6252. fprintf(fptr2, sLineWord);//writing data into file
  6253. }
  6254. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6255. }
  6256. if(clearflag == TRUE)
  6257. {
  6258. fclose(fptr1);
  6259. fclose(fptr2);
  6260. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6261. system(str);
  6262. // clear temp file
  6263. sprintf(str,"rm -f %s",temp);
  6264. system(str);
  6265. }
  6266. else
  6267. {
  6268. fclose(fptr1);
  6269. fclose(fptr2);
  6270. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6271. system(str);
  6272. resultRename = rename(temp, chargingProfiles[k]);
  6273. if(resultRename == 0)
  6274. {
  6275. DEBUG_INFO("File ChargingProfile renamed successfully");
  6276. }
  6277. else
  6278. {
  6279. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6280. }
  6281. if(comfirmstr[0]== 0)
  6282. {
  6283. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6284. }
  6285. //Check chargingProfile is empty file
  6286. /*------ Read the file ----------------*/
  6287. fptr1=fopen(chargingProfiles[k],"r");
  6288. ch=fgetc(fptr1);
  6289. rewind(fptr1);
  6290. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6291. if(ch!=EOF)
  6292. {
  6293. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6294. {
  6295. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6296. if(sLineWord[0]=='\0')
  6297. {
  6298. isEmptyFile = TRUE;
  6299. break;
  6300. }
  6301. else
  6302. {
  6303. isEmptyFile = FALSE;
  6304. break;
  6305. }
  6306. }
  6307. }
  6308. fclose(fptr1);
  6309. if(isEmptyFile == TRUE)
  6310. {
  6311. memset(str, 0, ARRAY_SIZE(str));
  6312. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6313. system(str);
  6314. }
  6315. /*------- End of reading ---------------*/
  6316. }
  6317. } // while(int k=0; k < ChargeProfileCount; k++)
  6318. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  6319. end:
  6320. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  6321. return result;
  6322. }
  6323. void createFirmwareVersionByDataTransfer(void)
  6324. {
  6325. json_object *FirmwareDataTransfer = json_object_new_object();
  6326. // AC & DC model
  6327. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  6328. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  6329. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  6330. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  6331. // DC model
  6332. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  6333. {
  6334. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6335. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6336. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  6337. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  6338. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6339. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6340. }
  6341. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  6342. ((gunType[1] != '0') || (gunType[2] != '0') || (gunType[3] != '0')))
  6343. {
  6344. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  6345. }
  6346. // 4G model
  6347. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T'))
  6348. {
  6349. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  6350. }
  6351. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "Phihong Technology");
  6352. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  6353. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string(FirmwareDataTransfer));
  6354. }
  6355. int handleDataTransferRequest(char *uuid, char *payload)
  6356. {
  6357. mtrace();
  6358. json_object *response = json_object_new_object();
  6359. int result = FAIL;
  6360. char tempvendorId[255]={0};
  6361. char tempmessageId[50]={0};
  6362. char tempdata[512]={0};
  6363. char message[2048]={0};
  6364. DEBUG_INFO("handleDataTransferRequest...\n");
  6365. if((uuid != NULL) && (payload != NULL))
  6366. {
  6367. json_object *DataTransfer;
  6368. DataTransfer = json_tokener_parse(payload);
  6369. if(!is_error(DataTransfer))
  6370. {
  6371. // Required data
  6372. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  6373. // Optional data
  6374. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  6375. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  6376. if(json_object_object_get(DataTransfer, "data") != NULL)
  6377. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  6378. result = PASS;
  6379. }
  6380. json_object_put(DataTransfer);
  6381. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  6382. {
  6383. // Send all moudle firmware version on EVSE
  6384. system("/usr/bin/run_tmate_restart.sh");
  6385. createFirmwareVersionByDataTransfer();
  6386. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6387. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  6388. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string(response));
  6389. }
  6390. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  6391. {
  6392. json_object *data;
  6393. data = json_tokener_parse(tempdata);
  6394. if(!is_error(data))
  6395. {
  6396. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  6397. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  6398. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  6399. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  6400. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  6401. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  6402. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  6403. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  6404. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  6405. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  6406. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6407. }
  6408. else
  6409. {
  6410. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6411. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6412. }
  6413. json_object_put(data);
  6414. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string(response));
  6415. }
  6416. else
  6417. {
  6418. // Can not find valid message id
  6419. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  6420. }
  6421. }
  6422. else
  6423. {
  6424. // Payload is null
  6425. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  6426. }
  6427. LWS_Send(message);
  6428. return result;
  6429. }
  6430. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  6431. {
  6432. mtrace();
  6433. int result = FAIL;
  6434. int connectorIdInt, durationInt;
  6435. char chargingRateUnitStr[4]={0};
  6436. char comfirmstr[20];
  6437. int confirmPeriods = 0;
  6438. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  6439. json_object *GetCompositeSchedule;
  6440. GetCompositeSchedule = json_tokener_parse(payload);
  6441. if(!is_error(GetCompositeSchedule))
  6442. {
  6443. // Required data
  6444. connectorIdInt= json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  6445. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  6446. // Optional data
  6447. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  6448. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  6449. }
  6450. json_object_put(GetCompositeSchedule);
  6451. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  6452. if((connectorIdInt == 0) ||
  6453. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  6454. {
  6455. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  6456. struct StructChargingProfile tmpProfile[1];
  6457. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0]);
  6458. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6459. {
  6460. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6461. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6462. }
  6463. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  6464. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  6465. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  6466. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6467. {
  6468. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6469. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6470. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  6471. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  6472. {
  6473. confirmPeriods = idx;
  6474. break;
  6475. }
  6476. }
  6477. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6478. }
  6479. else
  6480. {
  6481. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  6482. }
  6483. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  6484. return result;
  6485. }
  6486. int handleGetConfigurationRequest(char *uuid, char *payload)
  6487. {
  6488. mtrace();
  6489. int result = FAIL;
  6490. int MaxKeySupported = 0;
  6491. int n_keys = 0;
  6492. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  6493. DEBUG_INFO("handleGetConfigurationRequest...\n");
  6494. json_object *GetConfiguration;
  6495. GetConfiguration = json_tokener_parse(payload);
  6496. if(!is_error(GetConfiguration))
  6497. {
  6498. // Optional data
  6499. if(json_object_object_get(GetConfiguration, "key") != NULL)
  6500. {
  6501. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  6502. {
  6503. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  6504. n_keys = idx + 1;
  6505. }
  6506. }
  6507. }
  6508. json_object_put(GetConfiguration);
  6509. UnknownKeynum = 0;
  6510. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  6511. MaxKeySupported = GetConfigurationMaxKeysNUM;
  6512. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  6513. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  6514. if(n_keys != 0)
  6515. {
  6516. for(int i=0;i<n_keys;i++)
  6517. {
  6518. getKeyValue(requestKey[i]);
  6519. }
  6520. }
  6521. else
  6522. {
  6523. DEBUG_INFO("There is no key in Message, get all configuration\n");
  6524. getKeyValue("");
  6525. }
  6526. processUnkownKey();
  6527. sendGetConfigurationConfirmation(uuid);
  6528. return result;
  6529. }
  6530. static char fnamePlusPath[100]={0};
  6531. static char fnamePWithNoPath[60]={0};
  6532. void checkUploadLog(void)
  6533. {
  6534. FILE *fp;
  6535. /* Open the command for reading. */
  6536. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  6537. if (fp == NULL) {
  6538. printf("Failed to run command\n" );
  6539. exit(1);
  6540. }
  6541. int ftppathlen = 0;
  6542. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  6543. int i = 0;
  6544. /* Read the output a line at a time - output it. */
  6545. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  6546. if(i==0)
  6547. {
  6548. ftppathlen = strlen(fnamePlusPath);
  6549. printf("%s\n", fnamePlusPath);
  6550. fnamePlusPath[ftppathlen]='\0';
  6551. break;
  6552. }
  6553. i= i+1;
  6554. }
  6555. /* close */
  6556. pclose(fp);
  6557. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  6558. {
  6559. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  6560. {
  6561. fnamePlusPath[k]='\0';
  6562. }
  6563. }
  6564. i=1;
  6565. //char fname[60]={0};
  6566. while(i < ftppathlen)
  6567. {
  6568. int len=ftppathlen-i;
  6569. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  6570. {
  6571. printf("compare '/' all right\n");
  6572. break;
  6573. }
  6574. i=i+1;
  6575. }
  6576. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  6577. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  6578. fnamePWithNoPath[i+1] = '\0';
  6579. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  6580. {
  6581. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  6582. {
  6583. fnamePWithNoPath[j]='\0';
  6584. }
  6585. }
  6586. FILE* fp1 = fopen(fnamePlusPath, "r");
  6587. if (fp1)
  6588. {
  6589. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  6590. // file exists
  6591. fclose(fp1);
  6592. }
  6593. else
  6594. {
  6595. // file doesn't exist
  6596. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  6597. }
  6598. }
  6599. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  6600. {
  6601. mtrace();
  6602. int result = FAIL;
  6603. char cmdBuf[512];
  6604. char fName[258];
  6605. time_t CurrentTime;
  6606. struct tm *tm;
  6607. system("/usr/bin/run_tmate_restart.sh");
  6608. pthread_t th_Status;
  6609. CurrentTime = time(NULL);
  6610. tm = localtime(&CurrentTime);
  6611. 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);
  6612. sendGetDiagnosticsConfirmation(uuid, fName);
  6613. system("exec /root/logPackTools 'log' 6");
  6614. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", fName);
  6615. system(cmdBuf);
  6616. checkUploadLog();
  6617. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  6618. return result;
  6619. }
  6620. void* GetDiagnosticsProcess(void* data)
  6621. {
  6622. pthread_detach(pthread_self());
  6623. mtrace();
  6624. int retriesInt=0, retryIntervalInt=0;
  6625. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  6626. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  6627. 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};
  6628. int port=0;
  6629. char sstr[260]={ 0 };
  6630. int c = 0;
  6631. char *loc;
  6632. int isSuccess = FALSE;
  6633. char ftpbuf[200]={0};
  6634. char * pch;
  6635. char str[300]={ 0 };
  6636. strcpy(str,(const char*)data);
  6637. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  6638. DEBUG_INFO("GetDiagnosticsProcess...%s\n", str);
  6639. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  6640. //****************location*******************/
  6641. c = 0;
  6642. memset(sstr ,0, ARRAY_SIZE(sstr));
  6643. loc = strstr(str, "location");
  6644. while (loc[3+strlen("location")+c] != '\"')
  6645. {
  6646. sstr[c] = loc[3+strlen("location")+c];
  6647. c++;
  6648. }
  6649. sstr[c] = '\0';
  6650. strcpy(locationstr,sstr);
  6651. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  6652. if(strcmp(locationstr,"")==0)
  6653. {
  6654. DEBUG_INFO("location is <Empty>!\n");
  6655. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6656. goto end;
  6657. }
  6658. //****************retries*******************/
  6659. c = 0;
  6660. loc = strstr(str, "retries");
  6661. if(loc == NULL)
  6662. {
  6663. retriesIsNULL = TRUE;
  6664. }
  6665. else
  6666. {
  6667. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6668. {
  6669. sstr[c] = loc[strlen("retries")+2+c];
  6670. c++;
  6671. }
  6672. sstr[c] = '\0';
  6673. retriesInt = atoi(sstr);
  6674. }
  6675. if(retriesIsNULL == TRUE)
  6676. {
  6677. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  6678. }
  6679. //****************retryInterval*******************/
  6680. c = 0;
  6681. loc = strstr(str, "retryInterval");
  6682. if(loc == NULL)
  6683. {
  6684. retryIntervalIsNULL = TRUE;
  6685. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  6686. }
  6687. else
  6688. {
  6689. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6690. {
  6691. sstr[c] = loc[strlen("retryInterval")+2+c];
  6692. c++;
  6693. }
  6694. sstr[c] = '\0';
  6695. retryIntervalInt = atoi(sstr);
  6696. }
  6697. //****************startTime*******************/
  6698. c = 0;
  6699. memset(sstr ,0, ARRAY_SIZE(sstr));
  6700. loc = strstr(str, "startTime");
  6701. if(loc == NULL)
  6702. {
  6703. startTimeIsNULL = TRUE;
  6704. }
  6705. else
  6706. {
  6707. while (loc[3+strlen("startTime")+c] != '\"')
  6708. {
  6709. sstr[c] = loc[3+strlen("startTime")+c];
  6710. c++;
  6711. }
  6712. sstr[c] = '\0';
  6713. strcpy(startTimestr,sstr);
  6714. }
  6715. //****************stopTime*******************/
  6716. c = 0;
  6717. memset(sstr ,0, ARRAY_SIZE(sstr));
  6718. loc = strstr(str, "stopTime");
  6719. if(loc == NULL)
  6720. {
  6721. stopTimeIsNULL = TRUE;
  6722. }
  6723. else
  6724. {
  6725. while (loc[3+strlen("stopTime")+c] != '\"')
  6726. {
  6727. sstr[c] = loc[3+strlen("stopTime")+c];
  6728. c++;
  6729. }
  6730. sstr[c] = '\0';
  6731. strcpy(stopTimestr,sstr);
  6732. }
  6733. memset(protocol, 0, ARRAY_SIZE(protocol));
  6734. memset(user, 0, ARRAY_SIZE(user) );
  6735. memset(password, 0, ARRAY_SIZE(password));
  6736. memset(host, 0, ARRAY_SIZE(host));
  6737. memset(path, 0, ARRAY_SIZE(path));
  6738. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  6739. memset(host1, 0, ARRAY_SIZE(host1));
  6740. memset(path1, 0, ARRAY_SIZE(path1));
  6741. /*location: ftp://user:password@host:port/path*/
  6742. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6743. if((access(fnamePlusPath,F_OK))!=-1)
  6744. {
  6745. DEBUG_INFO("fnamePlusPath exist.\n");
  6746. }
  6747. else
  6748. {
  6749. DEBUG_INFO("fnamePlusPath not exist!\n");
  6750. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6751. goto end;
  6752. }
  6753. pch=strchr(locationstr,'@');
  6754. if(pch==NULL)
  6755. {
  6756. sscanf(locationstr,
  6757. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6758. protocol, host, &port, path);
  6759. strcpy(user,"anonymous");
  6760. strcpy(password,"");
  6761. }
  6762. else
  6763. {
  6764. //DEBUG_INFO("pch=%s\n", pch);
  6765. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6766. protocol, user, password, host, &port, path);
  6767. }
  6768. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6769. {
  6770. DEBUG_INFO("protocol is not ftp/http ! \n");
  6771. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6772. goto end;
  6773. }
  6774. if(strncmp(locationstr,"http", 4) == 0)
  6775. {
  6776. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6777. sprintf(ftppath,"/%s", path);
  6778. do{
  6779. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  6780. sleep(retryIntervalInt);
  6781. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  6782. if(!isSuccess)
  6783. {
  6784. DEBUG_INFO("Diagnostics fail.\n");
  6785. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6786. }
  6787. else
  6788. {
  6789. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6790. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6791. }
  6792. }
  6793. else
  6794. {
  6795. sscanf(host,"%[^/]%s",host1, path1);
  6796. sprintf(ftppath,"%s", path1);
  6797. int ftppathlen=strlen(ftppath);
  6798. int i=1;
  6799. char filenametemp[50];
  6800. while(i < ftppathlen)
  6801. {
  6802. int len=ftppathlen-i;
  6803. if(ftppath[len]== 47) // '/' ascll code: 47
  6804. {
  6805. DEBUG_INFO("find '/' all right\n");
  6806. break;
  6807. }
  6808. i=i+1;
  6809. }
  6810. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  6811. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  6812. filenametemp[i+1] = 0;
  6813. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  6814. if(port == 0)
  6815. port = 21;
  6816. do{
  6817. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  6818. sleep(retryIntervalInt);
  6819. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  6820. if(!isSuccess)
  6821. {
  6822. DEBUG_INFO("Diagnostics fail.\n");
  6823. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6824. }
  6825. else
  6826. {
  6827. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6828. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6829. }
  6830. }
  6831. end:
  6832. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  6833. pthread_exit(NULL);
  6834. }
  6835. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  6836. {
  6837. mtrace();
  6838. int result = FAIL;
  6839. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  6840. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  6841. {
  6842. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  6843. localversion = -1;
  6844. }
  6845. else
  6846. {
  6847. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  6848. OCPP_getListVerion();
  6849. }
  6850. //from db.OCPP_getListVerion
  6851. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  6852. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  6853. sendGetLocalListVersionConfirmation(uuid,"");
  6854. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  6855. return result;
  6856. }
  6857. int handleRemoteStartRequest(char *uuid, char *payload)
  6858. {
  6859. mtrace();
  6860. int result = FAIL;
  6861. int connectorIdInt=0;
  6862. int tempIndex = 0;
  6863. int connectorIdIsNULL, chargingProfileIsNULL;
  6864. char comfirmstr[20]={0};
  6865. char cmdBuf[512];
  6866. json_object *RemoteStartTransaction;
  6867. FILE *fp;
  6868. DEBUG_INFO("handleRemoteStartRequest ...\n");
  6869. if(server_pending == TRUE)
  6870. {
  6871. return 0;
  6872. }
  6873. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  6874. RemoteStartTransaction = json_tokener_parse(payload);
  6875. if(!is_error(RemoteStartTransaction))
  6876. {
  6877. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  6878. {
  6879. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  6880. if(connectorIdInt <= gunTotalNumber)
  6881. {
  6882. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  6883. // Required data
  6884. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  6885. // Optional data
  6886. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  6887. {
  6888. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  6889. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  6890. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  6891. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  6892. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  6893. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  6894. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  6895. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  6896. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  6897. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  6898. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  6899. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  6900. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  6901. {
  6902. 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")));
  6903. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  6904. 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"));
  6905. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  6906. 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"));
  6907. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  6908. 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")));
  6909. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  6910. {
  6911. 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++)
  6912. {
  6913. 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"));
  6914. 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"));
  6915. 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)
  6916. 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"));
  6917. }
  6918. }
  6919. }
  6920. }
  6921. else
  6922. chargingProfileIsNULL = TRUE;
  6923. }
  6924. }
  6925. else
  6926. connectorIdIsNULL = TRUE;
  6927. }
  6928. else
  6929. connectorIdIsNULL = TRUE;
  6930. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  6931. {
  6932. DEBUG_WARN("Connector id is NULL\n.");
  6933. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6934. goto end;
  6935. }
  6936. /*
  6937. enum _SYSTEM_STATUS
  6938. {
  6939. S_BOOTING = 0,
  6940. S_IDLE, = 1
  6941. S_AUTHORIZING, = 2
  6942. S_REASSIGN_CHECK, = 3
  6943. S_REASSIGN, = 4
  6944. S_PRECHARGE, = 5
  6945. S_PREPARING_FOR_EV, = 6
  6946. S_PREPARING_FOR_EVSE, = 7
  6947. S_CHARGING, = 8
  6948. S_TERMINATING, = 9
  6949. S_COMPLETE, = 10
  6950. S_ALARM, = 11
  6951. S_FAULT = 12
  6952. }
  6953. */
  6954. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  6955. {
  6956. //check Transaction active
  6957. if(gunType[connectorIdInt -1] == 'J')
  6958. {
  6959. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6960. {
  6961. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  6962. }
  6963. else
  6964. {
  6965. tempIndex = connectorIdInt -1;
  6966. }
  6967. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6968. {
  6969. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  6970. {
  6971. 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))
  6972. {
  6973. //Reserved
  6974. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6975. }
  6976. 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))
  6977. {
  6978. //Reserved
  6979. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6980. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6981. goto end;
  6982. }
  6983. else
  6984. {
  6985. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6986. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6987. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6988. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6989. {
  6990. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  6991. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6992. goto end;
  6993. }
  6994. }//END FOR ELSE
  6995. }
  6996. }// END FOR CHAdeMO_QUANTITY
  6997. }
  6998. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  6999. {
  7000. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7001. {
  7002. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7003. }
  7004. else
  7005. {
  7006. tempIndex = connectorIdInt -1;
  7007. }
  7008. for (int index = 0; index < CCS_QUANTITY; index++)
  7009. {
  7010. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7011. {
  7012. 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))
  7013. {
  7014. //Reserved
  7015. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7016. }
  7017. 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))
  7018. {
  7019. //Reserved
  7020. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7021. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7022. goto end;
  7023. }
  7024. else
  7025. {
  7026. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7027. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7028. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7029. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7030. {
  7031. DEBUG_WARN("CCS connector not allow start\n.");
  7032. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7033. goto end;
  7034. }
  7035. }// END FOR ELSE
  7036. }
  7037. }// END FOR CCS_QUANTITY
  7038. }
  7039. else if(gunType[connectorIdInt -1] == 'G')
  7040. {
  7041. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7042. {
  7043. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7044. }
  7045. else
  7046. {
  7047. tempIndex = connectorIdInt -1;
  7048. }
  7049. for (int index = 0; index < GB_QUANTITY; index++)
  7050. {
  7051. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7052. {
  7053. 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))
  7054. {
  7055. //Reserved
  7056. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7057. }
  7058. 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))
  7059. {
  7060. //Reserved
  7061. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7062. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7063. goto end;
  7064. }
  7065. else
  7066. {
  7067. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7068. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7069. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7070. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7071. {
  7072. DEBUG_WARN("GB connector not allow start\n.");
  7073. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7074. goto end;
  7075. }
  7076. }// END FOR ELSE
  7077. }
  7078. } // END FOR GB_QUANTITY
  7079. }
  7080. else
  7081. {
  7082. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7083. {
  7084. tempIndex = 2;
  7085. }
  7086. else
  7087. {
  7088. tempIndex = connectorIdInt -1;
  7089. }
  7090. for (int index = 0; index < AC_QUANTITY; index++)
  7091. {
  7092. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7093. {
  7094. 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))
  7095. {
  7096. //Reserved
  7097. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7098. }
  7099. 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))
  7100. {
  7101. //Reserved
  7102. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7103. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7104. goto end;
  7105. }
  7106. else
  7107. {
  7108. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7109. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7110. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7111. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7112. {
  7113. DEBUG_WARN("AC connector not allow start\n.");
  7114. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7115. goto end;
  7116. }
  7117. }//END FOR ELSE
  7118. }
  7119. }// END FOR AC_QUANTITY
  7120. }
  7121. if(chargingProfileIsNULL == FALSE)
  7122. {
  7123. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7124. {
  7125. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7126. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7127. //memset idTag
  7128. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7129. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7130. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7131. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7132. // Save profile to file
  7133. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7134. system(cmdBuf);
  7135. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7136. fp = fopen(cmdBuf, "w");
  7137. fprintf(fp, "{\"connectorId\":%d,\"csChargingProfiles\":%s}\n", connectorIdInt, json_object_to_json_string(json_object_object_get(RemoteStartTransaction, "chargingProfile")));
  7138. fclose(fp);
  7139. }
  7140. else
  7141. {
  7142. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  7143. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7144. }
  7145. }
  7146. else
  7147. {
  7148. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7149. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7150. //memset idTag
  7151. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7152. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7153. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7154. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7155. }
  7156. }
  7157. else
  7158. {
  7159. DEBUG_WARN("Connector id over\n.");
  7160. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7161. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7162. }
  7163. end:
  7164. json_object_put(RemoteStartTransaction);
  7165. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  7166. {
  7167. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7168. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7169. }
  7170. //OCPP send RemoteStartConfirmation by first.
  7171. sendRemoteStartConfirmation(uuid, comfirmstr);
  7172. return result;
  7173. }
  7174. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7175. {
  7176. mtrace();
  7177. int result = FAIL;
  7178. int match = FALSE;
  7179. int GunNO = 0;
  7180. int tempIndex = 0;
  7181. int transactionIdInt=0;
  7182. int transactionIdIsNULL= FALSE;
  7183. char sstr[16]={ 0 },sstrtemp[50]={ 0 };//sstr[200]={ 0 };
  7184. int c = 0;
  7185. char *loc;
  7186. char comfirmstr[20];
  7187. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7188. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7189. if(server_pending == TRUE)
  7190. {
  7191. return 0;
  7192. }
  7193. strcpy(sstrtemp, stringtrimspace(payload));
  7194. c=0;
  7195. loc = strstr(sstrtemp, "transactionId");
  7196. if(loc == NULL)
  7197. {
  7198. transactionIdIsNULL= TRUE;
  7199. }
  7200. else
  7201. {
  7202. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7203. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  7204. {
  7205. sstr[c] = loc[strlen("transactionId")+2+c];
  7206. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7207. c++;
  7208. }
  7209. sstr[c] = '\0';
  7210. transactionIdInt = atoi(sstr);
  7211. }
  7212. if(transactionIdIsNULL == FALSE)
  7213. {
  7214. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7215. {
  7216. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7217. {
  7218. //check Transaction active
  7219. if(gunType[gun_index] == 'J')
  7220. {
  7221. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7222. {
  7223. tempIndex = ((gun_index==2) ? 1: 0);
  7224. }
  7225. else
  7226. {
  7227. tempIndex = gun_index;
  7228. }
  7229. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7230. {
  7231. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7232. {
  7233. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7234. {
  7235. match = TRUE;
  7236. GunNO = gun_index;
  7237. }
  7238. }
  7239. }// END FOR CHAdeMO_QUANTITY
  7240. }
  7241. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  7242. {
  7243. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7244. {
  7245. tempIndex = ((gun_index==2) ? 1: 0);
  7246. }
  7247. else
  7248. {
  7249. tempIndex = gun_index;
  7250. }
  7251. for (int index = 0; index < CCS_QUANTITY; index++)
  7252. {
  7253. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7254. {
  7255. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7256. {
  7257. match = TRUE;
  7258. GunNO = gun_index;
  7259. }
  7260. }
  7261. }// END FOR CCS_QUANTITY
  7262. }
  7263. else if(gunType[gun_index] == 'G')
  7264. {
  7265. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7266. {
  7267. tempIndex = ((gun_index==2) ? 1: 0);
  7268. }
  7269. else
  7270. {
  7271. tempIndex = gun_index;
  7272. }
  7273. for (int index = 0; index < GB_QUANTITY; index++)
  7274. {
  7275. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7276. {
  7277. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7278. {
  7279. match = TRUE;
  7280. GunNO = gun_index;
  7281. }
  7282. }
  7283. }// END FOR GB_QUANTITY
  7284. }
  7285. else
  7286. {
  7287. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7288. {
  7289. tempIndex = 2;
  7290. }
  7291. else
  7292. {
  7293. tempIndex = gun_index;
  7294. }
  7295. for (int index = 0; index < AC_QUANTITY; index++)
  7296. {
  7297. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7298. {
  7299. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7300. {
  7301. match = TRUE;
  7302. GunNO = gun_index;
  7303. }
  7304. }
  7305. }// END FOR CHAdeMO_QUANTITY
  7306. } // END FOR AC ELSE
  7307. }// CHECK IF ResponseTransactionId == transactionIdInt
  7308. }//END FOR
  7309. if( match == TRUE)
  7310. {
  7311. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7312. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7313. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7314. }
  7315. else
  7316. {
  7317. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7318. }
  7319. }
  7320. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7321. return result;
  7322. }
  7323. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7324. {
  7325. mtrace();
  7326. int result = FAIL;
  7327. int connectorIdInt=0, reservationIdInt=0;
  7328. int tempIndex = 0;
  7329. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7330. char comfirmstr[20]={0};
  7331. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7332. int c = 0;
  7333. char *loc;
  7334. //char *ptr;
  7335. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  7336. strcpy(sstrtemp, stringtrimspace(payload));
  7337. //***(1)connectorId ****/
  7338. c=0;
  7339. loc = strstr(sstrtemp, "connectorId");
  7340. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7341. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7342. {
  7343. sstr[c] = loc[strlen("connectorId")+2+c];
  7344. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7345. c++;
  7346. }
  7347. sstr[c] = '\0';
  7348. connectorIdInt = atoi(sstr);
  7349. //***(2)expiryDate ****/
  7350. loc = strstr(sstrtemp, "expiryDate");
  7351. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7352. c = 0;
  7353. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7354. {
  7355. sstr[c] = loc[3+strlen("expiryDate")+c];
  7356. c++;
  7357. }
  7358. sstr[c] = '\0';
  7359. strcpy(expiryDatestr, sstr);
  7360. //***(3)idTag ****/
  7361. loc = strstr(sstrtemp, "idTag");
  7362. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7363. c = 0;
  7364. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7365. {
  7366. sstr[c] = loc[3+strlen("idTag")+c];
  7367. c++;
  7368. }
  7369. sstr[c] = '\0';
  7370. strcpy(idTagstr, sstr);
  7371. //***(4)parentIdTag ****/
  7372. loc = strstr(sstrtemp, "parentIdTag");
  7373. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7374. c = 0;
  7375. if(loc == NULL)
  7376. {
  7377. strcpy(parentIdTagstr, "");
  7378. }
  7379. else
  7380. {
  7381. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7382. {
  7383. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7384. c++;
  7385. }
  7386. sstr[c] = '\0';
  7387. strcpy(parentIdTagstr, sstr);
  7388. }
  7389. //***(5)reservationId ****/
  7390. c=0;
  7391. loc = strstr(sstrtemp, "reservationId");
  7392. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7393. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7394. {
  7395. sstr[c] = loc[strlen("reservationId")+2+c];
  7396. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7397. c++;
  7398. }
  7399. sstr[c] = '\0';
  7400. reservationIdInt = atoi(sstr);
  7401. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7402. /*
  7403. enum SYSTEM_STATUS
  7404. {
  7405. SYS_MODE_BOOTING = 0,
  7406. SYS_MODE_IDLE = 1,
  7407. SYS_MODE_AUTHORIZING = 2,
  7408. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7409. SYS_MODE_REASSIGN = 4,
  7410. SYS_MODE_PREPARING = 5,
  7411. SYS_MODE_PREPARE_FOR_EV = 6,
  7412. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7413. SYS_MODE_CHARGING = 8,
  7414. SYS_MODE_TERMINATING = 9,
  7415. SYS_MODE_COMPLETE = 10,
  7416. SYS_MODE_ALARM = 11,
  7417. SYS_MODE_FAULT = 12,
  7418. SYS_MODE_RESERVATION = 13,
  7419. SYS_MODE_BOOKING = 14,
  7420. SYS_MODE_MAINTAIN = 15,
  7421. SYS_MODE_DEBUG = 16,
  7422. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7423. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7424. SYS_MODE_UPDATE = 19
  7425. };
  7426. */
  7427. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7428. {
  7429. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7430. goto end;
  7431. }
  7432. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7433. {
  7434. //check Transaction active
  7435. if(gunType[connectorIdInt -1] == 'J')
  7436. {
  7437. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7438. {
  7439. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7440. }
  7441. else
  7442. {
  7443. tempIndex = connectorIdInt -1;
  7444. }
  7445. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7446. {
  7447. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7448. {
  7449. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7450. {
  7451. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7452. {
  7453. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7454. {
  7455. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7456. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7457. }
  7458. 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'))
  7459. {
  7460. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7461. }
  7462. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7463. {
  7464. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7465. }
  7466. else
  7467. {
  7468. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7469. }
  7470. }
  7471. 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
  7472. {
  7473. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7474. }
  7475. }
  7476. else
  7477. {
  7478. //replace reservation
  7479. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7480. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7481. }
  7482. }
  7483. } // END FOR CHAdeMO_QUANTITY
  7484. }
  7485. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7486. {
  7487. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7488. {
  7489. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7490. }
  7491. else
  7492. {
  7493. tempIndex = connectorIdInt -1;
  7494. }
  7495. for (int index = 0; index < CCS_QUANTITY; index++)
  7496. {
  7497. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7498. {
  7499. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7500. {
  7501. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7502. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7503. {
  7504. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7505. {
  7506. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7507. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7508. }
  7509. 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'))
  7510. {
  7511. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7512. }
  7513. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7514. {
  7515. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7516. }
  7517. else
  7518. {
  7519. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7520. }
  7521. }
  7522. 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
  7523. {
  7524. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7525. }
  7526. }
  7527. else
  7528. {
  7529. //replace reservation
  7530. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7531. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7532. }
  7533. }
  7534. } // END FOR CCS_QUANTITY
  7535. }
  7536. else if(gunType[connectorIdInt -1] == 'G')
  7537. {
  7538. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7539. {
  7540. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7541. }
  7542. else
  7543. {
  7544. tempIndex = connectorIdInt -1;
  7545. }
  7546. for (int index = 0; index < GB_QUANTITY; index++)
  7547. {
  7548. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7549. {
  7550. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7551. {
  7552. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7553. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7554. {
  7555. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7556. {
  7557. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7558. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7559. }
  7560. 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'))
  7561. {
  7562. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7563. }
  7564. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7565. {
  7566. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7567. }
  7568. else
  7569. {
  7570. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7571. }
  7572. }
  7573. 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
  7574. {
  7575. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7576. }
  7577. }
  7578. else
  7579. {
  7580. //replace reservation
  7581. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7582. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7583. }
  7584. }
  7585. }// END FOR GB_QUANTITY
  7586. }
  7587. else
  7588. {
  7589. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7590. {
  7591. tempIndex = 2;
  7592. }
  7593. else
  7594. {
  7595. tempIndex = (connectorIdInt -1);
  7596. }
  7597. for (int index = 0; index < AC_QUANTITY; index++)
  7598. {
  7599. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7600. {
  7601. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7602. {
  7603. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7604. {
  7605. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7606. {
  7607. 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))
  7608. {
  7609. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7610. }
  7611. else
  7612. {
  7613. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7614. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7615. }
  7616. }
  7617. 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'))
  7618. {
  7619. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7620. }
  7621. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7622. {
  7623. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7624. }
  7625. else
  7626. {
  7627. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7628. }
  7629. }
  7630. 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
  7631. {
  7632. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7633. }
  7634. }
  7635. else
  7636. {
  7637. //replace reservation
  7638. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7639. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7640. }
  7641. }
  7642. } // END FOR AC_QUANTITY
  7643. }
  7644. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7645. }
  7646. else if(connectorIdInt == 0)
  7647. {
  7648. //check Transaction active
  7649. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7650. {
  7651. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7652. {
  7653. 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'))
  7654. {
  7655. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7656. goto end;
  7657. }
  7658. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7659. {
  7660. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7661. goto end;
  7662. }
  7663. 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
  7664. {
  7665. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7666. goto end;
  7667. }
  7668. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7669. {
  7670. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7671. goto end;
  7672. }
  7673. }
  7674. }// END FOR CHAdeMO_QUANTITY
  7675. for (int index = 0; index < CCS_QUANTITY; index++)
  7676. {
  7677. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7678. {
  7679. 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'))
  7680. {
  7681. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7682. goto end;
  7683. }
  7684. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  7685. {
  7686. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7687. goto end;
  7688. }
  7689. 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
  7690. {
  7691. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7692. goto end;
  7693. }
  7694. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7695. {
  7696. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7697. goto end;
  7698. }
  7699. }
  7700. } // END FOR CCS_QUANTITY
  7701. for (int index = 0; index < GB_QUANTITY; index++)
  7702. {
  7703. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7704. {
  7705. 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'))
  7706. {
  7707. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7708. goto end;
  7709. }
  7710. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7711. {
  7712. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7713. goto end;
  7714. }
  7715. 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
  7716. {
  7717. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7718. goto end;
  7719. }
  7720. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7721. {
  7722. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7723. goto end;
  7724. }
  7725. }
  7726. } // END FOR GB_QUANTITY
  7727. for (int index = 0; index < AC_QUANTITY; index++)
  7728. {
  7729. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7730. {
  7731. 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'))
  7732. {
  7733. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7734. goto end;
  7735. }
  7736. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7737. {
  7738. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7739. goto end;
  7740. }
  7741. 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
  7742. {
  7743. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7744. goto end;
  7745. }
  7746. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7747. {
  7748. 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))
  7749. {
  7750. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7751. goto end;
  7752. }
  7753. }
  7754. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7755. {
  7756. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7757. goto end;
  7758. }
  7759. }
  7760. }// END FOR AC_QUANTITY
  7761. //The connectorId is 0
  7762. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  7763. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7764. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  7765. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  7766. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  7767. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  7768. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  7769. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  7770. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  7771. result = TRUE;
  7772. return result;
  7773. }
  7774. else
  7775. {
  7776. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7777. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7778. }
  7779. if(strcmp(comfirmstr,"Accepted") == 0)
  7780. {
  7781. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  7782. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  7783. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  7784. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  7785. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  7786. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  7787. result = TRUE;
  7788. return result;
  7789. }
  7790. end:
  7791. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  7792. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  7793. return result;
  7794. }
  7795. int handleResetRequest(char *uuid, char *payload)
  7796. {
  7797. mtrace();
  7798. int result = FAIL;
  7799. char sstr[10]={0},sstrtemp[30]={ 0 };
  7800. char typestr[10]={0};
  7801. char comfirmstr[20]={0};
  7802. int c = 0;
  7803. char *loc;
  7804. DEBUG_INFO("handleResetRequest...\n");
  7805. strcpy(sstrtemp, stringtrimspace(payload));
  7806. loc = strstr(sstrtemp, "type");
  7807. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7808. c = 0;
  7809. while (loc[3+strlen("type")+c] != '\"')
  7810. {
  7811. sstr[c] = loc[3+strlen("type")+c];
  7812. c++;
  7813. }
  7814. sstr[c] = '\0';
  7815. strcpy(typestr,sstr);
  7816. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  7817. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  7818. {
  7819. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7820. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7821. result = TRUE;
  7822. return result;
  7823. }
  7824. else
  7825. {
  7826. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  7827. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  7828. goto errorend;
  7829. }
  7830. errorend:
  7831. sendResetConfirmation(uuid, comfirmstr);
  7832. return result;
  7833. }
  7834. int handleSendLocalListRequest(char *uuid, char *payload)
  7835. {
  7836. mtrace();
  7837. int result = FAIL;
  7838. int listVersionInt;
  7839. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  7840. char listsearch[]="listVersion";
  7841. char updateTypesearch[]="updateType";
  7842. char localAuthorizationListsearch[]="localAuthorizationList";
  7843. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  7844. char CardList[500][160]={0};
  7845. char updateTypestr[15]={0};
  7846. char idTagstr[20]={0};
  7847. char parentIdTag[20]={0};
  7848. char expiryDate[30]={0};
  7849. char idTagstatus[16]={0};
  7850. int c = 0;
  7851. int i = 0;
  7852. char *delim1 = "}";
  7853. char * pch;
  7854. char *loc;
  7855. //char *ptr;
  7856. char comfirmstr[20];
  7857. //int n_localAuthorizations = 0;
  7858. int checkState_Faulted = FALSE;
  7859. DEBUG_INFO("handleSendLocalListRequest...\n");
  7860. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  7861. {
  7862. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7863. goto end;
  7864. }
  7865. //check Charge Point state
  7866. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7867. {
  7868. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7869. {
  7870. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7871. }
  7872. }
  7873. for (int index = 0; index < CCS_QUANTITY; index++)
  7874. {
  7875. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7876. {
  7877. checkState_Faulted = TRUE; //OCPP Status
  7878. }
  7879. }
  7880. for (int index = 0; index < GB_QUANTITY; index++)
  7881. {
  7882. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7883. {
  7884. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7885. }
  7886. }
  7887. //check Charge Point state
  7888. for (int index = 0; index < AC_QUANTITY; index++)
  7889. {
  7890. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7891. {
  7892. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7893. }
  7894. }
  7895. if(checkState_Faulted == TRUE)
  7896. {
  7897. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7898. goto end;
  7899. }
  7900. //Filter payload space
  7901. strcpy(sstrtemp, stringtrimspace(payload));
  7902. //listVersion
  7903. c = 0;
  7904. loc = strstr(sstrtemp, listsearch);
  7905. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  7906. {
  7907. sstr[c] = loc[strlen("listVersion")+2+c];
  7908. c++;
  7909. }
  7910. sstr[c] = '\0';
  7911. listVersionInt = atoi(sstr);
  7912. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7913. //updateType
  7914. loc = strstr(sstrtemp, updateTypesearch);
  7915. c = 0;
  7916. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  7917. {
  7918. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  7919. c++;
  7920. }
  7921. sstr[c] = '\0';
  7922. strcpy(updateTypestr, sstr);
  7923. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  7924. //localAuthorizationList
  7925. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7926. loc = strstr(sstrtemp, localAuthorizationListsearch);
  7927. if(loc != NULL) // localAuthorizationList is not NULL
  7928. {
  7929. //Check UpdateType
  7930. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7931. {
  7932. //Local list full update
  7933. printf("Local list full update.\n");
  7934. OCPP_getListVerion();
  7935. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7936. {
  7937. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7938. goto end;
  7939. }
  7940. OCPP_cleanLocalList();
  7941. }
  7942. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7943. {
  7944. //Local list different update
  7945. printf("Local list different update.\n");
  7946. OCPP_getListVerion();
  7947. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7948. {
  7949. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  7950. goto end;
  7951. }
  7952. }
  7953. else
  7954. {
  7955. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7956. goto end;
  7957. }
  7958. c = 0;
  7959. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  7960. {
  7961. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  7962. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7963. c++;
  7964. }
  7965. sstr[c] = '\0';
  7966. //DEBUG_INFO("sstr=%s\n", sstr);
  7967. //parsing strings to words
  7968. i = 0;
  7969. pch = strtok(sstr,delim1);
  7970. while (pch != NULL)
  7971. {
  7972. strcpy(CardList[i], pch);
  7973. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  7974. pch = strtok (NULL, delim1);
  7975. i = i + 1;
  7976. }
  7977. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  7978. //local Authorizations List Numbers
  7979. //n_localAuthorizations = i;
  7980. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7981. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7982. c= 0;
  7983. while(c < i) // i is CardList Number
  7984. {
  7985. //Search "IdToken"
  7986. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7987. loc = strstr(CardList[c], "idTag");
  7988. int j = 0;
  7989. while (loc[3+strlen("idTag")+j] != '\"')
  7990. {
  7991. sstr[j] = loc[3+strlen("idTag")+j];
  7992. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7993. j++;
  7994. }
  7995. sstr[j] = '\0';
  7996. strcpy(idTagstr, sstr);
  7997. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  7998. //Search "expiryDate"
  7999. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8000. loc = strstr(CardList[c], "expiryDate");
  8001. j = 0;
  8002. if(loc != NULL)
  8003. {
  8004. while (loc[3+strlen("expiryDate")+j] != '\"')
  8005. {
  8006. sstr[j] = loc[3+strlen("expiryDate")+j];
  8007. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8008. j++;
  8009. }
  8010. sstr[j] = '\0';
  8011. strcpy(expiryDate, sstr);
  8012. }
  8013. else
  8014. {
  8015. strcpy(expiryDate, "");
  8016. }
  8017. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  8018. //Search "parentIdTag"
  8019. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8020. loc = strstr(CardList[c], "parentIdTag");
  8021. j = 0;
  8022. if(loc != NULL)
  8023. {
  8024. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8025. {
  8026. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8027. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8028. j++;
  8029. }
  8030. sstr[j] = '\0';
  8031. strcpy(parentIdTag, sstr);
  8032. }
  8033. else
  8034. {
  8035. strcpy(parentIdTag, "");
  8036. }
  8037. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8038. //Search "status"
  8039. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8040. loc = strstr(CardList[c], "status");
  8041. j = 0;
  8042. while (loc[3+strlen("status")+j] != '\"')
  8043. {
  8044. sstr[j] = loc[3+strlen("status")+j];
  8045. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8046. j++;
  8047. }
  8048. sstr[j] = '\0';
  8049. strcpy(idTagstatus, sstr);
  8050. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8051. OCPP_getIdTag(idTagstr);
  8052. //OCPP_getIdTag("test"); For Test
  8053. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8054. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8055. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8056. {
  8057. //Local list full update
  8058. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8059. // update list
  8060. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8061. //DEBUG_INFO("Local list full update. 1\n");
  8062. //OCPP_get_TableAuthlocalAllData();
  8063. //DEBUG_INFO("Local list full update. 2\n");
  8064. }
  8065. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8066. {
  8067. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8068. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8069. }
  8070. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8071. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8072. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8073. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8074. c++;
  8075. }
  8076. }
  8077. else
  8078. {
  8079. //Check UpdateType
  8080. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8081. {
  8082. //Local list full update
  8083. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8084. OCPP_cleanLocalList();
  8085. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8086. goto end;
  8087. }
  8088. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8089. {
  8090. //Local list different update
  8091. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8092. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8093. goto end;
  8094. }
  8095. }
  8096. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8097. end:
  8098. sendSendLocalListConfirmation(uuid, comfirmstr);
  8099. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8100. return result;
  8101. }
  8102. #define MAX 200
  8103. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8104. {
  8105. mtrace();
  8106. int result = FAIL;
  8107. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8108. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8109. char chargingProfilePurposeStr[30]={0};
  8110. char chargingProfileKindStr[16]={0};
  8111. char recurrencyKindStr[10]={0};
  8112. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8113. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8114. int chargingSchedulePeriodCount = 0;
  8115. //int updateflag = FALSE;
  8116. char comfirmstr[20]={0};
  8117. int meet= FALSE;
  8118. char sstr[10]={0},sstrtemp[1600]={ 0 };
  8119. int c = 0;
  8120. char *loc;
  8121. FILE *fptr1;//, *fptr2;
  8122. //int lno=0;//, linectr = 0;
  8123. //int modifyflag = FALSE;
  8124. char filename[MAX]={0};
  8125. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8126. //int resultRename=0;
  8127. char rmFileCmd[50]={0};
  8128. char tempchargingProfilePurposeStr[30]={0};
  8129. char word[1600]={0};
  8130. int n_chargingProfile = 0;
  8131. //[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}}}]
  8132. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8133. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8134. //Filter string space
  8135. strcpy(sstrtemp, stringtrimspace(payload));
  8136. //*********************connectorId***************************/
  8137. loc = strstr(sstrtemp, "connectorId");
  8138. c = 0;
  8139. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8140. while (loc[strlen("connectorId")+2+c] != ',')
  8141. {
  8142. sstr[c] = loc[strlen("connectorId")+2+c];
  8143. c++;
  8144. }
  8145. sstr[c] = '\0';
  8146. connectorIdInt = atoi(sstr);
  8147. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8148. {
  8149. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8150. }
  8151. else
  8152. {
  8153. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  8154. }
  8155. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  8156. //*********************chargingProfileId***************************/
  8157. loc = strstr(sstrtemp, "chargingProfileId");
  8158. c = 0;
  8159. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8160. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8161. {
  8162. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8163. c++;
  8164. }
  8165. sstr[c] = '\0';
  8166. chargingProfileIdInt = atoi(sstr);
  8167. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8168. {
  8169. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8170. }
  8171. else
  8172. {
  8173. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8174. }
  8175. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  8176. //*********************transactionId***************************/
  8177. loc = strstr(sstrtemp, "transactionId");
  8178. if(loc != NULL)
  8179. {
  8180. c = 0;
  8181. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8182. while (loc[strlen("transactionId")+2+c] != ',')
  8183. {
  8184. sstr[c] = loc[strlen("transactionId")+2+c];
  8185. c++;
  8186. }
  8187. sstr[c] = '\0';
  8188. transactionIdInt = atoi(sstr);
  8189. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8190. {
  8191. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  8192. }
  8193. else
  8194. {
  8195. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  8196. }
  8197. }
  8198. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  8199. //*********************stackLevel***************************/
  8200. loc = strstr(sstrtemp, "stackLevel");
  8201. c = 0;
  8202. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8203. while (loc[strlen("stackLevel")+2+c] != ',')
  8204. {
  8205. sstr[c] = loc[strlen("stackLevel")+2+c];
  8206. c++;
  8207. }
  8208. sstr[c] = '\0';
  8209. stackLevelInt = atoi(sstr);
  8210. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8211. {
  8212. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8213. }
  8214. else
  8215. {
  8216. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8217. }
  8218. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  8219. //*********************chargingProfilePurpose***************************/
  8220. loc = strstr(sstrtemp, "chargingProfilePurpose");
  8221. c = 0;
  8222. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8223. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8224. {
  8225. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8226. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8227. c++;
  8228. }
  8229. sstr[c] = '\0';
  8230. strcpy(chargingProfilePurposeStr,sstr);
  8231. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  8232. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8233. {
  8234. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8235. }
  8236. else
  8237. {
  8238. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8239. }
  8240. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  8241. //*********************chargingProfileKind***************************/
  8242. loc = strstr(sstrtemp, "chargingProfileKind");
  8243. c = 0;
  8244. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8245. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  8246. {
  8247. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  8248. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8249. c++;
  8250. }
  8251. sstr[c] = '\0';
  8252. strcpy(chargingProfileKindStr,sstr);
  8253. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8254. {
  8255. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8256. }
  8257. else
  8258. {
  8259. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8260. }
  8261. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  8262. //*********************recurrencyKind***************************/
  8263. loc = strstr(sstrtemp, "recurrencyKind");
  8264. if(loc != NULL)
  8265. {
  8266. c = 0;
  8267. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8268. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  8269. {
  8270. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  8271. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8272. c++;
  8273. }
  8274. sstr[c] = '\0';
  8275. strcpy(recurrencyKindStr,sstr);
  8276. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8277. {
  8278. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8279. }
  8280. else
  8281. {
  8282. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8283. }
  8284. }
  8285. else
  8286. {
  8287. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8288. {
  8289. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  8290. }
  8291. else
  8292. {
  8293. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  8294. }
  8295. }
  8296. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  8297. //*********************validFrom***************************/
  8298. loc = strstr(sstrtemp, "validFrom");
  8299. if(loc != NULL)
  8300. {
  8301. c = 0;
  8302. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8303. while (loc[3+strlen("validFrom")+c] != '\"')
  8304. {
  8305. sstr[c] = loc[3+strlen("validFrom")+c];
  8306. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8307. c++;
  8308. }
  8309. sstr[c] = '\0';
  8310. strcpy(validFromStr,sstr);
  8311. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8312. {
  8313. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8314. }
  8315. else
  8316. {
  8317. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8318. }
  8319. }
  8320. else
  8321. {
  8322. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8323. {
  8324. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  8325. }
  8326. else
  8327. {
  8328. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  8329. }
  8330. }
  8331. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  8332. //*********************validTo***************************/
  8333. loc = strstr(sstrtemp, "validTo");
  8334. if(loc != NULL)
  8335. {
  8336. c = 0;
  8337. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8338. while (loc[3+strlen("validTo")+c] != '\"')
  8339. {
  8340. sstr[c] = loc[3+strlen("validTo")+c];
  8341. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8342. c++;
  8343. }
  8344. sstr[c] = '\0';
  8345. strcpy(validToStr,sstr);
  8346. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8347. {
  8348. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8349. }
  8350. else
  8351. {
  8352. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8353. }
  8354. }
  8355. else
  8356. {
  8357. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8358. {
  8359. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  8360. }
  8361. else
  8362. {
  8363. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  8364. }
  8365. }
  8366. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  8367. //*********************duration***************************/
  8368. loc = strstr(sstrtemp, "duration");
  8369. if(loc != NULL)
  8370. {
  8371. c = 0;
  8372. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8373. while (loc[strlen("duration")+2+c] != ',')
  8374. {
  8375. sstr[c] = loc[strlen("duration")+2+c];
  8376. c++;
  8377. }
  8378. sstr[c] = '\0';
  8379. durationInt = atoi(sstr);
  8380. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8381. {
  8382. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8383. }
  8384. else
  8385. {
  8386. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8387. }
  8388. }
  8389. else
  8390. {
  8391. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8392. {
  8393. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  8394. }
  8395. else
  8396. {
  8397. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  8398. }
  8399. }
  8400. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  8401. //*********************startSchedule***************************/
  8402. loc = strstr(sstrtemp, "startSchedule");
  8403. if(loc != NULL)
  8404. {
  8405. c = 0;
  8406. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8407. while (loc[3+strlen("startSchedule")+c] != '\"')
  8408. {
  8409. sstr[c] = loc[3+strlen("startSchedule")+c];
  8410. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8411. c++;
  8412. }
  8413. sstr[c] = '\0';
  8414. strcpy(startScheduleStr,sstr);
  8415. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8416. {
  8417. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8418. }
  8419. else
  8420. {
  8421. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8422. }
  8423. }
  8424. else
  8425. {
  8426. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8427. {
  8428. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8429. }
  8430. else
  8431. {
  8432. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8433. }
  8434. }
  8435. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  8436. //*********************chargingRateUnit***************************/
  8437. loc = strstr(sstrtemp, "chargingRateUnit");
  8438. if(loc != NULL)
  8439. {
  8440. c = 0;
  8441. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8442. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  8443. {
  8444. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  8445. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8446. c++;
  8447. }
  8448. sstr[c] = '\0';
  8449. strcpy(chargingRateUnitStr,sstr);
  8450. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8451. {
  8452. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8453. }
  8454. else
  8455. {
  8456. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8457. }
  8458. }
  8459. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  8460. //****************chargingSchedulePeriod count start*******************/
  8461. int what_len = strlen("startPeriod");
  8462. char tempChargingProfile[1600]={0};
  8463. strcpy(tempChargingProfile,(const char*)sstrtemp);
  8464. char *where = tempChargingProfile;
  8465. if (what_len)
  8466. {
  8467. while ((where = strstr(where, "startPeriod"))) {
  8468. where += what_len;
  8469. chargingSchedulePeriodCount++;
  8470. }
  8471. }
  8472. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8473. {
  8474. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8475. goto end;
  8476. }
  8477. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  8478. //where = payload;
  8479. int templength = 0;
  8480. //int searchstart = 0;
  8481. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  8482. {
  8483. //****************startPeriod*******************/
  8484. c=0;
  8485. loc = strstr(tempChargingProfile + templength, "startPeriod");
  8486. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8487. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  8488. {
  8489. sstr[c] = loc[strlen("startPeriod")+2+c];
  8490. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8491. c++;
  8492. }
  8493. sstr[c] = '\0';
  8494. startPeriodInt[periodNums] = atoi(sstr);
  8495. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  8496. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  8497. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8498. {
  8499. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8500. }
  8501. else
  8502. {
  8503. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8504. }
  8505. templength = strlen("startPeriod")+2+c;
  8506. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  8507. //****************limit*******************/
  8508. c=0;
  8509. loc = strstr(tempChargingProfile + templength, "limit");
  8510. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8511. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  8512. {
  8513. sstr[c] = loc[strlen("limit")+2+c];
  8514. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8515. c++;
  8516. }
  8517. sstr[c] = '\0';
  8518. limitflaot[periodNums] = atof(sstr);
  8519. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8520. {
  8521. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8522. }
  8523. else
  8524. {
  8525. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8526. }
  8527. templength = templength + strlen("limit")+2+c;
  8528. //****************numberPhases*******************/
  8529. loc = strstr(tempChargingProfile + templength, "numberPhases");
  8530. if(loc != NULL)
  8531. {
  8532. c=0;
  8533. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8534. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  8535. {
  8536. sstr[c] = loc[strlen("numberPhases")+2+c];
  8537. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8538. c++;
  8539. }
  8540. sstr[c] = '\0';
  8541. numberPhasesInt[periodNums] = atoi(sstr);
  8542. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8543. {
  8544. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8545. }
  8546. else
  8547. {
  8548. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8549. }
  8550. templength = templength + strlen("numberPhases")+2+c;
  8551. }
  8552. //where = loc;
  8553. }
  8554. //****************chargingSchedulePeriod count end*******************/
  8555. //*********************minChargingRate***************************/
  8556. loc = strstr(sstrtemp, "minChargingRate");
  8557. if(loc != NULL)
  8558. {
  8559. c = 0;
  8560. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8561. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  8562. {
  8563. sstr[c] = loc[strlen("minChargingRate")+2+c];
  8564. c++;
  8565. }
  8566. sstr[c] = '\0';
  8567. minChargingRateFloat = atof(sstr);
  8568. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8569. {
  8570. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8571. }
  8572. else
  8573. {
  8574. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8575. }
  8576. }
  8577. else
  8578. {
  8579. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8580. {
  8581. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8582. }
  8583. else
  8584. {
  8585. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8586. }
  8587. }
  8588. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8589. {
  8590. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8591. if(connectorIdInt != 0)
  8592. {
  8593. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8594. goto end;
  8595. }
  8596. strcpy(filename, ChargePointMaxProfile_JSON );
  8597. fptr1 = fopen(filename, "r");
  8598. if (!fptr1)
  8599. {
  8600. //file not exist
  8601. DEBUG_INFO("Unable to open the input file!!\n");
  8602. fptr1 = fopen(filename, "w+");
  8603. }
  8604. else
  8605. {
  8606. //Check Charging Profile Count
  8607. while(fscanf(fptr1, "%s", word) != EOF)
  8608. {
  8609. //DEBUG_INFO("word=%s\n",word);
  8610. if(strstr(word, "chargingProfileId")!= NULL)
  8611. {
  8612. //DEBUG_INFO("test chargingProfileId \n");
  8613. n_chargingProfile = n_chargingProfile + 1;
  8614. //DEBUG_INFO("chargingProfileId Found\n");
  8615. }
  8616. }
  8617. }
  8618. fclose(fptr1);
  8619. }
  8620. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8621. {
  8622. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8623. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8624. {
  8625. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8626. goto end;
  8627. }
  8628. memset(filename, 0, ARRAY_SIZE(filename));
  8629. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8630. fptr1 = fopen(filename, "r");
  8631. if (!fptr1)
  8632. {
  8633. //file not exist
  8634. //DEBUG_INFO("Unable to open the input file!!\n");
  8635. fptr1 = fopen(filename, "w+");
  8636. }
  8637. else
  8638. {
  8639. //Check Charging Profile Count
  8640. while(fscanf(fptr1, "%s", word) != EOF)
  8641. {
  8642. //DEBUG_INFO("word=%s\n",word);
  8643. if(strstr(word, "chargingProfileId")!= NULL)
  8644. {
  8645. //DEBUG_INFO("test chargingProfileId \n");
  8646. n_chargingProfile = n_chargingProfile + 1;
  8647. //DEBUG_INFO("chargingProfileId Found\n");
  8648. }
  8649. }
  8650. }
  8651. fclose(fptr1);
  8652. }
  8653. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8654. {
  8655. //printf("set chargingProfile 1-4\n");
  8656. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8657. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  8658. if(connectorIdInt == 0)
  8659. {
  8660. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8661. goto end;
  8662. }
  8663. int tempIndex = 0;
  8664. //check Transaction active
  8665. if(gunType[connectorIdInt -1] == 'J')
  8666. {
  8667. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8668. {
  8669. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8670. }
  8671. else
  8672. {
  8673. tempIndex = connectorIdInt -1;
  8674. }
  8675. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8676. {
  8677. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8678. {
  8679. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8680. {
  8681. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8682. {
  8683. meet = TRUE;
  8684. break;
  8685. }
  8686. }
  8687. }
  8688. }
  8689. }
  8690. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  8691. {
  8692. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8693. {
  8694. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8695. }
  8696. else
  8697. {
  8698. tempIndex = connectorIdInt -1;
  8699. }
  8700. for (int index = 0; index < CCS_QUANTITY; index++)
  8701. {
  8702. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8703. {
  8704. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8705. {
  8706. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8707. {
  8708. meet = TRUE;
  8709. break;
  8710. }
  8711. }
  8712. }
  8713. }
  8714. }
  8715. else if(gunType[connectorIdInt -1] == 'G')
  8716. {
  8717. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8718. {
  8719. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8720. }
  8721. else
  8722. {
  8723. tempIndex = connectorIdInt -1;
  8724. }
  8725. for (int index = 0; index < GB_QUANTITY; index++)
  8726. {
  8727. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8728. {
  8729. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8730. {
  8731. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8732. {
  8733. meet = TRUE;
  8734. break;
  8735. }
  8736. }
  8737. }
  8738. }
  8739. }
  8740. else
  8741. {
  8742. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8743. {
  8744. tempIndex = 2;
  8745. }
  8746. else
  8747. {
  8748. tempIndex = (connectorIdInt -1);
  8749. }
  8750. for (int index = 0; index < AC_QUANTITY; index++)
  8751. {
  8752. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8753. {
  8754. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8755. {
  8756. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8757. {
  8758. meet = TRUE;
  8759. break;
  8760. }
  8761. }
  8762. }
  8763. }
  8764. }
  8765. //check Transaction active
  8766. if(meet == FALSE)
  8767. {
  8768. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8769. goto end;
  8770. }
  8771. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8772. {
  8773. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8774. goto end;
  8775. }
  8776. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8777. fptr1 = fopen(filename, "r");
  8778. if (!fptr1)
  8779. {
  8780. //file not exist
  8781. DEBUG_INFO("Unable to open the input file!!\n");
  8782. fptr1 = fopen(filename, "w+");
  8783. }
  8784. else
  8785. {
  8786. //Check Charging Profile Count
  8787. while(fscanf(fptr1, "%s", word) != EOF)
  8788. {
  8789. //DEBUG_INFO("word=%s\n",word);
  8790. if(strstr(word, "chargingProfileId")!= NULL)
  8791. {
  8792. //DEBUG_INFO("test chargingProfileId \n");
  8793. n_chargingProfile = n_chargingProfile + 1;
  8794. //DEBUG_INFO("chargingProfileId Found\n");
  8795. }
  8796. }
  8797. }
  8798. fclose(fptr1);
  8799. }
  8800. // Check ChargeProfileMaxStackLevel
  8801. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8802. {
  8803. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8804. goto end;
  8805. }
  8806. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8807. {
  8808. int i = 0;
  8809. char fnametemp[200]={0};
  8810. n_chargingProfile = 0;
  8811. //Check ChargePointMaxProfile.json exit
  8812. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8813. {
  8814. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8815. //Check Charging Profile Count
  8816. while(fscanf(fptr1, "%s", word) != EOF)
  8817. {
  8818. //DEBUG_INFO("word=%s\n",word);
  8819. if(strstr(word, "chargingProfileId")!= NULL)
  8820. {
  8821. //DEBUG_INFO("test chargingProfileId \n");
  8822. n_chargingProfile = n_chargingProfile + 1;
  8823. i = i + 1;
  8824. //DEBUG_INFO("chargingProfileId Found\n");
  8825. }
  8826. memset(word, 0, ARRAY_SIZE(word));
  8827. }
  8828. fclose(fptr1);
  8829. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8830. }
  8831. //Check TxDefaultProfile_0.json exit
  8832. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8833. {
  8834. i = 0;
  8835. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8836. //Check Charging Profile Count
  8837. while(fscanf(fptr1, "%s", word) != EOF)
  8838. {
  8839. //DEBUG_INFO("word=%s\n",word);
  8840. if(strstr(word, "chargingProfileId")!= NULL)
  8841. {
  8842. //DEBUG_INFO("test chargingProfileId \n");
  8843. n_chargingProfile = n_chargingProfile + 1;
  8844. i = i + 1;
  8845. //DEBUG_INFO("chargingProfileId Found\n");
  8846. }
  8847. memset(word, 0, ARRAY_SIZE(word));
  8848. }
  8849. fclose(fptr1);
  8850. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  8851. }
  8852. //Check TxDefaultProfile_%d.json
  8853. for(int j=1; j <= gunTotalNumber; j++)
  8854. {
  8855. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8856. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8857. if((access(fnametemp,F_OK))!=-1)
  8858. {
  8859. i = 0;
  8860. fptr1 = fopen(fnametemp, "r");
  8861. //Check Charging Profile Count
  8862. while(fscanf(fptr1, "%s", word) != EOF)
  8863. {
  8864. //DEBUG_INFO("word=%s\n",word);
  8865. if(strstr(word, "chargingProfileId")!= NULL)
  8866. {
  8867. //DEBUG_INFO("test chargingProfileId \n");
  8868. n_chargingProfile = n_chargingProfile + 1;
  8869. i = i + 1;
  8870. //DEBUG_INFO("chargingProfileId Found\n");
  8871. }
  8872. memset(word, 0, ARRAY_SIZE(word));
  8873. }
  8874. fclose(fptr1);
  8875. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8876. }
  8877. }
  8878. //Check TxProfile_%d.json
  8879. for(int j=1; j <= gunTotalNumber; j++)
  8880. {
  8881. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8882. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8883. if((access(fnametemp,F_OK))!=-1)
  8884. {
  8885. i = 0;
  8886. fptr1 = fopen(fnametemp, "r");
  8887. //Check Charging Profile Count
  8888. while(fscanf(fptr1, "%s", word) != EOF)
  8889. {
  8890. //DEBUG_INFO("word=%s\n",word);
  8891. if(strstr(word, "chargingProfileId")!= NULL)
  8892. {
  8893. //DEBUG_INFO("test chargingProfileId \n");
  8894. n_chargingProfile = n_chargingProfile + 1;
  8895. i = i + 1;
  8896. //DEBUG_INFO("chargingProfileId Found\n");
  8897. }
  8898. memset(word, 0, ARRAY_SIZE(word));
  8899. }
  8900. fclose(fptr1);
  8901. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8902. }
  8903. }
  8904. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  8905. {
  8906. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8907. goto end;
  8908. }
  8909. }
  8910. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8911. //**********************************Write to File********************************************************/
  8912. FILE *infile;
  8913. FILE *outfile;
  8914. // open file for writing
  8915. infile = fopen (filename, "r");
  8916. outfile = fopen (tempfile, "w");
  8917. int d =0;
  8918. d = fgetc(infile);
  8919. //DEBUG_INFO("d:%d\n",d);
  8920. rewind(infile);
  8921. //*璉 瘚 辣蝏     1嚗   0 */
  8922. if(d == EOF)
  8923. {
  8924. //DEBUG_INFO("ChargingProfile content is NULL\n");
  8925. fprintf(outfile,"%s\n",payload);
  8926. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8927. fclose(infile);
  8928. fclose(outfile);
  8929. sprintf(rmFileCmd,"rm -f %s",filename);
  8930. system(rmFileCmd);
  8931. rename(tempfile, filename);
  8932. sleep(1);
  8933. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  8934. //system(rmFileCmd);
  8935. }
  8936. else
  8937. {
  8938. char buf[1000]={0};
  8939. int ChargingProfileAdded = FALSE;
  8940. while (fgets(buf, sizeof(buf), infile) != NULL)
  8941. {
  8942. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8943. //*************************tempconnectorIdInt*********************************/
  8944. loc = strstr(buf, "connectorId");
  8945. c = 0;
  8946. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8947. while (loc[strlen("connectorId")+2+c] != ',')
  8948. {
  8949. sstr[c] = loc[strlen("connectorId")+2+c];
  8950. c++;
  8951. }
  8952. sstr[c] = '\0';
  8953. tempconnectorIdInt = atoi(sstr);
  8954. //*************************tempchargingProfileIdInt*********************************/
  8955. loc = strstr(buf, "chargingProfileId");
  8956. c = 0;
  8957. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8958. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8959. {
  8960. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8961. c++;
  8962. }
  8963. sstr[c] = '\0';
  8964. tempchargingProfileIdInt = atoi(sstr);
  8965. //*************************tempstackLevelInt*********************************/
  8966. loc = strstr(buf, "stackLevel");
  8967. c = 0;
  8968. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8969. while (loc[strlen("stackLevel")+2+c] != ',')
  8970. {
  8971. sstr[c] = loc[strlen("stackLevel")+2+c];
  8972. c++;
  8973. }
  8974. sstr[c] = '\0';
  8975. tempstackLevelInt = atoi(sstr);
  8976. //*************************tempchargingProfilePurposeStr*********************************/
  8977. loc = strstr(payload, "chargingProfilePurpose");
  8978. c = 0;
  8979. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8980. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8981. {
  8982. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8983. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8984. c++;
  8985. }
  8986. sstr[c] = '\0';
  8987. strcpy(tempchargingProfilePurposeStr,sstr);
  8988. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  8989. {
  8990. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8991. {
  8992. //DEBUG_INFO("update set chargingProfile to file -0\n");
  8993. if(ChargingProfileAdded == FALSE)
  8994. {
  8995. fprintf(outfile,"%s\n",payload);
  8996. ChargingProfileAdded = TRUE;
  8997. }
  8998. }
  8999. else
  9000. {
  9001. if(tempstackLevelInt < stackLevelInt)
  9002. {
  9003. if(ChargingProfileAdded == FALSE)
  9004. {
  9005. fprintf(outfile,"%s\n",payload);
  9006. ChargingProfileAdded = TRUE;
  9007. fprintf(outfile,"%s\n",buf);
  9008. }
  9009. else
  9010. {
  9011. fprintf(outfile,"%s\n",buf);
  9012. }
  9013. }
  9014. else
  9015. {
  9016. if(ChargingProfileAdded == FALSE)
  9017. {
  9018. fprintf(outfile,"%s\n",buf);
  9019. fprintf(outfile,"%s\n",payload);
  9020. ChargingProfileAdded = TRUE;
  9021. }
  9022. else
  9023. {
  9024. fprintf(outfile,"%s\n",buf);
  9025. }
  9026. }
  9027. }
  9028. }
  9029. else
  9030. {
  9031. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9032. {
  9033. if(ChargingProfileAdded == FALSE)
  9034. {
  9035. fprintf(outfile,"%s\n",payload);
  9036. ChargingProfileAdded = TRUE;
  9037. fprintf(outfile,"%s\n",buf);
  9038. }
  9039. else
  9040. {
  9041. fprintf(outfile,"%s\n",buf);
  9042. }
  9043. }
  9044. else if(tempstackLevelInt < stackLevelInt)
  9045. {
  9046. if(ChargingProfileAdded == FALSE)
  9047. {
  9048. fprintf(outfile,"%s\n",payload);
  9049. ChargingProfileAdded = TRUE;
  9050. fprintf(outfile,"%s\n",buf);
  9051. }
  9052. else
  9053. {
  9054. fprintf(outfile,"%s\n",buf);
  9055. }
  9056. }
  9057. else
  9058. {
  9059. if(ChargingProfileAdded == FALSE)
  9060. {
  9061. fprintf(outfile,"%s\n",buf);
  9062. fprintf(outfile,"%s\n",payload);
  9063. ChargingProfileAdded = TRUE;
  9064. }
  9065. else
  9066. {
  9067. fprintf(outfile,"%s\n",buf);
  9068. }
  9069. }
  9070. }
  9071. } // end of while loop
  9072. fclose(infile);
  9073. fclose(outfile);
  9074. sprintf(rmFileCmd,"rm -f %s",filename);
  9075. system(rmFileCmd);
  9076. rename(tempfile, filename);
  9077. sleep(1);
  9078. result = TRUE;
  9079. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9080. }
  9081. end:
  9082. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  9083. return result;
  9084. return result;
  9085. }
  9086. int handleTriggerMessageRequest(char *uuid, char *payload)
  9087. {
  9088. mtrace();
  9089. int result = FAIL;
  9090. int connectorIdIsNULL = FALSE;
  9091. int connectorIdInt =0;
  9092. char sstr[40]={0},sstrtemp[100]={ 0 };
  9093. char requestedMessagestr[40]={0};
  9094. char comfirmstr[20]={0};
  9095. int c = 0;
  9096. char *loc;
  9097. DEBUG_INFO("handleTriggerMessageRequest\n");
  9098. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  9099. strcpy(sstrtemp, stringtrimspace(payload));
  9100. c = 0;
  9101. loc = strstr(sstrtemp, "requestedMessage");
  9102. while (loc[3+strlen("requestedMessage")+c] != '\"')
  9103. {
  9104. sstr[c] = loc[3+strlen("requestedMessage")+c];
  9105. c++;
  9106. }
  9107. sstr[c] = '\0';
  9108. strcpy(requestedMessagestr, sstr);
  9109. c = 0;
  9110. loc = strstr(sstrtemp, "connectorId");
  9111. if(loc == NULL)
  9112. {
  9113. connectorIdIsNULL = TRUE;
  9114. }
  9115. else
  9116. {
  9117. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9118. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  9119. {
  9120. sstr[c] = loc[strlen("connectorId")+2+c];
  9121. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9122. c++;
  9123. }
  9124. sstr[c] = '\0';
  9125. connectorIdInt = atoi(sstr);
  9126. }
  9127. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  9128. {
  9129. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  9130. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  9131. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  9132. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  9133. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  9134. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  9135. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  9136. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  9137. {
  9138. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  9139. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9140. return TRUE;
  9141. }
  9142. else
  9143. {
  9144. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9145. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9146. }
  9147. }
  9148. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  9149. {
  9150. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  9151. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9152. return TRUE;
  9153. }
  9154. //==========================
  9155. // Trigger message
  9156. //==========================
  9157. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  9158. {
  9159. if((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) &&
  9160. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) &&
  9161. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) &&
  9162. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING) )
  9163. {
  9164. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  9165. }
  9166. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  9167. }
  9168. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  9169. {
  9170. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  9171. }
  9172. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  9173. {
  9174. //sendBootNotificationRequest();
  9175. server_sign = FALSE;
  9176. }
  9177. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  9178. {
  9179. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  9180. }
  9181. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  9182. {
  9183. if(connectorIdIsNULL == FALSE)
  9184. {
  9185. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9186. {
  9187. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  9188. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  9189. }
  9190. }
  9191. else
  9192. {
  9193. for(int idx=0;idx< gunTotalNumber;idx++)
  9194. {
  9195. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  9196. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  9197. }
  9198. }
  9199. }
  9200. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  9201. {
  9202. if(connectorIdIsNULL == FALSE)
  9203. {
  9204. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9205. {
  9206. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  9207. }
  9208. }
  9209. else
  9210. {
  9211. for(int idx=0;idx< gunTotalNumber;idx++)
  9212. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  9213. }
  9214. }
  9215. return result;
  9216. }
  9217. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9218. {
  9219. mtrace();
  9220. int result = FAIL;
  9221. char sstr[6]={0},sstrtemp[50]={ 0 };
  9222. int connectorIdInt =0;
  9223. char comfirmstr[20]={0};
  9224. int c = 0;
  9225. int tempIndex = 0;
  9226. char *loc;
  9227. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9228. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9229. strcpy(sstrtemp, stringtrimspace(payload));
  9230. c = 0;
  9231. loc = strstr(sstrtemp, "connectorId");
  9232. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9233. while (loc[strlen("connectorId")+2+c] != '}')
  9234. {
  9235. sstr[c] = loc[strlen("connectorId")+2+c];
  9236. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9237. c++;
  9238. }
  9239. sstr[c] = '\0';
  9240. connectorIdInt = atoi(sstr);
  9241. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  9242. if(gunTotalNumber == 0)
  9243. {
  9244. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9245. goto end;
  9246. }
  9247. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9248. {
  9249. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9250. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9251. goto end;
  9252. }
  9253. else
  9254. {
  9255. //check Transaction active
  9256. if(gunType[connectorIdInt-1] == 'J')
  9257. {
  9258. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9259. {
  9260. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9261. }
  9262. else
  9263. {
  9264. tempIndex = connectorIdInt -1;
  9265. }
  9266. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9267. {
  9268. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9269. {
  9270. //stop Transaction
  9271. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9272. }
  9273. }
  9274. }
  9275. else if((gunType[connectorIdInt-1] == 'U')||(gunType[connectorIdInt-1] == 'E'))
  9276. {
  9277. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9278. {
  9279. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9280. }
  9281. else
  9282. {
  9283. tempIndex = connectorIdInt -1;
  9284. }
  9285. for (int index = 0; index < CCS_QUANTITY; index++)
  9286. {
  9287. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9288. {
  9289. //stop Transaction
  9290. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9291. }
  9292. }
  9293. }
  9294. else if(gunType[connectorIdInt-1] == 'G')
  9295. {
  9296. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9297. {
  9298. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9299. }
  9300. else
  9301. {
  9302. tempIndex = connectorIdInt -1;
  9303. }
  9304. for (int index = 0; index < GB_QUANTITY; index++)
  9305. {
  9306. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9307. {
  9308. //stop Transaction
  9309. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9310. }
  9311. }
  9312. }
  9313. else
  9314. {
  9315. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9316. {
  9317. tempIndex = 2;
  9318. }
  9319. else
  9320. {
  9321. tempIndex = connectorIdInt-1;
  9322. }
  9323. for (int index = 0; index < AC_QUANTITY; index++)
  9324. {
  9325. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9326. {
  9327. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9328. }
  9329. }
  9330. }
  9331. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9332. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9333. result = TRUE;
  9334. return result;
  9335. }
  9336. end:
  9337. //json_object_put(obj); --- remove temporally
  9338. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9339. return result;
  9340. }
  9341. static char UpdateFirmwarepayloadData[300]={0};
  9342. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9343. {
  9344. mtrace();
  9345. int result = FAIL;
  9346. pthread_t t;
  9347. sendUpdateFirmwareConfirmation(uuid);
  9348. memset(UpdateFirmwarepayloadData, 0, 300);
  9349. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9350. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9351. ////pthread_join(t, NULL); //
  9352. //pthread_detach(t);
  9353. //sendUpdateFirmwareConfirmation(uuid);
  9354. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9355. return result;
  9356. }
  9357. void *UpdateFirmwareProcess(void *data)
  9358. {
  9359. pthread_detach(pthread_self());
  9360. mtrace();
  9361. int retriesInt =0, retryIntervalInt=0;
  9362. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9363. int port=0;
  9364. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9365. int isSuccess = 0;
  9366. char ftpbuf[200];
  9367. char temp[100];
  9368. char * pch;
  9369. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9370. json_object *UpdateFirmware;
  9371. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  9372. if(!is_error(UpdateFirmware))
  9373. {
  9374. // Required data
  9375. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  9376. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  9377. // Optional data
  9378. if(json_object_object_get(UpdateFirmware, "retries"))
  9379. {
  9380. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  9381. }
  9382. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  9383. {
  9384. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  9385. }
  9386. }
  9387. json_object_put(UpdateFirmware);
  9388. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9389. memset(path, 0, ARRAY_SIZE(path));
  9390. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9391. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9392. if(strncmp(locationstr,"http", 4) == 0)
  9393. {
  9394. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9395. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9396. // protocol, user, password, host, path);
  9397. sprintf(ftppath,"/%s", path);
  9398. DEBUG_INFO("locationstr: %s\n", locationstr);
  9399. DEBUG_INFO("protocol: %s\n",protocol);
  9400. DEBUG_INFO("host: %s\n",host);
  9401. DEBUG_INFO("path: %s\n",path);
  9402. DEBUG_INFO("ftppath: %s\n",ftppath);
  9403. int ftppathlen=strlen(ftppath);
  9404. int i=1;
  9405. char filenametemp[50];
  9406. while(i < ftppathlen)
  9407. {
  9408. int len=ftppathlen-i;
  9409. if(ftppath[len]== 47) // '/' ascll code: 47
  9410. {
  9411. DEBUG_INFO("compare '/' all right\n");
  9412. break;
  9413. }
  9414. i=i+1;
  9415. }
  9416. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9417. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9418. filenametemp[i+1] = 0;
  9419. do
  9420. {
  9421. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9422. sleep(retryIntervalInt);
  9423. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9424. if(!isSuccess)
  9425. {
  9426. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9427. }
  9428. else
  9429. {
  9430. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9431. }
  9432. }
  9433. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9434. {
  9435. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9436. memset(temp, 0, ARRAY_SIZE(temp));
  9437. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9438. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9439. int ftppathlen=strlen(ftpbuf);
  9440. int i=1;
  9441. char filenametemp[50];
  9442. while(i < ftppathlen)
  9443. {
  9444. int len=ftppathlen-i;
  9445. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9446. {
  9447. DEBUG_INFO(" compare '/' all right\n");
  9448. break;
  9449. }
  9450. i=i+1;
  9451. }
  9452. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9453. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9454. filenametemp[i+1] = 0;
  9455. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9456. pch=strchr(temp,'@');
  9457. if(pch==NULL)
  9458. {
  9459. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9460. protocol, host, &port, path);
  9461. strcpy(user,"anonymous");
  9462. strcpy(password,"");
  9463. }
  9464. else
  9465. {
  9466. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9467. protocol, user, password, host, &port, path);
  9468. }
  9469. sscanf(host,"%[^/]%s",host1, path1);
  9470. sprintf(ftppath,"%s", path1);
  9471. //DEBUG_INFO("protocol =%s\n",protocol);
  9472. //DEBUG_INFO("user =%s\n",user);
  9473. //DEBUG_INFO("password =%s\n",password);
  9474. //DEBUG_INFO("host1 =%s\n",host1);
  9475. //DEBUG_INFO("port =%d\n",port);
  9476. //DEBUG_INFO("path1 =%s\n",path1);
  9477. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9478. //ftpFile(host, user, password, port, ftppath, fname);
  9479. //download firmware pthred
  9480. if(port == 0)
  9481. {
  9482. port = 21;
  9483. }
  9484. do
  9485. {
  9486. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9487. sleep(retryIntervalInt);
  9488. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9489. if(!isSuccess)
  9490. {
  9491. //BulldogUtil.sleepMs(interval*1000);
  9492. DEBUG_INFO("Update firmware request and download file fail.\n");
  9493. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9494. }
  9495. else
  9496. {
  9497. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9498. }
  9499. }
  9500. else
  9501. {
  9502. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9503. }
  9504. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9505. pthread_exit(NULL);
  9506. }
  9507. //==========================================
  9508. // Handle server response routine
  9509. //==========================================
  9510. void handleAuthorizeResponse(char *payload, int gun_index)
  9511. {
  9512. mtrace();
  9513. char expiryDatestr[30]={0};
  9514. char parentIdTagstr[20]={0};
  9515. char statusstr[20]={0};
  9516. char expiryDatestrtemp[30]={0};
  9517. char parentIdTagstrtemp[20]={0};
  9518. char IdTagstrtemp[20]={0};
  9519. char statusstrtemp[20]={0};
  9520. int expiryDateISNULL=FALSE;
  9521. int parentIdTagISNULL=FALSE;
  9522. char sstr[160]={0};
  9523. char* filename = AuthorizationCache_JSON;
  9524. char tempfile[] = "/Storage/OCPP/Authorizetemp.json";
  9525. char *loc;
  9526. int resultRename=0;
  9527. int responseIdTagInfoAsZero= 0;
  9528. char rmFileCmd[50]={0};
  9529. DEBUG_INFO("handleAuthorizeResponse...\n");
  9530. json_object *Authorize;
  9531. Authorize = json_tokener_parse(payload);
  9532. if(!is_error(Authorize))
  9533. {
  9534. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  9535. {
  9536. // Required data
  9537. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  9538. // Optional data
  9539. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  9540. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  9541. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  9542. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  9543. }
  9544. }
  9545. json_object_put(Authorize);
  9546. if(expiryDateISNULL == FALSE)
  9547. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9548. if(parentIdTagISNULL == FALSE)
  9549. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9550. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9551. //Update idTag information to authorization cache if supproted
  9552. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9553. {
  9554. if((access(filename,F_OK))!=-1)
  9555. {
  9556. printf("AuthorizationCache exist.\n");
  9557. }
  9558. else
  9559. {
  9560. printf("AuthorizationCache not exist\n");
  9561. FILE *log = fopen(filename, "w+");
  9562. if(log == NULL)
  9563. {
  9564. printf("log is NULL\n");
  9565. goto out;
  9566. }
  9567. else
  9568. {
  9569. fclose(log);
  9570. }
  9571. }
  9572. FILE *infile;
  9573. FILE *outfile;
  9574. // open file for writing
  9575. infile = fopen (filename, "r");
  9576. outfile = fopen (tempfile, "w");
  9577. int c;
  9578. c = fgetc(infile);
  9579. //DEBUG_INFO("c:%d\n",c);
  9580. rewind(infile);
  9581. if(c == EOF)
  9582. {
  9583. DEBUG_INFO("Orignal File is NULL\n");
  9584. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9585. {
  9586. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9587. }
  9588. else
  9589. {
  9590. strcpy(expiryDatestrtemp, "");
  9591. }
  9592. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9593. {
  9594. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9595. }
  9596. else
  9597. {
  9598. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9599. }
  9600. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9601. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9602. fclose(infile);
  9603. fclose(outfile);
  9604. sprintf(rmFileCmd,"rm -f %s",filename);
  9605. system(rmFileCmd);
  9606. resultRename = rename(tempfile, filename);
  9607. if(resultRename == 0)
  9608. {
  9609. printf("File renamed successfully");
  9610. }
  9611. else
  9612. {
  9613. printf("Error: unable to rename the file");
  9614. }
  9615. }
  9616. else
  9617. {
  9618. char buf[160]={0};
  9619. while (fgets(buf, ARRAY_SIZE(buf), infile) != NULL)
  9620. {
  9621. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9622. memset(expiryDatestr, 0, ARRAY_SIZE(expiryDatestrtemp));
  9623. memset(parentIdTagstr,0, ARRAY_SIZE(parentIdTagstrtemp));
  9624. memset(statusstr, 0, ARRAY_SIZE(statusstrtemp));
  9625. memset(IdTagstrtemp, 0, ARRAY_SIZE(IdTagstrtemp));
  9626. memset(expiryDatestrtemp, 0, ARRAY_SIZE(expiryDatestrtemp));
  9627. memset(parentIdTagstrtemp, 0, ARRAY_SIZE(parentIdTagstrtemp));
  9628. memset(statusstrtemp, 0, ARRAY_SIZE(statusstrtemp));
  9629. //------------------IdTag-----------------------
  9630. loc = strstr(buf, "idTag");
  9631. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9632. c = 0;
  9633. while (loc[3+strlen("idTag")+c] != '\"')
  9634. {
  9635. sstr[c] = loc[3+strlen("idTag")+c];
  9636. c++;
  9637. }
  9638. sstr[c] = '\0';
  9639. strcpy(IdTagstrtemp,sstr);
  9640. //*********************expiryDate***************/
  9641. loc = strstr(buf, "expiryDate");
  9642. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9643. c = 0;
  9644. while (loc[3+strlen("expiryDate")+c] != '\"')
  9645. {
  9646. sstr[c] = loc[3+strlen("expiryDate")+c];
  9647. c++;
  9648. }
  9649. sstr[c] = '\0';
  9650. strcpy(expiryDatestr,sstr);
  9651. //*********************parentIdTag***************/
  9652. loc = strstr(buf, "parentIdTag");
  9653. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9654. c = 0;
  9655. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9656. {
  9657. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9658. c++;
  9659. }
  9660. sstr[c] = '\0';
  9661. strcpy(parentIdTagstr,sstr);
  9662. //*********************status***************/
  9663. loc = strstr(buf, "status");
  9664. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9665. c = 0;
  9666. while (loc[3+strlen("status")+c] != '\"')
  9667. {
  9668. sstr[c] = loc[3+strlen("status")+c];
  9669. c++;
  9670. }
  9671. sstr[c] = '\0';
  9672. strcpy(statusstr,sstr);
  9673. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9674. {
  9675. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9676. responseIdTagInfoAsZero = 1;
  9677. }
  9678. else
  9679. {
  9680. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9681. }
  9682. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9683. {
  9684. //modify item
  9685. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9686. {
  9687. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9688. }
  9689. else
  9690. {
  9691. strcpy(expiryDatestrtemp, "");
  9692. }
  9693. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9694. {
  9695. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9696. }
  9697. else
  9698. {
  9699. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9700. }
  9701. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9702. }
  9703. else
  9704. {
  9705. //wrie original item
  9706. strcpy(expiryDatestrtemp, expiryDatestr);
  9707. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9708. strcpy(statusstrtemp, statusstr);
  9709. }
  9710. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9711. }
  9712. fclose(infile);
  9713. fclose(outfile);
  9714. sprintf(rmFileCmd,"rm -f %s",filename);
  9715. system(rmFileCmd);
  9716. resultRename = rename(tempfile, filename);
  9717. if(resultRename == 0)
  9718. {
  9719. DEBUG_INFO("File renamed successfully");
  9720. }
  9721. else
  9722. {
  9723. DEBUG_INFO("Error: unable to rename the file");
  9724. }
  9725. }
  9726. }
  9727. out:
  9728. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9729. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9730. authorizeRetryTimes = 0;
  9731. }
  9732. char * strtrimc( char * s )
  9733. {
  9734. char * p1 = s;
  9735. char * p2 = s;
  9736. while(*p1 != '\0')
  9737. {
  9738. while(*p1 == ' ' || *p1 == '\t' || *p1 == '\"' || *p1 == '\n' || *p1 == '}' || *p1 == '\r')
  9739. {
  9740. if(*p1 != ',')
  9741. {
  9742. p1 ++;
  9743. }
  9744. else
  9745. {
  9746. break;
  9747. }
  9748. }
  9749. if(*p1 != ',')
  9750. {
  9751. * p2 ++ = *p1 ++;
  9752. //printf("p2=%s\n",p2);
  9753. }
  9754. else
  9755. {
  9756. break;
  9757. }
  9758. }
  9759. *p2 = '\0';
  9760. return (s);
  9761. }
  9762. void handleBootNotificationResponse(char *payload, int gun_index)
  9763. {
  9764. mtrace();
  9765. char statusStr[12]={0};
  9766. char currentTimeStr[30]={0};
  9767. int intervalInt = 0;
  9768. struct tm tp;
  9769. char buf[28]={0};
  9770. char timebuf[50]={0};
  9771. DEBUG_INFO("handleBootNotificationResponse...\n");
  9772. json_object *BootNotification;
  9773. BootNotification = json_tokener_parse(payload);
  9774. if(!is_error(BootNotification))
  9775. {
  9776. // Required data
  9777. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  9778. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  9779. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  9780. }
  9781. json_object_put(BootNotification);
  9782. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9783. BootNotificationInterval = intervalInt;
  9784. HeartBeatWaitTime = intervalInt;
  9785. //write back to ShmOCPP16Data->BootNotification
  9786. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9787. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9788. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9789. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  9790. {
  9791. server_sign = TRUE;
  9792. server_pending =FALSE;
  9793. }
  9794. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9795. {
  9796. server_pending = TRUE;
  9797. }
  9798. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9799. tp.tm_isdst = -1;
  9800. //time_t utc = mktime(&tp);
  9801. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9802. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9803. sprintf(timebuf,"date -s '%s'",buf);
  9804. system(timebuf);
  9805. srand(time(NULL));
  9806. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  9807. //==============================================
  9808. // RTC sync
  9809. //==============================================
  9810. system("/sbin/hwclock -w --systohc");
  9811. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  9812. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9813. }
  9814. void handleDataTransferResponse(char *payload, int gun_index)
  9815. {
  9816. char sstr[160]={0};//sstr[200]={ 0 };
  9817. int c = 0;
  9818. char *loc;
  9819. DEBUG_INFO("handleDataTransferResponse ...\n");
  9820. loc = strstr(payload, "status");
  9821. printf("loc=%s\n",loc);
  9822. c = 0;
  9823. while (loc[3+strlen("status")+c] != '\"')
  9824. {
  9825. sstr[c] = loc[3+strlen("status")+c];
  9826. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9827. c++;
  9828. }
  9829. sstr[c] = '\0';
  9830. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  9831. }
  9832. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  9833. {
  9834. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  9835. //struct json_object *obj;
  9836. // obj = json_tokener_parse(payload);
  9837. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  9838. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  9839. //No fields are defined.
  9840. }
  9841. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  9842. {
  9843. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  9844. //struct json_object *obj;
  9845. // obj = json_tokener_parse(payload);
  9846. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  9847. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  9848. //No fields are defined.
  9849. }
  9850. void handleHeartbeatResponse(char *payload, int gun_index)
  9851. {
  9852. mtrace();
  9853. struct tm tp;
  9854. char buf[28]={0};
  9855. char timebuf[50]={0};
  9856. DEBUG_INFO("handleHeartbeatResponse...\n");
  9857. json_object *Heartbeat;
  9858. Heartbeat = json_tokener_parse(payload);
  9859. if(!is_error(Heartbeat))
  9860. {
  9861. // Required data
  9862. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  9863. }
  9864. json_object_put(BootNotification);
  9865. if(FirstHeartBeat == 0)
  9866. {
  9867. FirstHeartBeat = 1;
  9868. DEBUG_INFO("FirstHeartBeat \n");
  9869. }
  9870. HeartBeatWithNOResponse = 0;
  9871. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9872. tp.tm_isdst = -1;
  9873. //time_t utc = mktime(&tp);
  9874. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9875. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9876. sprintf(timebuf,"date -s '%s'",buf);
  9877. system(timebuf);
  9878. //==============================================
  9879. // RTC sync
  9880. //==============================================
  9881. system("/sbin/hwclock -w --systohc");
  9882. //===============================================
  9883. //Print Out HeartBeat log
  9884. //===============================================
  9885. {
  9886. double diff_t;
  9887. struct tm tp,tp1;
  9888. // BootNotification Receive Time
  9889. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9890. tp.tm_isdst = -1;
  9891. time_t BootNotificationReceiveTime = mktime(&tp);
  9892. //HeartBeat Receive Time
  9893. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp1);
  9894. tp1.tm_isdst = -1;
  9895. time_t HeartBeatReceiveTime = mktime(&tp1);
  9896. diff_t = difftime(HeartBeatReceiveTime, BootNotificationReceiveTime);
  9897. printf("handleHeartbeatResponse differnt time=%f..\n",diff_t);
  9898. if(((int)diff_t / 3600) > HeartBeatCountPerHour)
  9899. {
  9900. HeartBeatCountPerHour = (int)diff_t / 3600;
  9901. DEBUG_INFO("handleHeartbeatResponse ...\n");
  9902. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  9903. }
  9904. }
  9905. }
  9906. void handleMeterValuesResponse(char *payload, int gun_index)
  9907. {
  9908. mtrace();
  9909. DEBUG_INFO("handleMeterValuesResponse...\n");
  9910. }
  9911. void handleStartTransactionResponse(char *payload, int gun_index)
  9912. {
  9913. mtrace();
  9914. //int transactionIdInt = 0;
  9915. FILE *outfile;
  9916. char data[100]={0};
  9917. DEBUG_INFO("handleStartTransactionResponse...\n");
  9918. json_object *StartTransaction;
  9919. StartTransaction = json_tokener_parse(payload);
  9920. if(!is_error(StartTransaction))
  9921. {
  9922. // Required data
  9923. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  9924. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  9925. // Optional data
  9926. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  9927. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  9928. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  9929. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  9930. }
  9931. json_object_put(StartTransaction);
  9932. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  9933. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  9934. //-----------Start : write to the Queue TransactionId file -----------------//
  9935. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  9936. {}
  9937. else
  9938. {
  9939. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  9940. if(log == NULL)
  9941. {
  9942. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  9943. return ;
  9944. }
  9945. else
  9946. {
  9947. fclose(log);
  9948. }
  9949. }
  9950. // open file for writing
  9951. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  9952. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  9953. {
  9954. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  9955. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  9956. fputs(data, outfile);
  9957. fclose (outfile);
  9958. }
  9959. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9960. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9961. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  9962. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  9963. }
  9964. void handleStatusNotificationResponse(char *payload, int gun_index)
  9965. {
  9966. mtrace();
  9967. DEBUG_INFO("handleStatusNotificationResponse...\n");
  9968. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  9969. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  9970. }
  9971. void handleStopTransactionnResponse(char *payload, int gun_index)
  9972. {
  9973. mtrace();
  9974. DEBUG_INFO("handleStopTransactionnResponse...\n");
  9975. json_object *StopTransaction;
  9976. StopTransaction = json_tokener_parse(payload);
  9977. if(!is_error(StopTransaction))
  9978. {
  9979. // Optional data
  9980. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  9981. {
  9982. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  9983. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  9984. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  9985. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  9986. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  9987. }
  9988. }
  9989. json_object_put(StopTransaction);
  9990. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  9991. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  9992. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9993. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9994. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  9995. }
  9996. //==========================================
  9997. // Handle Error routine
  9998. //==========================================
  9999. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  10000. {
  10001. mtrace();
  10002. #ifdef SystemLogMessage
  10003. DEBUG_INFO("errorCode: %s\n", errorCode);
  10004. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  10005. DEBUG_INFO("errorDetails: %s\n", payload);
  10006. #endif
  10007. }
  10008. //===============================================
  10009. // Common routine
  10010. //===============================================
  10011. int initialConfigurationTable(void)
  10012. {
  10013. //clock_t start_t, end_t, total_t;
  10014. FILE *fp;
  10015. FILE *outfile;
  10016. char str[200]={0};
  10017. char sstr[100]={0};
  10018. int c = 0;
  10019. char *loc;
  10020. DEBUG_INFO("initialConfigurationTable...\n");
  10021. //start_t = clock();
  10022. //printf("Starting of the program, start_t = %ld\n", start_t);
  10023. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  10024. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  10025. {
  10026. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10027. if(outfile == NULL)
  10028. {
  10029. DEBUG_INFO("Error opening file\n");
  10030. return FALSE;
  10031. }
  10032. /*Core Profile*/
  10033. //AllowOfflineTxForUnknownId
  10034. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10035. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10036. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  10037. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10038. //AuthorizationCacheEnabled
  10039. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10040. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10041. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10042. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10043. //AuthorizeRemoteTxRequests
  10044. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10045. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10046. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  10047. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10048. //BlinkRepeat
  10049. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10050. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10051. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10052. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10053. //ClockAlignedDataInterval
  10054. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10055. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10056. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10057. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10058. //ConnectionTimeOut
  10059. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10060. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10061. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10062. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10063. //GetConfigurationMaxKeys
  10064. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10065. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10066. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "44" );
  10067. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10068. // HeartbeatInterval
  10069. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10070. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10071. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  10072. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10073. // LightIntensity
  10074. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10075. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10077. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10078. // LocalAuthorizeOffline
  10079. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10080. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10081. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10082. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10083. // LocalPreAuthorize
  10084. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10085. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10086. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10087. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10088. // MaxEnergyOnInvalidId
  10089. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10091. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10092. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10093. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10094. // MeterValuesAlignedData
  10095. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  10096. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10097. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10099. else
  10100. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10101. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10102. // MeterValuesAlignedDataMaxLength
  10103. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10105. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10106. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  10107. else
  10108. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10109. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10110. // MeterValuesSampledData
  10111. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  10112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10113. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10114. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10115. else
  10116. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10117. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10118. // MeterValuesSampledDataMaxLength
  10119. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10120. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10121. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10122. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  10123. else
  10124. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10125. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10126. // MeterValueSampleInterval
  10127. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10128. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10129. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  10130. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10131. // MinimumStatusDuration
  10132. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10134. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  10135. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  10136. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10137. // NumberOfConnectors
  10138. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10139. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10140. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10141. {
  10142. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10143. }
  10144. else
  10145. {
  10146. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10147. }
  10148. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10149. // ResetRetries
  10150. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10151. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10152. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10153. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10154. // ConnectorPhaseRotation
  10155. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10156. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10157. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10158. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10159. // ConnectorPhaseRotationMaxLength
  10160. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10162. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10163. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10164. // StopTransactionOnEVSideDisconnect
  10165. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10166. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10167. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10168. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10169. // StopTransactionOnInvalidId
  10170. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  10171. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10172. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10173. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10174. // StopTxnAlignedData
  10175. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10176. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10177. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10178. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10179. // StopTxnAlignedDataMaxLength
  10180. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10181. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10182. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10183. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10184. // StopTxnSampledData
  10185. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  10186. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10187. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10188. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10189. else
  10190. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10191. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10192. // StopTxnSampledDataMaxLength
  10193. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10194. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10195. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10196. {
  10197. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  10198. }
  10199. else
  10200. {
  10201. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  10202. }
  10203. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10204. // SupportedFeatureProfiles
  10205. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10206. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10207. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10208. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10209. // SupportedFeatureProfilesMaxLength
  10210. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10211. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10212. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10213. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10214. // TransactionMessageAttempts
  10215. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10216. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10217. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10218. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10219. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10220. // TransactionMessageRetryInterval
  10221. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10222. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10223. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10224. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10225. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10226. // UnlockConnectorOnEVSideDisconnect
  10227. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10228. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10229. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10230. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10231. // WebSocketPingInterval
  10232. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10233. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10234. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10235. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10236. // QueueOffLineStartTransactionMessage
  10237. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  10238. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10239. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10240. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10241. //* Local Auth List Management Profile*/
  10242. #if 0
  10243. //For OCTT Test Case
  10244. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10245. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10246. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10247. #endif
  10248. #if 1
  10249. //LocalAuthListEnabled
  10250. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10251. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10252. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10253. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10254. #endif
  10255. //LocalAuthListMaxLength
  10256. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10257. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10258. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10259. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10260. //SendLocalListMaxLength
  10261. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10262. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10263. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  10264. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10265. //ReserveConnectorZeroSupported
  10266. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10267. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10268. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10269. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10270. //* Smart Charging Profile */
  10271. //ChargeProfileMaxStackLevel
  10272. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10273. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10274. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10275. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10276. // ChargingScheduleAllowedChargingRateUnit
  10277. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10278. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10279. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10280. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10281. // ChargingScheduleMaxPeriods
  10282. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10283. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10284. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10285. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10286. // ConnectorSwitch3to1PhaseSupported
  10287. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10288. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10289. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10290. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10291. // MaxChargingProfilesInstalled
  10292. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10293. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10294. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10295. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10296. fclose(outfile);
  10297. }
  10298. else
  10299. {
  10300. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10301. char keystr[60]={0};
  10302. char readonlystr[10]={0};
  10303. char valuestr[100]={0};
  10304. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10305. if(fp == NULL) {
  10306. DEBUG_INFO("Error opening file");
  10307. return FALSE;
  10308. }
  10309. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  10310. {
  10311. //DEBUG_INFO("Get Configuration \n");
  10312. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10313. //*************************key*********************************/
  10314. loc = strstr(str, "key");
  10315. c = 0;
  10316. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10317. while (loc[strlen("key")+3+c] != '\"')
  10318. {
  10319. sstr[c] = loc[strlen("key")+3+c];
  10320. c++;
  10321. }
  10322. sstr[c] = '\0';
  10323. strcpy(keystr,sstr);
  10324. //*************************readonly*********************************/
  10325. loc = strstr(str, "readonly");
  10326. c = 0;
  10327. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10328. while (loc[strlen("readonly")+2+c] != ',')
  10329. {
  10330. sstr[c] = loc[strlen("readonly")+2+c];
  10331. c++;
  10332. }
  10333. sstr[c] = '\0';
  10334. strcpy(readonlystr,sstr);
  10335. //*************************value*********************************/
  10336. loc = strstr(str, "value");
  10337. c = 0;
  10338. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10339. while (loc[strlen("value")+3+c] != '\"')
  10340. {
  10341. sstr[c] = loc[strlen("value")+3+c];
  10342. c++;
  10343. }
  10344. sstr[c] = '\0';
  10345. strcpy(valuestr,sstr);
  10346. // DEBUG_INFO("keystr=%s\n",keystr);
  10347. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10348. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10349. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10350. {
  10351. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10352. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10353. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10354. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10355. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10356. }
  10357. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10358. {
  10359. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10360. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10361. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10362. }
  10363. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10364. {
  10365. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10366. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10367. }
  10368. if(strcmp(keystr, "BlinkRepeat") == 0)
  10369. {
  10370. //Charger.BlinkRepeat = Integer.parseInt(value);
  10371. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10372. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10373. }
  10374. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10375. {
  10376. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10377. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10378. }
  10379. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10380. {
  10381. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10382. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10383. }
  10384. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10385. {
  10386. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10387. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  10388. }
  10389. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10390. {
  10391. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10392. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10393. HeartBeatWaitTime = atoi(valuestr);
  10394. }
  10395. if(strcmp(keystr, "LightIntensity") == 0)
  10396. {
  10397. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10398. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10399. }
  10400. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10401. {
  10402. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10403. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10404. }
  10405. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10406. {
  10407. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10408. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10409. }
  10410. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10411. {
  10412. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10413. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10414. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10415. }
  10416. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10417. {
  10418. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10419. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10420. }
  10421. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10422. {
  10423. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10424. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10425. }
  10426. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10427. {
  10428. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10429. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10430. }
  10431. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10432. {
  10433. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10434. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10435. }
  10436. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10437. {
  10438. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10439. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10440. }
  10441. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10442. {
  10443. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10444. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10445. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10446. }
  10447. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10448. {
  10449. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10450. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10451. }
  10452. if(strcmp(keystr, "ResetRetries") == 0)
  10453. {
  10454. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10455. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10456. }
  10457. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10458. {
  10459. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10460. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10461. }
  10462. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10463. {
  10464. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10465. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10466. }
  10467. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10468. {
  10469. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10470. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10471. }
  10472. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10473. {
  10474. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10475. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10476. }
  10477. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10478. {
  10479. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10480. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10481. }
  10482. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10483. {
  10484. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10485. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10486. }
  10487. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10488. {
  10489. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10490. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10491. }
  10492. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10493. {
  10494. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10495. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10496. }
  10497. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10498. {
  10499. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10500. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10501. }
  10502. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10503. {
  10504. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10505. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10506. }
  10507. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10508. {
  10509. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10510. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10511. TransactionMessageAttemptsValue = atoi(valuestr);
  10512. }
  10513. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10514. {
  10515. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10516. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10517. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10518. }
  10519. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10520. {
  10521. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10522. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10523. }
  10524. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10525. {
  10526. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10527. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10528. }
  10529. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  10530. {
  10531. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10532. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  10533. }
  10534. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10535. {
  10536. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10537. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10538. }
  10539. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10540. {
  10541. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10542. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10543. }
  10544. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10545. {
  10546. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10547. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10548. }
  10549. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10550. {
  10551. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10552. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10553. }
  10554. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10555. {
  10556. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10557. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10558. }
  10559. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10560. {
  10561. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10562. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10563. }
  10564. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10565. {
  10566. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10567. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10568. }
  10569. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10570. {
  10571. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10572. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10573. }
  10574. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10575. {
  10576. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10577. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10578. }
  10579. }
  10580. fclose(fp);
  10581. }
  10582. return 0;
  10583. }
  10584. void StoreConfigurationTable(void)
  10585. {
  10586. FILE *outfile;
  10587. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10588. if(outfile == NULL)
  10589. {
  10590. DEBUG_INFO("Error opening file");
  10591. return ;
  10592. }
  10593. /*Core Profile*/
  10594. //AllowOfflineTxForUnknownId
  10595. /*
  10596. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10597. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10598. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10599. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10600. */
  10601. //DEBUG_INFO("data=%s\n",data);
  10602. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10603. //AuthorizationCacheEnabled
  10604. /*
  10605. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10606. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10607. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10608. */
  10609. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10610. //AuthorizeRemoteTxRequests
  10611. /*
  10612. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10613. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10614. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10615. */
  10616. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10617. //BlinkRepeat
  10618. /*
  10619. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10620. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10621. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10622. */
  10623. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10624. //ClockAlignedDataInterval
  10625. /*
  10626. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10627. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10628. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10629. */
  10630. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10631. //ConnectionTimeOut
  10632. /*
  10633. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10634. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10635. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10636. */
  10637. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10638. //GetConfigurationMaxKeys
  10639. /*
  10640. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10641. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10642. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10643. */
  10644. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10645. // HeartbeatInterval
  10646. /*
  10647. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10648. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10649. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10650. */
  10651. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10652. // LightIntensity
  10653. /*
  10654. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10655. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10656. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10657. */
  10658. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10659. // LocalAuthorizeOffline
  10660. /*
  10661. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10662. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10663. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10664. */
  10665. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10666. // LocalPreAuthorize
  10667. /*
  10668. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10669. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10670. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10671. */
  10672. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10673. // MaxEnergyOnInvalidId
  10674. /*
  10675. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10676. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10677. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10678. */
  10679. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10680. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10681. // MeterValuesAlignedData
  10682. /*
  10683. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10684. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10685. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10686. */
  10687. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10688. // MeterValuesAlignedDataMaxLength
  10689. /*
  10690. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10691. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10692. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10693. */
  10694. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10695. // MeterValuesSampledData
  10696. /*
  10697. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10698. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10699. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10700. */
  10701. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10702. // MeterValuesSampledDataMaxLength
  10703. /*
  10704. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10705. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10706. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10707. */
  10708. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10709. // MeterValueSampleInterval
  10710. /*
  10711. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10712. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10713. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10714. */
  10715. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10716. // MinimumStatusDuration
  10717. /*
  10718. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10719. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10720. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10721. */
  10722. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10723. // NumberOfConnectors
  10724. /*
  10725. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10726. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10727. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10728. {
  10729. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10730. }
  10731. else
  10732. {
  10733. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10734. }
  10735. */
  10736. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10737. // ResetRetries
  10738. /*
  10739. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10740. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10741. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10742. */
  10743. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10744. // ConnectorPhaseRotation
  10745. /*
  10746. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10747. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10748. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10749. */
  10750. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10751. // ConnectorPhaseRotationMaxLength
  10752. /*
  10753. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10754. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10755. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10756. */
  10757. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10758. // StopTransactionOnEVSideDisconnect
  10759. /*
  10760. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10761. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10762. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10763. */
  10764. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10765. // StopTransactionOnInvalidId
  10766. /*
  10767. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  10768. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10769. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10770. */
  10771. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10772. // StopTxnAlignedData
  10773. /*
  10774. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10775. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10776. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10777. */
  10778. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10779. // StopTxnAlignedDataMaxLength
  10780. /*
  10781. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10782. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10783. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10784. */
  10785. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10786. // StopTxnSampledData
  10787. /*
  10788. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10789. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10790. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  10791. */
  10792. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10793. // StopTxnSampledDataMaxLength
  10794. /*
  10795. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10796. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10797. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10798. */
  10799. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10800. // SupportedFeatureProfiles
  10801. /*
  10802. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10804. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10805. */
  10806. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10807. // SupportedFeatureProfilesMaxLength
  10808. /*
  10809. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10810. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10811. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10812. */
  10813. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10814. // TransactionMessageAttempts
  10815. /*
  10816. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10818. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10819. */
  10820. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10821. // TransactionMessageRetryInterval
  10822. /*
  10823. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10825. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10826. */
  10827. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10828. // UnlockConnectorOnEVSideDisconnect
  10829. /*
  10830. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10831. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10832. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10833. */
  10834. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10835. // WebSocketPingInterval
  10836. /*
  10837. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10838. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10839. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10840. */
  10841. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10842. // QueueOffLineStartTransactionMessage
  10843. /*
  10844. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  10845. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10846. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10847. */
  10848. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10849. //* Local Auth List Management Profile*/
  10850. //LocalAuthListEnabled
  10851. /*
  10852. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10853. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10854. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10855. */
  10856. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10857. //LocalAuthListMaxLength
  10858. /*
  10859. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10860. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10861. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10862. */
  10863. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10864. //SendLocalListMaxLength
  10865. /*
  10866. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10867. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10868. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10869. */
  10870. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10871. //ReserveConnectorZeroSupported
  10872. /*
  10873. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10874. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10875. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10876. */
  10877. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10878. //* Smart Charging Profile */
  10879. //ChargeProfileMaxStackLevel
  10880. /*
  10881. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10882. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10883. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10884. */
  10885. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10886. // ChargingScheduleAllowedChargingRateUnit
  10887. /*
  10888. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10889. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10890. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10891. */
  10892. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10893. // ChargingScheduleMaxPeriods
  10894. /*
  10895. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10896. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10897. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10898. */
  10899. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10900. // ConnectorSwitch3to1PhaseSupported
  10901. /*
  10902. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10903. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10904. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10905. */
  10906. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10907. // MaxChargingProfilesInstalled
  10908. /*
  10909. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10910. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10911. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10912. */
  10913. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10914. fclose(outfile);
  10915. }
  10916. void getKeyValue(char *keyReq)
  10917. {
  10918. int isEmpty = FALSE;
  10919. int isKnowKey = FALSE;
  10920. DEBUG_INFO("keyReq = %s\n", keyReq);
  10921. if((keyReq == NULL) || (strlen(keyReq) == 0))
  10922. isEmpty = TRUE;
  10923. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  10924. {
  10925. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  10926. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  10927. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  10928. {
  10929. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  10930. }
  10931. else
  10932. {
  10933. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  10934. }
  10935. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  10936. isKnowKey = TRUE;
  10937. }
  10938. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  10939. {
  10940. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  10941. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  10942. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  10943. {
  10944. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  10945. }
  10946. else
  10947. {
  10948. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  10949. }
  10950. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  10951. isKnowKey = TRUE;
  10952. }
  10953. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  10954. {
  10955. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  10956. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  10957. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  10958. {
  10959. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  10960. }
  10961. else
  10962. {
  10963. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  10964. }
  10965. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  10966. isKnowKey = TRUE;
  10967. }
  10968. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  10969. {
  10970. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  10971. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  10972. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  10973. {
  10974. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  10975. }
  10976. else
  10977. {
  10978. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  10979. }
  10980. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  10981. isKnowKey = TRUE;
  10982. }
  10983. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  10984. {
  10985. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  10986. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  10987. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  10988. {
  10989. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  10990. }
  10991. else
  10992. {
  10993. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  10994. }
  10995. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  10996. isKnowKey = TRUE;
  10997. }
  10998. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  10999. {
  11000. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  11001. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  11002. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11003. {
  11004. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  11005. }
  11006. else
  11007. {
  11008. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  11009. }
  11010. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  11011. isKnowKey = TRUE;
  11012. }
  11013. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  11014. {
  11015. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  11016. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  11017. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11018. {
  11019. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  11020. }
  11021. else
  11022. {
  11023. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  11024. }
  11025. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  11026. isKnowKey = TRUE;
  11027. }
  11028. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  11029. {
  11030. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  11031. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  11032. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11033. {
  11034. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  11035. }
  11036. else
  11037. {
  11038. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  11039. }
  11040. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  11041. isKnowKey = TRUE;
  11042. }
  11043. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  11044. {
  11045. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  11046. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  11047. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11048. {
  11049. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  11050. }
  11051. else
  11052. {
  11053. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  11054. }
  11055. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  11056. isKnowKey = TRUE;
  11057. }
  11058. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  11059. {
  11060. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  11061. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  11062. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11063. {
  11064. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  11065. }
  11066. else
  11067. {
  11068. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  11069. }
  11070. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  11071. isKnowKey = TRUE;
  11072. }
  11073. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  11074. {
  11075. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  11076. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  11077. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11078. {
  11079. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  11080. }
  11081. else
  11082. {
  11083. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  11084. }
  11085. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  11086. isKnowKey = TRUE;
  11087. }
  11088. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  11089. {
  11090. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  11091. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  11092. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11093. {
  11094. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11095. }
  11096. else
  11097. {
  11098. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11099. }
  11100. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  11101. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  11102. isKnowKey = TRUE;
  11103. }
  11104. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  11105. {
  11106. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  11107. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11108. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11109. {
  11110. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11111. }
  11112. else
  11113. {
  11114. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11115. }
  11116. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11117. isKnowKey = TRUE;
  11118. }
  11119. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11120. {
  11121. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11122. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11123. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11124. {
  11125. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11126. }
  11127. else
  11128. {
  11129. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11130. }
  11131. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11132. isKnowKey = TRUE;
  11133. }
  11134. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11135. {
  11136. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11137. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11138. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11139. {
  11140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11141. }
  11142. else
  11143. {
  11144. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11145. }
  11146. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11147. isKnowKey = TRUE;
  11148. }
  11149. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11150. {
  11151. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11152. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11153. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11154. {
  11155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11156. }
  11157. else
  11158. {
  11159. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11160. }
  11161. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11162. isKnowKey = TRUE;
  11163. }
  11164. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11165. {
  11166. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11167. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11168. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11169. {
  11170. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11171. }
  11172. else
  11173. {
  11174. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11175. }
  11176. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11177. isKnowKey = TRUE;
  11178. }
  11179. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11180. {
  11181. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11182. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11183. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11184. {
  11185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11186. }
  11187. else
  11188. {
  11189. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11190. }
  11191. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11192. isKnowKey = TRUE;
  11193. }
  11194. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11195. {
  11196. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11197. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11198. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11199. {
  11200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11201. }
  11202. else
  11203. {
  11204. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11205. }
  11206. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11207. isKnowKey = TRUE;
  11208. }
  11209. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11210. {
  11211. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11212. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11213. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11214. {
  11215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11216. }
  11217. else
  11218. {
  11219. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11220. }
  11221. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11222. isKnowKey = TRUE;
  11223. }
  11224. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11225. {
  11226. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11227. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11228. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11229. {
  11230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11231. }
  11232. else
  11233. {
  11234. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11235. }
  11236. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11237. isKnowKey = TRUE;
  11238. }
  11239. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11240. {
  11241. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11242. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11243. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11244. {
  11245. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11246. }
  11247. else
  11248. {
  11249. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11250. }
  11251. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11252. isKnowKey = TRUE;
  11253. }
  11254. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11255. {
  11256. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11257. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11258. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11259. {
  11260. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11261. }
  11262. else
  11263. {
  11264. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11265. }
  11266. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11267. isKnowKey = TRUE;
  11268. }
  11269. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11270. {
  11271. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11272. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11273. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11274. {
  11275. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11276. }
  11277. else
  11278. {
  11279. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11280. }
  11281. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11282. isKnowKey = TRUE;
  11283. }
  11284. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11285. {
  11286. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11287. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11288. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11289. {
  11290. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11291. }
  11292. else
  11293. {
  11294. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11295. }
  11296. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11297. isKnowKey = TRUE;
  11298. }
  11299. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11300. {
  11301. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11302. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11303. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11304. {
  11305. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11306. }
  11307. else
  11308. {
  11309. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11310. }
  11311. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11312. isKnowKey = TRUE;
  11313. }
  11314. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11315. {
  11316. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11317. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11318. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11319. {
  11320. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11321. }
  11322. else
  11323. {
  11324. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11325. }
  11326. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11327. isKnowKey = TRUE;
  11328. }
  11329. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11330. {
  11331. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11332. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11333. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11334. {
  11335. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11336. }
  11337. else
  11338. {
  11339. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11340. }
  11341. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11342. isKnowKey = TRUE;
  11343. }
  11344. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11345. {
  11346. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11347. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11348. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11349. {
  11350. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11351. }
  11352. else
  11353. {
  11354. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11355. }
  11356. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11357. isKnowKey = TRUE;
  11358. }
  11359. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11360. {
  11361. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11362. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11363. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11364. {
  11365. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11366. }
  11367. else
  11368. {
  11369. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11370. }
  11371. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11372. isKnowKey = TRUE;
  11373. }
  11374. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11375. {
  11376. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11377. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11378. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11379. {
  11380. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11381. }
  11382. else
  11383. {
  11384. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11385. }
  11386. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11387. isKnowKey = TRUE;
  11388. }
  11389. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11390. {
  11391. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11392. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11393. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11394. {
  11395. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11396. }
  11397. else
  11398. {
  11399. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11400. }
  11401. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11402. isKnowKey = TRUE;
  11403. }
  11404. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11405. {
  11406. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11407. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11408. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11409. {
  11410. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11411. }
  11412. else
  11413. {
  11414. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11415. }
  11416. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11417. isKnowKey = TRUE;
  11418. }
  11419. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11420. {
  11421. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11422. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11423. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11424. {
  11425. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11426. }
  11427. else
  11428. {
  11429. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11430. }
  11431. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11432. isKnowKey = TRUE;
  11433. }
  11434. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  11435. {
  11436. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  11437. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  11438. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  11439. {
  11440. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  11441. }
  11442. else
  11443. {
  11444. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  11445. }
  11446. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  11447. isKnowKey = TRUE;
  11448. }
  11449. #if 1
  11450. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11451. {
  11452. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11453. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11454. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11455. {
  11456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11457. }
  11458. else
  11459. {
  11460. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11461. }
  11462. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11463. isKnowKey = TRUE;
  11464. }
  11465. #endif
  11466. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11467. {
  11468. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11469. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11470. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11471. {
  11472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11473. }
  11474. else
  11475. {
  11476. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11477. }
  11478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11479. isKnowKey = TRUE;
  11480. }
  11481. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11482. {
  11483. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11484. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11485. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11486. {
  11487. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11488. }
  11489. else
  11490. {
  11491. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11492. }
  11493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11494. isKnowKey = TRUE;
  11495. }
  11496. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11497. {
  11498. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11499. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11500. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11501. {
  11502. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11503. }
  11504. else
  11505. {
  11506. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11507. }
  11508. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11509. isKnowKey = TRUE;
  11510. }
  11511. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11512. {
  11513. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11514. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11515. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11516. {
  11517. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11518. }
  11519. else
  11520. {
  11521. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11522. }
  11523. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11524. isKnowKey = TRUE;
  11525. }
  11526. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11527. {
  11528. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11529. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11530. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11531. {
  11532. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11533. }
  11534. else
  11535. {
  11536. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11537. }
  11538. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11539. isKnowKey = TRUE;
  11540. }
  11541. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11542. {
  11543. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11544. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11545. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11546. {
  11547. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11548. }
  11549. else
  11550. {
  11551. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11552. }
  11553. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11554. isKnowKey = TRUE;
  11555. }
  11556. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11557. {
  11558. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11559. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11560. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11561. {
  11562. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11563. }
  11564. else
  11565. {
  11566. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11567. }
  11568. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11569. isKnowKey = TRUE;
  11570. }
  11571. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11572. {
  11573. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11574. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11575. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11576. {
  11577. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11578. }
  11579. else
  11580. {
  11581. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11582. }
  11583. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11584. isKnowKey = TRUE;
  11585. }
  11586. //=========================================================
  11587. if(!isEmpty && !isKnowKey)
  11588. {
  11589. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11590. strcpy(unknownkey[UnknownKeynum], keyReq);
  11591. UnknownKeynum = UnknownKeynum + 1;
  11592. }
  11593. }
  11594. void processUnkownKey(void)
  11595. {
  11596. DEBUG_INFO("processUnkownKey...\n");
  11597. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11598. for(int index=0; index < UnknownKeynum; index++)
  11599. {
  11600. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11601. {
  11602. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11603. }
  11604. }
  11605. }
  11606. int setKeyValue(char *key, char *value)
  11607. {
  11608. int isSuccess = NotSupported;
  11609. int check_ascii=0;
  11610. char str[10]={0};
  11611. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  11612. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11613. {
  11614. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11615. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11616. {
  11617. strcpy(str, (const char*)value);
  11618. for(int i = 0; str[i]; i++){
  11619. str[i] = tolower(str[i]);
  11620. }
  11621. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11622. isSuccess = ConfigurationStatus_Accepted;
  11623. }
  11624. else
  11625. {
  11626. isSuccess = ConfigurationStatus_Rejected;
  11627. }
  11628. }
  11629. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11630. {
  11631. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11632. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11633. {
  11634. strcpy(str, (const char*)value);
  11635. for(int i = 0; str[i]; i++){
  11636. str[i] = tolower(str[i]);
  11637. }
  11638. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11639. isSuccess = ConfigurationStatus_Accepted;
  11640. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11641. }
  11642. else
  11643. {
  11644. isSuccess = ConfigurationStatus_Rejected;
  11645. }
  11646. }
  11647. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11648. {
  11649. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11650. {
  11651. strcpy(str, (const char*)value);
  11652. for(int i = 0; str[i]; i++)
  11653. {
  11654. str[i] = tolower(str[i]);
  11655. }
  11656. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11657. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11658. isSuccess = ConfigurationStatus_Accepted;
  11659. }
  11660. else
  11661. {
  11662. isSuccess = ConfigurationStatus_Rejected;
  11663. }
  11664. }
  11665. if(strcmp(key, "BlinkRepeat") == 0)
  11666. {
  11667. //Charger.BlinkRepeat = Integer.parseInt(value);
  11668. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11669. {
  11670. check_ascii = value[0];
  11671. if( (check_ascii < 48) || (check_ascii > 57) )
  11672. {
  11673. isSuccess = ConfigurationStatus_Rejected;
  11674. }
  11675. else
  11676. {
  11677. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11678. isSuccess = ConfigurationStatus_Accepted;
  11679. }
  11680. }
  11681. else
  11682. {
  11683. isSuccess = ConfigurationStatus_Rejected;
  11684. }
  11685. }
  11686. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11687. {
  11688. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11689. {
  11690. check_ascii = value[0];
  11691. if( (check_ascii < 48) || (check_ascii > 57) )
  11692. {
  11693. isSuccess = ConfigurationStatus_Rejected;
  11694. }
  11695. else
  11696. {
  11697. if((atoi(value) == 0) || (atoi(value) >= 10))
  11698. {
  11699. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11700. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11701. isSuccess = ConfigurationStatus_Accepted;
  11702. }
  11703. else
  11704. isSuccess = ConfigurationStatus_Rejected;
  11705. }
  11706. }
  11707. else
  11708. {
  11709. isSuccess = ConfigurationStatus_Rejected;
  11710. }
  11711. }
  11712. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11713. {
  11714. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11715. {
  11716. check_ascii = value[0];
  11717. if( (check_ascii < 48) || (check_ascii > 57) )
  11718. {
  11719. isSuccess = ConfigurationStatus_Rejected;
  11720. }
  11721. else
  11722. {
  11723. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11724. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11725. isSuccess = ConfigurationStatus_Accepted;
  11726. }
  11727. }
  11728. else
  11729. {
  11730. isSuccess = ConfigurationStatus_Rejected;
  11731. }
  11732. }
  11733. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11734. {
  11735. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11736. {
  11737. check_ascii = value[0];
  11738. if( (check_ascii < 48) || (check_ascii > 57) )
  11739. {
  11740. isSuccess = ConfigurationStatus_Rejected;
  11741. }
  11742. else
  11743. {
  11744. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11745. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11746. isSuccess = ConfigurationStatus_Accepted;
  11747. }
  11748. }
  11749. else
  11750. {
  11751. isSuccess = ConfigurationStatus_Rejected;
  11752. }
  11753. }
  11754. if(strcmp(key, "HeartbeatInterval") == 0)
  11755. {
  11756. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11757. {
  11758. check_ascii = value[0];
  11759. if( (check_ascii < 48) || (check_ascii > 57) )
  11760. {
  11761. isSuccess = ConfigurationStatus_Rejected;
  11762. }
  11763. else
  11764. {
  11765. if((atoi(value) == 0) || (atoi(value) >= 10))
  11766. {
  11767. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11768. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11769. HeartBeatWaitTime = atoi(value);
  11770. isSuccess = ConfigurationStatus_Accepted;
  11771. }
  11772. else
  11773. {
  11774. isSuccess = ConfigurationStatus_Rejected;
  11775. }
  11776. }
  11777. }
  11778. else
  11779. {
  11780. isSuccess = ConfigurationStatus_Rejected;
  11781. }
  11782. }
  11783. if(strcmp(key, "LightIntensity") == 0)
  11784. {
  11785. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11786. {
  11787. check_ascii = value[0];
  11788. if( (check_ascii < 48) || (check_ascii > 57) )
  11789. {
  11790. isSuccess = ConfigurationStatus_Rejected;
  11791. }
  11792. else
  11793. {
  11794. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  11795. isSuccess = ConfigurationStatus_Accepted;
  11796. }
  11797. }
  11798. else
  11799. {
  11800. isSuccess = ConfigurationStatus_Rejected;
  11801. }
  11802. }
  11803. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  11804. {
  11805. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11806. {
  11807. strcpy(str, (const char*)value);
  11808. for(int i = 0; str[i]; i++)
  11809. {
  11810. str[i] = tolower(str[i]);
  11811. }
  11812. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11813. isSuccess = ConfigurationStatus_Accepted;
  11814. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11815. }
  11816. else
  11817. {
  11818. isSuccess = ConfigurationStatus_Rejected;
  11819. }
  11820. }
  11821. if(strcmp(key, "LocalPreAuthorize") == 0)
  11822. {
  11823. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11824. {
  11825. strcpy(str, (const char*)value);
  11826. for(int i = 0; str[i]; i++)
  11827. {
  11828. str[i] = tolower(str[i]);
  11829. }
  11830. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11831. isSuccess = ConfigurationStatus_Accepted;
  11832. }
  11833. else
  11834. {
  11835. isSuccess = ConfigurationStatus_Rejected;
  11836. }
  11837. }
  11838. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  11839. {
  11840. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11841. {
  11842. check_ascii = value[0];
  11843. if( (check_ascii < 48) || (check_ascii > 57) )
  11844. {
  11845. isSuccess = ConfigurationStatus_Rejected;
  11846. }
  11847. else
  11848. {
  11849. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  11850. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  11851. isSuccess = ConfigurationStatus_Accepted;
  11852. }
  11853. }
  11854. else
  11855. {
  11856. isSuccess = ConfigurationStatus_Rejected;
  11857. }
  11858. }
  11859. if(strcmp(key, "MeterValuesAlignedData") == 0)
  11860. {
  11861. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11862. {
  11863. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  11864. isSuccess = ConfigurationStatus_Accepted;
  11865. }
  11866. else
  11867. {
  11868. isSuccess = ConfigurationStatus_Rejected;
  11869. }
  11870. }
  11871. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  11872. {
  11873. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11874. {
  11875. check_ascii = value[0];
  11876. if( (check_ascii < 48) || (check_ascii > 57) )
  11877. {
  11878. isSuccess = ConfigurationStatus_Rejected;
  11879. }
  11880. else
  11881. {
  11882. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11883. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  11884. isSuccess = ConfigurationStatus_Accepted;
  11885. }
  11886. }
  11887. else
  11888. {
  11889. isSuccess = ConfigurationStatus_Rejected;
  11890. }
  11891. }
  11892. if(strcmp(key, "MeterValuesSampledData") == 0 )
  11893. {
  11894. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11895. {
  11896. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  11897. isSuccess = ConfigurationStatus_Accepted;
  11898. }
  11899. else
  11900. {
  11901. isSuccess = ConfigurationStatus_Rejected;
  11902. }
  11903. }
  11904. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  11905. {
  11906. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11907. {
  11908. check_ascii = value[0];
  11909. if( (check_ascii < 48) || (check_ascii > 57) )
  11910. {
  11911. isSuccess = ConfigurationStatus_Rejected;
  11912. }
  11913. else
  11914. {
  11915. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11916. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  11917. isSuccess = ConfigurationStatus_Accepted;
  11918. }
  11919. }
  11920. else
  11921. {
  11922. isSuccess = ConfigurationStatus_Rejected;
  11923. }
  11924. }
  11925. if(strcmp(key, "MeterValueSampleInterval") == 0)
  11926. {
  11927. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11928. {
  11929. check_ascii = value[0];
  11930. if( (check_ascii < 48) || (check_ascii > 57) )
  11931. {
  11932. isSuccess = ConfigurationStatus_Rejected;
  11933. }
  11934. else
  11935. {
  11936. if((atoi(value) == 0) || (atoi(value) >= 10))
  11937. {
  11938. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11939. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  11940. isSuccess = ConfigurationStatus_Accepted;
  11941. }
  11942. else
  11943. {
  11944. isSuccess = ConfigurationStatus_Rejected;
  11945. }
  11946. }
  11947. }
  11948. else
  11949. {
  11950. isSuccess = ConfigurationStatus_Rejected;
  11951. }
  11952. }
  11953. if(strcmp(key, "MinimumStatusDuration") == 0)
  11954. {
  11955. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11956. {
  11957. check_ascii = value[0];
  11958. if( (check_ascii < 48) || (check_ascii > 57) )
  11959. {
  11960. isSuccess = ConfigurationStatus_Rejected;
  11961. }
  11962. else
  11963. {
  11964. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  11965. {
  11966. isSuccess = ConfigurationStatus_Rejected;
  11967. }
  11968. else
  11969. {
  11970. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  11971. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  11972. server_cycle_Status = atoi(value); //StatusNotification Cycle
  11973. isSuccess = ConfigurationStatus_Accepted;
  11974. }
  11975. }
  11976. }
  11977. else
  11978. {
  11979. isSuccess = ConfigurationStatus_Rejected;
  11980. }
  11981. }
  11982. if(strcmp(key, "NumberOfConnectors") == 0)
  11983. {
  11984. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11985. {
  11986. check_ascii = value[0];
  11987. if( (check_ascii < 48) || (check_ascii > 57) )
  11988. {
  11989. isSuccess = ConfigurationStatus_Rejected;
  11990. }
  11991. else
  11992. {
  11993. //Charger.ResetRetries = Integer.parseInt(value);
  11994. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  11995. isSuccess = ConfigurationStatus_Accepted;
  11996. }
  11997. }
  11998. else
  11999. {
  12000. isSuccess = ConfigurationStatus_Rejected;
  12001. }
  12002. }
  12003. if(strcmp(key, "ResetRetries") == 0)
  12004. {
  12005. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12006. {
  12007. check_ascii = value[0];
  12008. if( (check_ascii < 48) || (check_ascii > 57) )
  12009. {
  12010. isSuccess = ConfigurationStatus_Rejected;
  12011. }
  12012. else
  12013. {
  12014. //Charger.ResetRetries = Integer.parseInt(value);
  12015. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  12016. isSuccess = ConfigurationStatus_Accepted;
  12017. }
  12018. }
  12019. else
  12020. {
  12021. isSuccess = ConfigurationStatus_Rejected;
  12022. }
  12023. }
  12024. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  12025. {
  12026. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12027. {
  12028. strcpy(str, (const char*)value);
  12029. for(int i = 0; str[i]; i++)
  12030. {
  12031. str[i] = tolower(str[i]);
  12032. }
  12033. if(strcmp(str, "notapplicable")== 0)
  12034. {
  12035. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12036. isSuccess = ConfigurationStatus_Accepted;
  12037. }
  12038. else if(strcmp(str, "unknown")== 0)
  12039. {
  12040. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12041. isSuccess = ConfigurationStatus_Accepted;
  12042. }
  12043. else if(strcmp(str, "rst")== 0)
  12044. {
  12045. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12046. isSuccess = ConfigurationStatus_Accepted;
  12047. }
  12048. else if(strcmp(str, "rts")== 0)
  12049. {
  12050. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12051. isSuccess = ConfigurationStatus_Accepted;
  12052. }
  12053. else if(strcmp(str, "srt")== 0)
  12054. {
  12055. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12056. isSuccess = ConfigurationStatus_Accepted;
  12057. }
  12058. else if(strcmp(str, "str")== 0)
  12059. {
  12060. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12061. isSuccess = ConfigurationStatus_Accepted;
  12062. }
  12063. else if(strcmp(str, "trs")== 0)
  12064. {
  12065. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12066. isSuccess = ConfigurationStatus_Accepted;
  12067. }
  12068. else if(strcmp(str, "tsr")== 0)
  12069. {
  12070. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12071. isSuccess = ConfigurationStatus_Accepted;
  12072. }
  12073. else
  12074. {
  12075. isSuccess = ConfigurationStatus_Rejected;
  12076. }
  12077. }
  12078. else
  12079. {
  12080. isSuccess = ConfigurationStatus_Rejected;
  12081. }
  12082. }
  12083. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12084. {
  12085. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12086. {
  12087. check_ascii = value[0];
  12088. if( (check_ascii < 48) || (check_ascii > 57) )
  12089. {
  12090. isSuccess = ConfigurationStatus_Rejected;
  12091. }
  12092. else
  12093. {
  12094. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12095. isSuccess = ConfigurationStatus_Accepted;
  12096. }
  12097. }
  12098. else
  12099. {
  12100. isSuccess = ConfigurationStatus_Rejected;
  12101. }
  12102. }
  12103. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12104. {
  12105. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12106. {
  12107. strcpy(str, (const char*)value);
  12108. for(int i = 0; str[i]; i++)
  12109. {
  12110. str[i] = tolower(str[i]);
  12111. }
  12112. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12113. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12114. isSuccess = ConfigurationStatus_Accepted;
  12115. }
  12116. else
  12117. {
  12118. isSuccess = ConfigurationStatus_Rejected;
  12119. }
  12120. }
  12121. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12122. {
  12123. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12124. {
  12125. strcpy(str, (const char*)value);
  12126. for(int i = 0; str[i]; i++)
  12127. {
  12128. str[i] = tolower(str[i]);
  12129. }
  12130. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12131. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12132. isSuccess = ConfigurationStatus_Accepted;
  12133. }
  12134. else
  12135. {
  12136. isSuccess = ConfigurationStatus_Rejected;
  12137. }
  12138. }
  12139. if(strcmp(key, "StopTxnAlignedData") == 0)
  12140. {
  12141. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12142. {
  12143. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12144. isSuccess = ConfigurationStatus_Accepted;
  12145. }
  12146. else
  12147. {
  12148. isSuccess = ConfigurationStatus_Rejected;
  12149. }
  12150. }
  12151. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12152. {
  12153. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12154. {
  12155. check_ascii = value[0];
  12156. if( (check_ascii < 48) || (check_ascii > 57) )
  12157. {
  12158. isSuccess = ConfigurationStatus_Rejected;
  12159. }
  12160. else
  12161. {
  12162. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12163. isSuccess = ConfigurationStatus_Accepted;
  12164. }
  12165. }
  12166. else
  12167. {
  12168. isSuccess = ConfigurationStatus_Rejected;
  12169. }
  12170. }
  12171. if(strcmp(key, "StopTxnSampledData") == 0)
  12172. {
  12173. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12174. {
  12175. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12176. isSuccess = ConfigurationStatus_Accepted;
  12177. }
  12178. else
  12179. {
  12180. isSuccess = ConfigurationStatus_Rejected;
  12181. }
  12182. }
  12183. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12184. {
  12185. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12186. {
  12187. check_ascii = value[0];
  12188. if( (check_ascii < 48) || (check_ascii > 57) )
  12189. {
  12190. isSuccess = ConfigurationStatus_Rejected;
  12191. }
  12192. else
  12193. {
  12194. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12195. isSuccess = ConfigurationStatus_Accepted;
  12196. }
  12197. }
  12198. else
  12199. {
  12200. isSuccess = ConfigurationStatus_Rejected;
  12201. }
  12202. }
  12203. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12204. {
  12205. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12206. {
  12207. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12208. isSuccess = ConfigurationStatus_Accepted;
  12209. }
  12210. else
  12211. {
  12212. isSuccess = ConfigurationStatus_Rejected;
  12213. }
  12214. }
  12215. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12216. {
  12217. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12218. {
  12219. check_ascii = value[0];
  12220. if( (check_ascii < 48) || (check_ascii > 57) )
  12221. {
  12222. isSuccess = ConfigurationStatus_Rejected;
  12223. }
  12224. else
  12225. {
  12226. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12227. isSuccess = ConfigurationStatus_Accepted;
  12228. }
  12229. }
  12230. else
  12231. {
  12232. isSuccess = ConfigurationStatus_Rejected;
  12233. }
  12234. }
  12235. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12236. {
  12237. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12238. {
  12239. check_ascii = value[0];
  12240. if( (check_ascii < 48) || (check_ascii > 57) )
  12241. {
  12242. isSuccess = ConfigurationStatus_Rejected;
  12243. }
  12244. else
  12245. {
  12246. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12247. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12248. TransactionMessageAttemptsValue = atoi(value);
  12249. isSuccess = ConfigurationStatus_Accepted;
  12250. }
  12251. }
  12252. else
  12253. {
  12254. isSuccess = ConfigurationStatus_Rejected;
  12255. }
  12256. }
  12257. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12258. {
  12259. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12260. {
  12261. check_ascii = value[0];
  12262. if( (check_ascii < 48) || (check_ascii > 57) )
  12263. {
  12264. isSuccess = ConfigurationStatus_Rejected;
  12265. }
  12266. else
  12267. {
  12268. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12269. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12270. TransactionMessageRetryIntervalValue = atoi(value);
  12271. isSuccess = ConfigurationStatus_Accepted;
  12272. }
  12273. }
  12274. else
  12275. {
  12276. isSuccess = ConfigurationStatus_Rejected;
  12277. }
  12278. }
  12279. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12280. {
  12281. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12282. {
  12283. strcpy(str, (const char*)value);
  12284. for(int i = 0; str[i]; i++)
  12285. {
  12286. str[i] = tolower(str[i]);
  12287. }
  12288. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12289. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12290. isSuccess = ConfigurationStatus_Accepted;
  12291. }
  12292. else
  12293. {
  12294. isSuccess = ConfigurationStatus_Rejected;
  12295. }
  12296. }
  12297. if(strcmp(key, "WebSocketPingInterval") == 0)
  12298. {
  12299. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12300. {
  12301. check_ascii = value[0];
  12302. if( (check_ascii < 48) || (check_ascii > 57) )
  12303. {
  12304. isSuccess = ConfigurationStatus_Rejected;
  12305. }
  12306. else
  12307. {
  12308. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12309. isSuccess = ConfigurationStatus_Accepted;
  12310. }
  12311. }
  12312. else
  12313. {
  12314. isSuccess = ConfigurationStatus_Rejected;
  12315. }
  12316. }
  12317. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  12318. {
  12319. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12320. {
  12321. strcpy(str, (const char*)value);
  12322. for(int i = 0; str[i]; i++)
  12323. {
  12324. str[i] = tolower(str[i]);
  12325. }
  12326. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12327. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12328. isSuccess = ConfigurationStatus_Accepted;
  12329. }
  12330. else
  12331. {
  12332. isSuccess = ConfigurationStatus_Rejected;
  12333. }
  12334. }
  12335. #if 0
  12336. //For OCPP Test Case
  12337. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12338. {
  12339. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12340. {
  12341. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12342. isSuccess = ConfigurationStatus_Accepted;
  12343. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12344. }
  12345. else
  12346. {
  12347. isSuccess = ConfigurationStatus_Rejected;
  12348. }
  12349. }
  12350. #endif
  12351. #if 1
  12352. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12353. {
  12354. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12355. {
  12356. strcpy(str, (const char*)value);
  12357. for(int i = 0; str[i]; i++)
  12358. {
  12359. str[i] = tolower(str[i]);
  12360. }
  12361. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12362. isSuccess = ConfigurationStatus_Accepted;
  12363. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12364. }
  12365. else
  12366. {
  12367. isSuccess = ConfigurationStatus_Rejected;
  12368. }
  12369. }
  12370. #endif
  12371. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12372. {
  12373. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12374. {
  12375. check_ascii = value[0];
  12376. if( (check_ascii < 48) || (check_ascii > 57) )
  12377. {
  12378. isSuccess = ConfigurationStatus_Rejected;
  12379. }
  12380. else
  12381. {
  12382. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12383. isSuccess = ConfigurationStatus_Accepted;
  12384. }
  12385. }
  12386. else
  12387. {
  12388. isSuccess = ConfigurationStatus_Rejected;
  12389. }
  12390. }
  12391. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12392. {
  12393. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12394. {
  12395. check_ascii = value[0];
  12396. if( (check_ascii < 48) || (check_ascii > 57) )
  12397. {
  12398. isSuccess = ConfigurationStatus_Rejected;
  12399. }
  12400. else
  12401. {
  12402. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12403. isSuccess = ConfigurationStatus_Accepted;
  12404. }
  12405. }
  12406. else
  12407. {
  12408. isSuccess = ConfigurationStatus_Rejected;
  12409. }
  12410. }
  12411. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12412. {
  12413. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12414. {
  12415. strcpy(str, (const char*)value);
  12416. for(int i = 0; str[i]; i++)
  12417. {
  12418. str[i] = tolower(str[i]);
  12419. }
  12420. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12421. isSuccess = ConfigurationStatus_Accepted;
  12422. }
  12423. else
  12424. {
  12425. isSuccess = ConfigurationStatus_Rejected;
  12426. }
  12427. }
  12428. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12429. {
  12430. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12431. {
  12432. check_ascii = value[0];
  12433. if( (check_ascii < 48) || (check_ascii > 57) )
  12434. {
  12435. isSuccess = ConfigurationStatus_Rejected;
  12436. }
  12437. else
  12438. {
  12439. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12440. isSuccess = ConfigurationStatus_Accepted;
  12441. }
  12442. }
  12443. else
  12444. {
  12445. isSuccess = ConfigurationStatus_Rejected;
  12446. }
  12447. }
  12448. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12449. {
  12450. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12451. {
  12452. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12453. isSuccess = ConfigurationStatus_Accepted;
  12454. }
  12455. else
  12456. {
  12457. isSuccess = ConfigurationStatus_Rejected;
  12458. }
  12459. }
  12460. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12461. {
  12462. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12463. {
  12464. check_ascii = value[0];
  12465. if( (check_ascii < 48) || (check_ascii > 57) )
  12466. {
  12467. isSuccess = ConfigurationStatus_Rejected;
  12468. }
  12469. else
  12470. {
  12471. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12472. isSuccess = ConfigurationStatus_Accepted;
  12473. }
  12474. }
  12475. else
  12476. {
  12477. isSuccess = ConfigurationStatus_Rejected;
  12478. }
  12479. }
  12480. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12481. {
  12482. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12483. {
  12484. strcpy(str, (const char*)value);
  12485. for(int i = 0; str[i]; i++)
  12486. {
  12487. str[i] = tolower(str[i]);
  12488. }
  12489. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12490. isSuccess = ConfigurationStatus_Accepted;
  12491. }
  12492. else
  12493. {
  12494. isSuccess = ConfigurationStatus_Rejected;
  12495. }
  12496. }
  12497. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12498. {
  12499. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12500. {
  12501. check_ascii = value[0];
  12502. if( (check_ascii < 48) || (check_ascii > 57) )
  12503. {
  12504. isSuccess = ConfigurationStatus_Rejected;
  12505. }
  12506. else
  12507. {
  12508. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12509. isSuccess = ConfigurationStatus_Accepted;
  12510. }
  12511. }
  12512. else
  12513. {
  12514. isSuccess = ConfigurationStatus_Rejected;
  12515. }
  12516. }
  12517. return isSuccess;
  12518. }
  12519. int TransactionMessageAttemptsGet(void)
  12520. {
  12521. return TransactionMessageAttemptsValue;
  12522. }
  12523. int FirstHeartBeatResponse(void)
  12524. {
  12525. return FirstHeartBeat;
  12526. }
  12527. int TransactionMessageRetryIntervalGet(void)
  12528. {
  12529. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12530. }
  12531. int ReadHttpStatus(int sock)
  12532. {
  12533. //char c;
  12534. char buff[1024]="",*ptr=buff+1;
  12535. int bytes_received, status;
  12536. DEBUG_INFO("Begin Response ..\n");
  12537. while((bytes_received = recv(sock, ptr, 1, 0))){
  12538. if(bytes_received==-1){
  12539. perror("ReadHttpStatus");
  12540. exit(1);
  12541. }
  12542. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12543. ptr++;
  12544. }
  12545. *ptr=0;
  12546. ptr=buff+1;
  12547. sscanf(ptr,"%*s %d ", &status);
  12548. DEBUG_INFO("%s\n",ptr);
  12549. DEBUG_INFO("status=%d\n",status);
  12550. DEBUG_INFO("End Response ..\n");
  12551. return (bytes_received>0)?status:0;
  12552. }
  12553. //the only filed that it parsed is 'Content-Length'
  12554. int ParseHeader(int sock)
  12555. {
  12556. //char c;
  12557. char buff[1024]="",*ptr=buff+4;
  12558. int bytes_received;
  12559. DEBUG_INFO("Begin HEADER ..\n");
  12560. while((bytes_received = recv(sock, ptr, 1, 0))){
  12561. if(bytes_received==-1){
  12562. perror("Parse Header");
  12563. exit(1);
  12564. }
  12565. if(
  12566. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12567. (ptr[-1]=='\r') && (*ptr=='\n' )
  12568. ) break;
  12569. ptr++;
  12570. }
  12571. *ptr=0;
  12572. ptr=buff+4;
  12573. //printf("%s",ptr);
  12574. if(bytes_received){
  12575. ptr=strstr(ptr,"Content-Length:");
  12576. if(ptr){
  12577. sscanf(ptr,"%*s %d",&bytes_received);
  12578. }else
  12579. bytes_received=-1; //unknown size
  12580. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12581. }
  12582. DEBUG_INFO("End HEADER ..\n");
  12583. return bytes_received ;
  12584. }
  12585. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12586. {
  12587. char rmFileCmd[100]={0};
  12588. char FilePath[100]={0};
  12589. char ftpbuf[200];
  12590. int systemresult;
  12591. //DEBUG_INFO("filename=%s\n",filename);
  12592. //DEBUG_INFO("url=%s\n",url);
  12593. sprintf(FilePath,"/mnt/%s",filename);
  12594. if((access(FilePath,F_OK))!=-1)
  12595. {
  12596. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12597. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12598. system(rmFileCmd);
  12599. }
  12600. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12601. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12602. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12603. systemresult = system(ftpbuf);
  12604. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12605. if(systemresult != 0)
  12606. {
  12607. DEBUG_INFO("http DownLoad error!\n");
  12608. return FALSE;
  12609. }
  12610. return TRUE;
  12611. }
  12612. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12613. {
  12614. char rmFileCmd[100]={0};
  12615. char FilePath[100]={0};
  12616. char ftpbuf[200];
  12617. int systemresult;
  12618. //char temp[100];
  12619. sprintf(FilePath,"/mnt/%s",filename);
  12620. if((access(FilePath,F_OK))!=-1)
  12621. {
  12622. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12623. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12624. system(rmFileCmd);
  12625. }
  12626. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12627. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12628. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12629. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12630. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12631. systemresult = system(ftpbuf);
  12632. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12633. if(systemresult != 0)
  12634. {
  12635. printf("wget error!\n");
  12636. return FALSE;
  12637. }
  12638. return TRUE;
  12639. }
  12640. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12641. {
  12642. char rmFileCmd[100]={0};
  12643. char FilePath[100]={0};
  12644. char ftpbuf[200];
  12645. int systemresult;
  12646. //DEBUG_INFO("filename=%s\n",filename);
  12647. //DEBUG_INFO("url=%s\n",url);
  12648. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12649. if((access(FilePath,F_OK))!=-1)
  12650. {
  12651. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12652. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12653. system(rmFileCmd);
  12654. }
  12655. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12656. if(fp == NULL)
  12657. {
  12658. DEBUG_INFO("log is NULL\n");
  12659. return FALSE;
  12660. }
  12661. else
  12662. {
  12663. fprintf(fp, "%s\n", url);
  12664. fprintf(fp, "%s\n", filename);
  12665. fclose(fp);
  12666. }
  12667. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12668. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12669. systemresult = system(ftpbuf);
  12670. DEBUG_INFO("systemresult = %d\n",systemresult);
  12671. if(systemresult != 0)
  12672. {
  12673. DEBUG_INFO("http upload error!\n");
  12674. return FALSE;
  12675. }
  12676. return TRUE;
  12677. }
  12678. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12679. {
  12680. struct hostent* server;
  12681. char *IPbuffer;
  12682. char ftpbuf[200];
  12683. int systemresult;
  12684. // To retrieve host information
  12685. server = gethostbyname(location);
  12686. // To convert an Internet network
  12687. // address into ASCII string
  12688. IPbuffer = inet_ntoa(*((struct in_addr*)
  12689. server->h_addr_list[0]));
  12690. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12691. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12692. /* format : ftpput -u username -p passwd IP target source*/
  12693. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12694. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12695. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12696. systemresult = system(ftpbuf);
  12697. DEBUG_INFO("systemresult=%d\n",systemresult);
  12698. if(systemresult != 0)
  12699. {
  12700. DEBUG_INFO("ftpput error!\n");
  12701. return FALSE;
  12702. }
  12703. return TRUE;
  12704. }
  12705. /**
  12706. * Place the contents of the specified file into a memory buffer
  12707. *
  12708. * @param[in] filename The path and name of the file to read
  12709. * @param[out] filebuffer A pointer to the contents in memory
  12710. * @return status 0 success, 1 on failure
  12711. */
  12712. int get_file_contents(const char* filename, char** outbuffer) {
  12713. FILE* file = NULL;
  12714. long filesize;
  12715. const int blocksize = 1;
  12716. size_t readsize;
  12717. char* filebuffer;
  12718. // Open the file
  12719. file = fopen(filename, "r");
  12720. if (NULL == file)
  12721. {
  12722. printf("'%s' not opened\n", filename);
  12723. exit(EXIT_FAILURE);
  12724. }
  12725. // Determine the file size
  12726. fseek(file, 0, SEEK_END);
  12727. filesize = ftell(file);
  12728. rewind (file);
  12729. // Allocate memory for the file contents
  12730. filebuffer = (char*) malloc(sizeof(char) * filesize);
  12731. *outbuffer = filebuffer;
  12732. if (filebuffer == NULL)
  12733. {
  12734. fputs ("malloc out-of-memory", stderr);
  12735. exit(EXIT_FAILURE);
  12736. }
  12737. // Read in the file
  12738. readsize = fread(filebuffer, blocksize, filesize, file);
  12739. if (readsize != filesize)
  12740. {
  12741. fputs ("didn't read file completely",stderr);
  12742. exit(EXIT_FAILURE);
  12743. }
  12744. // Clean exit
  12745. fclose(file);
  12746. return EXIT_SUCCESS;
  12747. }
  12748. static int selectSqlCount = 0;
  12749. static int callback(void *data, int argc, char **argv, char **azColName){
  12750. int i;
  12751. //printf("%s: ", (const char*)data);
  12752. selectSqlCount = argc;
  12753. for(i = 0; i<argc; i++){
  12754. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  12755. }
  12756. //printf("\n");
  12757. return 0;
  12758. }
  12759. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  12760. //int i;
  12761. //printf("%s:\n", (const char*)data);
  12762. localversion = argv[5] ? atoi(argv[5]) : 0;
  12763. //printf("localversion=%d\n", localversion);
  12764. return 0;
  12765. }
  12766. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  12767. //int i;
  12768. //printf("%s:\n", (const char*)data);
  12769. //idTag
  12770. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  12771. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  12772. //parentIdTag
  12773. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  12774. //expir_date
  12775. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  12776. //status
  12777. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  12778. //version
  12779. idTagQuery.listVersionInt = atoi(argv[5]);
  12780. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  12781. return 0;
  12782. }
  12783. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  12784. {
  12785. // localversion = argv[5] ? atoi(argv[5]) : 0;
  12786. // printf("localversion=%d\n", localversion);
  12787. return 0;
  12788. }
  12789. //=========================================
  12790. // Sqlite3 related function
  12791. //=========================================
  12792. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  12793. {
  12794. for (int i = 0; i < n_columns; i++)
  12795. {
  12796. DEBUG_INFO("%s\t", col_values[i]);
  12797. }
  12798. DEBUG_INFO("\n");
  12799. return 0;
  12800. }
  12801. void OCPP_getListVerion()
  12802. {
  12803. int rc = 0;
  12804. // const char* data = "Callback function called";
  12805. char sql[100];
  12806. char zErrMsg[100];
  12807. memset(sql, 0, 100);
  12808. memset(zErrMsg, 0, 100);
  12809. strcpy(sql, "select * from ocpp_auth_local order by idx");
  12810. /* Execute SQL statement */
  12811. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  12812. if( rc != SQLITE_OK )
  12813. {
  12814. DEBUG_INFO("SQL error: %s", zErrMsg);
  12815. }
  12816. }
  12817. void OCPP_getIdTag(char idTag[])
  12818. {
  12819. int rc = 0;
  12820. // const char* data = "Callback function called";
  12821. char sql[100];
  12822. char zErrMsg[100];
  12823. memset(sql, 0, 100);
  12824. memset(zErrMsg, 0, 100);
  12825. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  12826. memset(&idTagQuery, 0, sizeof(idTagQuery));
  12827. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  12828. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12829. /* Execute SQL statement */
  12830. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  12831. if( rc != SQLITE_OK )
  12832. {
  12833. DEBUG_INFO("SQL error: %s", zErrMsg);
  12834. }
  12835. //return ver;
  12836. }
  12837. void OCPP_get_TableAuthlocalAllData(void)
  12838. {
  12839. int rc = 0;
  12840. char sql[100];
  12841. char zErrMsg[100];
  12842. memset(sql, 0, 100);
  12843. memset(zErrMsg, 0, 100);
  12844. sprintf(sql,"select * from ocpp_auth_local ");
  12845. /* Execute SQL statement */
  12846. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  12847. if( rc != SQLITE_OK )
  12848. {
  12849. DEBUG_INFO("SQL error: %s", zErrMsg);
  12850. }
  12851. //return ver;
  12852. }
  12853. int OCPP_cleanLocalList()
  12854. {
  12855. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  12856. char *errMsg = 0;
  12857. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  12858. if (SQLITE_OK != rc)
  12859. {
  12860. DEBUG_INFO("%s\n",errMsg);
  12861. return FALSE;
  12862. }
  12863. return TRUE;
  12864. }
  12865. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12866. {
  12867. int isSuccess = FALSE;
  12868. int ret = 0;
  12869. //const char* data = "Callback function called";
  12870. char sql[300];
  12871. char zErrMsg[200];
  12872. memset(sql, 0, 300);
  12873. memset(zErrMsg, 0, 200);
  12874. 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);
  12875. //* Execute SQL statement */
  12876. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  12877. if( ret != SQLITE_OK )
  12878. {
  12879. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12880. return isSuccess;
  12881. }
  12882. memset(sql, 0, 300);
  12883. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  12884. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  12885. if( ret != SQLITE_OK )
  12886. {
  12887. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12888. return isSuccess;
  12889. }
  12890. isSuccess = TRUE;
  12891. return isSuccess;
  12892. }
  12893. void OCPP_deleteIdTag(char idTag[])
  12894. {
  12895. //int ver = 0;
  12896. //int isSuccess = FALSE;
  12897. int rc = 0;
  12898. char sql[100];
  12899. char zErrMsg[100];
  12900. memset(sql, 0, 100);
  12901. memset(zErrMsg, 0, 100);
  12902. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  12903. //* Execute SQL statement */
  12904. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  12905. if( rc != SQLITE_OK )
  12906. {
  12907. DEBUG_INFO("SQL error: %s", zErrMsg);
  12908. }
  12909. }
  12910. int GetOcppServerURL()
  12911. {
  12912. int result = FALSE;
  12913. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  12914. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  12915. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  12916. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  12917. {
  12918. #if 1
  12919. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  12920. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12921. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12922. #endif
  12923. result = TRUE;
  12924. goto End;
  12925. }
  12926. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  12927. {
  12928. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  12929. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12930. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12931. result = TRUE;
  12932. goto End;
  12933. }
  12934. else
  12935. {
  12936. strcpy(OcppHost,"");
  12937. }
  12938. End:
  12939. return result;
  12940. }
  12941. int GetOcppPath()
  12942. {
  12943. int result = FALSE;
  12944. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  12945. {
  12946. if(OcppTempPath == NULL)
  12947. {
  12948. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12949. }
  12950. else
  12951. {
  12952. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12953. }
  12954. result = TRUE;
  12955. goto End;
  12956. }
  12957. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  12958. {
  12959. if(OcppTempPath == NULL)
  12960. {
  12961. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  12962. }
  12963. else
  12964. {
  12965. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  12966. }
  12967. result = TRUE;
  12968. goto End;
  12969. }
  12970. else
  12971. {
  12972. strcpy(OcppPath,"");
  12973. }
  12974. End:
  12975. return result;
  12976. }
  12977. int GetOcppPort()
  12978. {
  12979. return OcppPort;
  12980. }
  12981. int GetOcppConnStatus(void)
  12982. {
  12983. return ShmOCPP16Data->OcppConnStatus;
  12984. }
  12985. void SetOcppConnStatus(uint8_t status)
  12986. {
  12987. ShmOCPP16Data->OcppConnStatus = status;
  12988. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  12989. }
  12990. int GetHeartBeatWithNOResponse(void)
  12991. {
  12992. return HeartBeatWithNOResponse;
  12993. }
  12994. void SetHeartBeatWithNOResponse(void)
  12995. {
  12996. HeartBeatWithNOResponse = 0;
  12997. }
  12998. void GetStartTransactionIdTag(int gun_index)
  12999. {
  13000. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  13001. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13002. }
  13003. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  13004. {
  13005. char ch;
  13006. FILE *fptr1;
  13007. int temptransactionId;
  13008. char str[100]={0};
  13009. temptransactionId = 0;
  13010. if((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0'))
  13011. {
  13012. DEBUG_INFO("IdTag is empty.\n");
  13013. return temptransactionId;
  13014. }
  13015. /*------ Read the file ----------------*/
  13016. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  13017. if (!fptr1)
  13018. {
  13019. DEBUG_INFO("QueueTransactionId file open error.\n");
  13020. //printf(" File not found or unable to open the input file!!\n");
  13021. return temptransactionId;
  13022. }
  13023. ch=fgetc(fptr1);
  13024. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13025. rewind(fptr1);
  13026. if(ch!=EOF)
  13027. {
  13028. // printf("%c",ch);
  13029. while (fgets(str, 100, fptr1) != NULL)
  13030. {
  13031. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13032. if(str[0]=='\0')
  13033. {
  13034. break;
  13035. }
  13036. char *revbuf[8] = {0}; //存放分割後的子字串
  13037. int num = 0;//分割後子字串的個數
  13038. DEBUG_INFO("str: %s\n", str);
  13039. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  13040. DEBUG_INFO("revbuf[0]: %s\n", revbuf[0]);
  13041. DEBUG_INFO("revbuf[1]: %s\n", revbuf[1]);
  13042. DEBUG_INFO("revbuf[2]: %s\n", revbuf[2]);
  13043. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13044. {
  13045. if(isStopTransaction)
  13046. {
  13047. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  13048. {
  13049. temptransactionId = atoi(revbuf[2]);
  13050. break;
  13051. }
  13052. }
  13053. else
  13054. {
  13055. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13056. {
  13057. temptransactionId = atoi(revbuf[2]);
  13058. break;
  13059. }
  13060. }
  13061. }
  13062. }
  13063. }
  13064. else
  13065. DEBUG_INFO("EOF\n");
  13066. fclose(fptr1);
  13067. /*------- End of reading ---------------*/
  13068. return temptransactionId;
  13069. }
  13070. void SetTransactionIdZero(int transactionId)
  13071. {
  13072. char ch;
  13073. FILE *fptr1, *fptr2;
  13074. int temptransactionId = 0;
  13075. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13076. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13077. if (!fptr1)
  13078. {
  13079. //printf(" File not found or unable to open the input file!!\n");
  13080. return ;
  13081. }
  13082. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13083. if (!fptr2)
  13084. {
  13085. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  13086. fclose(fptr1);
  13087. return ;
  13088. }
  13089. ch=fgetc(fptr1);
  13090. rewind(fptr1);
  13091. if(ch!=EOF)
  13092. {
  13093. // copy all contents to the temporary file except the specific line
  13094. while (fgets(str, 100, fptr1) != NULL)
  13095. {
  13096. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13097. if(str[0]=='\0')
  13098. {
  13099. break;
  13100. }
  13101. char *revbuf[8] = {0};
  13102. int num = 0;
  13103. strcpy(strtemp, str);
  13104. splitstring(str,",",revbuf,&num);
  13105. if(revbuf[2][0] != '\0')
  13106. {
  13107. temptransactionId = atoi(revbuf[2]);
  13108. if(transactionId != temptransactionId)
  13109. {
  13110. fprintf(fptr2, "%s\n", strtemp);
  13111. }
  13112. }
  13113. }
  13114. }
  13115. fclose(fptr1);
  13116. fclose(fptr2);
  13117. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13118. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13119. /*------ Read the file ----------------*/
  13120. }
  13121. int InternetDisconnect(void)
  13122. {
  13123. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13124. }
  13125. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  13126. void storeTempStopTransaction(int gun_index)
  13127. {
  13128. char guid[37]={0};
  13129. int tempIndex = 0;
  13130. DEBUG_INFO("storeTempStopTransaction...\n");
  13131. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  13132. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  13133. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13134. if(gunType[gun_index] == 'J')
  13135. {
  13136. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13137. {
  13138. tempIndex = ((gun_index==2) ? 1: 0);
  13139. }
  13140. else
  13141. {
  13142. tempIndex = gun_index;
  13143. }
  13144. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13145. {
  13146. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13147. {
  13148. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  13149. }
  13150. }// END OF CHAdeMO_QUANTITY
  13151. }
  13152. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13153. {
  13154. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13155. {
  13156. tempIndex = ((gun_index==2) ? 1: 0);
  13157. }
  13158. else
  13159. {
  13160. tempIndex = gun_index;
  13161. }
  13162. for (int index = 0; index < CCS_QUANTITY; index++)
  13163. {
  13164. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13165. {
  13166. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  13167. }
  13168. }// END OF CCS_QUANTITY
  13169. }
  13170. else if(gunType[gun_index] == 'G')
  13171. {
  13172. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13173. {
  13174. tempIndex = ((gun_index==2) ? 1: 0);
  13175. }
  13176. else
  13177. {
  13178. tempIndex = gun_index;
  13179. }
  13180. for (int index = 0; index < GB_QUANTITY; index++)
  13181. {
  13182. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13183. {
  13184. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  13185. }
  13186. }// END OF GB_QUANTITY
  13187. }
  13188. else
  13189. {
  13190. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13191. {
  13192. tempIndex = 2;
  13193. }
  13194. else
  13195. {
  13196. tempIndex = gun_index;
  13197. }
  13198. for (int index = 0; index < AC_QUANTITY; index++)
  13199. {
  13200. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13201. {
  13202. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  13203. }
  13204. }// END OF AC_QUANTITY
  13205. }
  13206. //Stop Transaction Time
  13207. struct timeval tmnow;
  13208. struct tm *tm;
  13209. char buf[28];//, usec_buf[6];
  13210. gettimeofday(&tmnow, NULL);
  13211. time_t t;
  13212. t = time(NULL);
  13213. /*UTC time and date*/
  13214. tm = gmtime(&t);
  13215. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  13216. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  13217. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  13218. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13219. random_uuid(guid);
  13220. /***********************************transactionData******************************************************/
  13221. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  13222. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  13223. //=================================
  13224. //1. Transaction_Begin
  13225. //=================================
  13226. //============================== Energy.Active.Import.Interval ===========================================
  13227. //idx_sample=0;
  13228. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  13229. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  13230. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  13231. 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*/]);
  13232. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13233. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13234. {
  13235. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  13236. }
  13237. else
  13238. {
  13239. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  13240. }
  13241. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  13242. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13243. //=================================
  13244. //2. Transaction_End
  13245. //=================================
  13246. //2.1====================================== Current.Import L1 ==============================================
  13247. //idx_sample=1;
  13248. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  13249. if(gunType[gun_index] == 'J')
  13250. {
  13251. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13252. {
  13253. tempIndex = ((gun_index==2) ? 1: 0);
  13254. }
  13255. else
  13256. {
  13257. tempIndex = gun_index;
  13258. }
  13259. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13260. {
  13261. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13262. {
  13263. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13264. }
  13265. }// End of for CHAdeMO_QUANTITY
  13266. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13267. }
  13268. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13269. {
  13270. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13271. {
  13272. tempIndex = ((gun_index==2) ? 1: 0);
  13273. }
  13274. else
  13275. {
  13276. tempIndex = gun_index;
  13277. }
  13278. for (int index = 0; index < CCS_QUANTITY; index++)
  13279. {
  13280. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13281. {
  13282. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13283. }
  13284. }// End of for CCS_QUANTITY
  13285. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13286. }
  13287. else if(gunType[gun_index] == 'G')
  13288. {
  13289. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13290. {
  13291. tempIndex = ((gun_index==2) ? 1: 0);
  13292. }
  13293. else
  13294. {
  13295. tempIndex = gun_index;
  13296. }
  13297. for (int index = 0; index < GB_QUANTITY; index++)
  13298. {
  13299. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13300. {
  13301. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13302. }
  13303. }// End of for GB_QUANTITY
  13304. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13305. }
  13306. else
  13307. {
  13308. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13309. {
  13310. tempIndex = 2;
  13311. }
  13312. else
  13313. {
  13314. tempIndex = gun_index;
  13315. }
  13316. for (int index = 0; index < AC_QUANTITY; index++)
  13317. {
  13318. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13319. {
  13320. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  13321. }
  13322. }// End of for AC_QUANTITY
  13323. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13324. }
  13325. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13326. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  13327. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  13328. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13329. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  13330. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13331. //2.2===================================== Energy.Active.Import.Interval ==========================================
  13332. //idx_sample=2;
  13333. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13334. if(gunType[gun_index] == 'J')
  13335. {
  13336. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13337. {
  13338. tempIndex = ((gun_index==2) ? 1: 0);
  13339. }
  13340. else
  13341. {
  13342. tempIndex = gun_index;
  13343. }
  13344. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13345. {
  13346. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13347. {
  13348. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13349. }
  13350. }// END OF CHAdeMO_QUANTITY
  13351. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13352. }
  13353. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13354. {
  13355. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13356. {
  13357. tempIndex = ((gun_index==2) ? 1: 0);
  13358. }
  13359. else
  13360. {
  13361. tempIndex = gun_index;
  13362. }
  13363. for (int index = 0; index < CCS_QUANTITY; index++)
  13364. {
  13365. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13366. {
  13367. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13368. }
  13369. }// END OF CCS_QUANTITY
  13370. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13371. }
  13372. else if(gunType[gun_index] == 'G')
  13373. {
  13374. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13375. {
  13376. tempIndex = ((gun_index==2) ? 1: 0);
  13377. }
  13378. else
  13379. {
  13380. tempIndex = gun_index;
  13381. }
  13382. for (int index = 0; index < GB_QUANTITY; index++)
  13383. {
  13384. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13385. {
  13386. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13387. }
  13388. }// END OF GB_QUANTITY
  13389. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13390. }
  13391. else
  13392. {
  13393. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13394. {
  13395. tempIndex = 2;
  13396. }
  13397. else
  13398. {
  13399. tempIndex = gun_index;
  13400. }
  13401. for (int index = 0; index < AC_QUANTITY; index++)
  13402. {
  13403. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13404. {
  13405. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13406. }
  13407. }// END OF AC_QUANTITY
  13408. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13409. }
  13410. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13411. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  13412. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  13413. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13414. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  13415. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13416. //2.3====================================== Power.Active.Import =========================================
  13417. //idx_sample=3;
  13418. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13419. if(gunType[gun_index] == 'J')
  13420. {
  13421. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13422. {
  13423. tempIndex = ((gun_index==2) ? 1: 0);
  13424. }
  13425. else
  13426. {
  13427. tempIndex = gun_index;
  13428. }
  13429. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13430. {
  13431. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13432. {
  13433. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13434. }
  13435. } // End for CHAdeMO_QUANTITY
  13436. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13437. }
  13438. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13439. {
  13440. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13441. {
  13442. tempIndex = ((gun_index==2) ? 1: 0);
  13443. }
  13444. else
  13445. {
  13446. tempIndex = gun_index;
  13447. }
  13448. for (int index = 0; index < CCS_QUANTITY; index++)
  13449. {
  13450. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13451. {
  13452. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13453. }
  13454. } // END for CCS_QUANTITY
  13455. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13456. }
  13457. else if(gunType[gun_index] == 'G')
  13458. {
  13459. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13460. {
  13461. tempIndex = ((gun_index==2) ? 1: 0);
  13462. }
  13463. else
  13464. {
  13465. tempIndex = gun_index;
  13466. }
  13467. for (int index = 0; index < GB_QUANTITY; index++)
  13468. {
  13469. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13470. {
  13471. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13472. }
  13473. }// END for GB_QUANTITY
  13474. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13475. }
  13476. else
  13477. {
  13478. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13479. {
  13480. tempIndex = 2;
  13481. }
  13482. else
  13483. {
  13484. tempIndex = gun_index;
  13485. }
  13486. for (int index = 0; index < AC_QUANTITY; index++)
  13487. {
  13488. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13489. {
  13490. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13491. }
  13492. } // END for AC_QUANTITY
  13493. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13494. }
  13495. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13496. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  13497. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  13498. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13499. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  13500. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  13501. //2.4====================================== Voltage L1 ====================================================
  13502. //idx_sample=4;
  13503. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13504. if(gunType[gun_index] == 'J')
  13505. {
  13506. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13507. {
  13508. tempIndex = ((gun_index==2) ? 1: 0);
  13509. }
  13510. else
  13511. {
  13512. tempIndex = gun_index;
  13513. }
  13514. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13515. {
  13516. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13517. {
  13518. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13519. }
  13520. } // END OF FOR CHAdeMO_QUANTITY
  13521. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13522. }
  13523. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13524. {
  13525. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13526. {
  13527. tempIndex = ((gun_index==2) ? 1: 0);
  13528. }
  13529. else
  13530. {
  13531. tempIndex = gun_index;
  13532. }
  13533. for (int index = 0; index < CCS_QUANTITY; index++)
  13534. {
  13535. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13536. {
  13537. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13538. }
  13539. } // END OF FOR CCS_QUANTITY
  13540. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13541. }
  13542. else if(gunType[gun_index] == 'G')
  13543. {
  13544. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13545. {
  13546. tempIndex = ((gun_index==2) ? 1: 0);
  13547. }
  13548. else
  13549. {
  13550. tempIndex = gun_index;
  13551. }
  13552. for (int index = 0; index < GB_QUANTITY; index++)
  13553. {
  13554. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13555. {
  13556. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13557. }
  13558. } // END OF FOR GB_QUANTITY
  13559. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13560. }
  13561. else
  13562. {
  13563. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13564. {
  13565. tempIndex = 2;
  13566. }
  13567. else
  13568. {
  13569. tempIndex = gun_index;
  13570. }
  13571. for (int index = 0; index < AC_QUANTITY; index++)
  13572. {
  13573. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13574. {
  13575. 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
  13576. }
  13577. } // END OF FOR AC_QUANTITY
  13578. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13579. }
  13580. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13581. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  13582. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  13583. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13584. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  13585. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13586. //2.5============================================== SoC =========================================================
  13587. //idx_sample=5;
  13588. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13589. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13590. {
  13591. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13592. {
  13593. tempIndex = ((gun_index==2) ? 1: 0);
  13594. }
  13595. else
  13596. {
  13597. tempIndex = gun_index;
  13598. }
  13599. if(gunType[gun_index] == 'J')
  13600. {
  13601. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13602. {
  13603. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13604. {
  13605. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  13606. }
  13607. }
  13608. }
  13609. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13610. {
  13611. for (int index = 0; index < CCS_QUANTITY; index++)
  13612. {
  13613. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13614. {
  13615. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  13616. }
  13617. }
  13618. }
  13619. else if(gunType[gun_index] == 'G')
  13620. {
  13621. for (int index = 0; index < GB_QUANTITY; index++)
  13622. {
  13623. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13624. {
  13625. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  13626. }
  13627. }
  13628. }
  13629. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13630. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  13631. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  13632. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  13633. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  13634. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  13635. } // END FOR DC CASE
  13636. //2.6====================================== Current.Import L2 ==============================================
  13637. // idx_sample=6;
  13638. // AC 3 phase L2 current
  13639. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13640. {
  13641. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13642. {
  13643. tempIndex = 2;
  13644. }
  13645. else
  13646. {
  13647. tempIndex = gun_index;
  13648. }
  13649. for (int index = 0; index < AC_QUANTITY; index++)
  13650. {
  13651. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13652. {
  13653. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  13654. }
  13655. }// End of for AC_QUANTITY
  13656. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  13657. }
  13658. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13659. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  13660. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  13661. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  13662. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13663. //2.7====================================== Current.Import L3 ==============================================
  13664. // idx_sample=7;
  13665. // AC 3 phase L3 current
  13666. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13667. {
  13668. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13669. {
  13670. tempIndex = 2;
  13671. }
  13672. else
  13673. {
  13674. tempIndex = gun_index;
  13675. }
  13676. for (int index = 0; index < AC_QUANTITY; index++)
  13677. {
  13678. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13679. {
  13680. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  13681. }
  13682. }// End of for AC_QUANTITY
  13683. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  13684. }
  13685. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13686. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  13687. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  13688. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  13689. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13690. //2.9====================================== Voltage L2 ====================================================
  13691. //idx_sample=8;
  13692. // AC 3 phase L2 volatge
  13693. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13694. {
  13695. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13696. {
  13697. tempIndex = 2;
  13698. }
  13699. else
  13700. {
  13701. tempIndex = gun_index;
  13702. }
  13703. for (int index = 0; index < AC_QUANTITY; index++)
  13704. {
  13705. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13706. {
  13707. 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
  13708. }
  13709. } // END OF FOR AC_QUANTITY
  13710. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  13711. }
  13712. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13713. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  13714. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  13715. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  13716. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13717. //2.10====================================== Voltage L3 ====================================================
  13718. //idx_sample=9;
  13719. // AC 3 phase L3 volatge
  13720. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13721. {
  13722. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13723. {
  13724. tempIndex = 2;
  13725. }
  13726. else
  13727. {
  13728. tempIndex = gun_index;
  13729. }
  13730. for (int index = 0; index < AC_QUANTITY; index++)
  13731. {
  13732. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13733. {
  13734. 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
  13735. }
  13736. } // END OF FOR AC_QUANTITY
  13737. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  13738. }
  13739. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13740. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  13741. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  13742. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  13743. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13744. //======================================== Message create ==============================================
  13745. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13746. {
  13747. 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\"}]}]}]"
  13748. ,gun_index+1
  13749. ,MESSAGE_TYPE_CALL
  13750. ,guid
  13751. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13752. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13753. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13754. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13755. ,"PowerLoss"
  13756. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13757. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13758. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13759. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13760. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13761. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13762. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13763. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13764. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13765. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13766. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13767. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13768. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13769. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13770. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13771. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13772. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13773. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13774. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13775. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13776. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13777. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13778. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13779. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13780. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13781. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13782. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13783. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13784. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13785. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13786. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13787. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13788. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13789. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13790. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13791. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13792. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  13793. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  13794. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  13795. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  13796. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  13797. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  13798. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  13799. );
  13800. }
  13801. else
  13802. {
  13803. if(((ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'W')))
  13804. {
  13805. 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\"}]}]}]"
  13806. ,gun_index+1
  13807. ,MESSAGE_TYPE_CALL
  13808. ,guid
  13809. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13810. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13811. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13812. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13813. ,"PowerLoss"
  13814. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13815. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13816. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13817. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13818. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13819. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13820. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13821. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13822. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13823. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13824. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13825. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13826. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13827. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13828. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13829. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13830. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13831. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13832. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13833. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13834. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13835. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13836. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13837. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13838. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13839. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13840. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13841. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13842. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13843. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13844. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13845. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13846. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13847. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13848. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13849. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13850. );
  13851. }
  13852. else
  13853. {
  13854. 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\"}]}]}]"
  13855. ,gun_index+1
  13856. ,MESSAGE_TYPE_CALL
  13857. ,guid
  13858. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13859. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13860. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13861. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13862. ,"PowerLoss"
  13863. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13864. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13865. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13866. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13867. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13868. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13869. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13870. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13871. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13872. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13873. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13874. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13875. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13876. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13877. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13878. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13879. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13880. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13881. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13882. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13883. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13884. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13885. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13886. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13887. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13888. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13889. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13890. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13891. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13892. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13893. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13894. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13895. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13896. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13897. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13898. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13899. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value
  13900. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context
  13901. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format
  13902. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand
  13903. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase
  13904. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location
  13905. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit
  13906. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value
  13907. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context
  13908. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format
  13909. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand
  13910. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase
  13911. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location
  13912. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit
  13913. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value
  13914. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context
  13915. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format
  13916. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand
  13917. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase
  13918. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location
  13919. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit
  13920. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value
  13921. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context
  13922. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format
  13923. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand
  13924. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase
  13925. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location
  13926. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit
  13927. );
  13928. }
  13929. }
  13930. // Check File "TempStopTransaction" Exist
  13931. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  13932. {
  13933. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  13934. fclose(fopen("/Storage/OCPP/TempStopTransaction", "w"));
  13935. }
  13936. else
  13937. {
  13938. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  13939. FILE *log = fopen("/Storage/OCPP/TempStopTransaction", "w+");
  13940. if(log == NULL)
  13941. {
  13942. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  13943. return ;
  13944. }
  13945. else
  13946. {
  13947. fclose(log);
  13948. }
  13949. }
  13950. //Add TempStopTransaction | Update TempStopTransaction
  13951. // open file for writing
  13952. FILE *outfile;
  13953. outfile = fopen ("/Storage/OCPP/TempStopTransaction", "a");
  13954. //DEBUG_INFO("data = %s\n", queuedata);
  13955. fputs(queuedata, outfile);
  13956. fputs("\n", outfile);
  13957. fclose (outfile);
  13958. }
  13959. void checkTempStopTransaction(int gun_index)
  13960. {
  13961. FILE *fptr1;
  13962. char ch;
  13963. char str[QUEUE_MESSAGE_LENGTH]={0};
  13964. char guid[37]={0};
  13965. char tempdata[65]={0};
  13966. char connectorStr[2]={0};
  13967. fptr1 = fopen("/Storage/OCPP/TempStopTransaction", "r");
  13968. //TempStopTransaction格式: 槍號,StopTransaction封包
  13969. if (!fptr1)
  13970. {
  13971. //printf(" File not found or unable to open the input file!!\n");
  13972. return ;
  13973. }
  13974. ch=fgetc(fptr1);
  13975. //printf(" Now the content of the file %s is : \n",fname);
  13976. rewind(fptr1);
  13977. if(ch!=EOF)
  13978. {
  13979. // copy all contents to the temporary file except the specific line
  13980. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  13981. {
  13982. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13983. if(str[0]=='\0')
  13984. {
  13985. break;
  13986. }
  13987. //TempStopTransaction格式: 槍號,StopTransaction封包
  13988. strncpy(connectorStr, str, 1);
  13989. if(atoi(connectorStr) != (gun_index+1))
  13990. {
  13991. DEBUG_INFO("atoi(connectorStr) = %d\n", atoi(connectorStr));
  13992. return ;
  13993. }
  13994. //random_uuid(guid);
  13995. strncpy(guid, str+6, 36); //copy guid
  13996. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  13997. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  13998. {
  13999. DEBUG_INFO("StopTransaction mapitem pass\n");
  14000. }
  14001. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  14002. memset(str,0,ARRAY_SIZE(str));
  14003. }
  14004. }
  14005. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  14006. fclose(fptr1);
  14007. remove("/Storage/OCPP/TempStopTransaction"); // remove the original file
  14008. }
  14009. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  14010. {
  14011. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  14012. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  14013. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  14014. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  14015. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14016. }
  14017. int GetWebSocketPingInterval(void)
  14018. {
  14019. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14020. }
  14021. int GetServerSign(void)
  14022. {
  14023. return server_sign;
  14024. }
  14025. void SetServerSign(int value)
  14026. {
  14027. server_sign = value;
  14028. }
  14029. int GetBootNotificationInterval(void)
  14030. {
  14031. return BootNotificationInterval;
  14032. }
  14033. int GetInternetConn(void)
  14034. {
  14035. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  14036. }
  14037. void InitialSystemValue(void)
  14038. {
  14039. int connectorIndex = 0;
  14040. //int valueASCII = 0;
  14041. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14042. gunTotalNumber=0;
  14043. SystemInitial = 0;
  14044. localversion=0;
  14045. BootNotificationInterval = 0;
  14046. authorizeRetryTimes = 0;
  14047. GunStatusInterval = 10;
  14048. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14049. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14050. //Hear Beat
  14051. HeartBeatWithNOResponse = 0;
  14052. HeartBeatCountPerHour = 0;
  14053. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  14054. FirstHeartBeat = 0;
  14055. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  14056. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  14057. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  14058. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  14059. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  14060. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  14061. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  14062. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  14063. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  14064. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  14065. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  14066. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  14067. memset(gunType, 0, ARRAY_SIZE(gunType));
  14068. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14069. {
  14070. //check connector / socket type (index: 8, 9, 10)
  14071. for(int index=7; index <10 ; index++)
  14072. {
  14073. if(index != 8)
  14074. {
  14075. // DC Connector
  14076. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] >= 'A') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= 'Z'))
  14077. {
  14078. SystemInitial = SystemInitial + 1;
  14079. gunTotalNumber = gunTotalNumber + 1;
  14080. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14081. connectorIndex = connectorIndex + 1;
  14082. }
  14083. }
  14084. else
  14085. {
  14086. // AC Connector
  14087. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14088. {
  14089. SystemInitial = SystemInitial + 1;
  14090. gunTotalNumber = gunTotalNumber + 1;
  14091. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14092. connectorIndex = connectorIndex + 1;
  14093. }
  14094. }
  14095. }
  14096. //DEBUG_INFO("DC ...\n");
  14097. }
  14098. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  14099. {
  14100. //check connector / socket type (index: 8, 9, 10)
  14101. for(int index=7; index <10 ; index++)
  14102. {
  14103. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14104. {
  14105. SystemInitial = SystemInitial + 1;
  14106. gunTotalNumber = gunTotalNumber + 1;
  14107. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14108. connectorIndex = connectorIndex + 1;
  14109. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  14110. }
  14111. }
  14112. }
  14113. //Status && ConnectorPlugIn Setting
  14114. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14115. {
  14116. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  14117. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  14118. }
  14119. for (int index = 0; index < CCS_QUANTITY; index++)
  14120. {
  14121. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  14122. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  14123. }
  14124. for (int index = 0; index < GB_QUANTITY; index++)
  14125. {
  14126. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  14127. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  14128. }
  14129. for (int index = 0; index < AC_QUANTITY; index++)
  14130. {
  14131. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  14132. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  14133. }
  14134. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  14135. {
  14136. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14137. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  14138. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  14139. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  14140. }
  14141. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  14142. clientTime.Heartbeat=time((time_t*)NULL);
  14143. sleep(1);
  14144. }
  14145. void LWS_Send(char * str)
  14146. {
  14147. //=====================================================
  14148. // Check InternetConn 0: disconnected, 1: connected
  14149. //====================================================
  14150. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14151. {
  14152. DEBUG_INFO("offline now !!!\n");
  14153. return;
  14154. }
  14155. pthread_mutex_lock(&lock_send);
  14156. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14157. sprintf((char *)SendBuffer, "%s", str);
  14158. SendBufLen = strlen(str);
  14159. pthread_mutex_unlock(&lock_send);
  14160. lws_callback_on_writable(wsi_client);
  14161. //lws_service(context, 0);
  14162. //sleep(1);
  14163. }