MessageHandler.c 729 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081
  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. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. //ConfigurationMaxKeys
  12. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  13. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  14. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  15. //=================================
  16. // StatusNotification cycle
  17. //=================================
  18. static int server_cycle_Status = 120;
  19. //===============================
  20. // Configuration: unknownkey
  21. //===============================
  22. static char unknownkey[10][20] = {0};
  23. static int UnknownKeynum = 0;
  24. //===============================
  25. // Gun Total Numbers
  26. //===============================
  27. static int gunTotalNumber = 0;
  28. static uint8_t gunType[4] = {0};
  29. //===============================
  30. // Local List Version
  31. //===============================
  32. static int localversion=0;
  33. static char idTagAuthorization[32] = {0};
  34. //===============================
  35. // OCPP sign variable
  36. //===============================
  37. static int server_sign = FALSE;
  38. int server_pending = FALSE;
  39. static int BootNotificationInterval = 0;
  40. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  41. //===============================
  42. // OCPP auth variable
  43. //===============================
  44. static int authorizeRetryTimes = 0; //number of Retry times
  45. //===============================
  46. // OCPP other variables
  47. //===============================
  48. static int HeartBeatWaitTime = 10;
  49. static int FirstHeartBeat = 0;
  50. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  51. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  52. static char CurrentChargingProfileScheduleStr[30] = {0};
  53. //========================================
  54. // OCPP status/previous related variables
  55. //========================================
  56. static int GunStatusInterval = 10;
  57. static uint8_t statusModeChage[CONNECTOR_QUANTITY] = {FALSE};
  58. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  59. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  60. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  61. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  62. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  63. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  64. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  65. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  66. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  67. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  68. static int TransactionMessageAttemptsValue = 0;
  69. static int TransactionMessageRetryIntervalValue = 0;
  70. static int TempMeterValueInterval = 0;
  71. static struct OCPPAuthLocalElemet
  72. {
  73. int listVersionInt;
  74. char idTagstr[20];
  75. char parentIdTag[20];
  76. char expiryDate[30];
  77. char idTagstatus[16];
  78. }idTagQuery;
  79. //=============================================
  80. // OCPP HeartBeat Response Not Receive Counts
  81. //============================================
  82. static int HeartBeatWithNOResponse = 0;
  83. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  84. extern sqlite3 *db;
  85. int TransactionMessageAttemptsGet(void);
  86. int TransactionMessageRetryIntervalGet(void);
  87. int GetOcppConnStatus(void);
  88. void SetOcppConnStatus(uint8_t status);
  89. int setKeyValue(char *key, char *value);
  90. void OCPP_get_TableAuthlocalAllData(void);
  91. void processUnkownKey(void);
  92. struct StructOCPPMeterValue
  93. {
  94. unsigned char TimeStamp[28];
  95. struct StructSampledValue SampledValue[10];
  96. };
  97. struct ClientTime
  98. {
  99. unsigned int Heartbeat;
  100. unsigned int StatusNotification[CONNECTOR_QUANTITY];
  101. unsigned int StartTransaction;
  102. unsigned int StopTransaction;
  103. unsigned int MeterValues[CONNECTOR_QUANTITY];
  104. }clientTime;
  105. typedef union
  106. {
  107. //Operations Initiated by Central System
  108. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  109. struct
  110. {
  111. //CsMsgValue[0]
  112. unsigned char StatusNotificationReq:1; //bit 0,
  113. unsigned char StatusNotificationConf:1; //bit 1,
  114. unsigned char TriggerMeterValue:1; //bit 2,
  115. unsigned char :5; //bit 5~7
  116. }bits[CONNECTOR_QUANTITY];
  117. }CpinitiateMsg;
  118. CpinitiateMsg cpinitateMsg;
  119. //GetConfiguration Array
  120. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  121. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  122. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  123. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  124. #if 0
  125. static char *ChargePointErrorCodeStr[] = {
  126. MACROSTR(ConnectorLockFailure),
  127. MACROSTR(EVCommunicationError),
  128. MACROSTR(GroundFailure),
  129. MACROSTR(HighTemperature),
  130. MACROSTR(InternalError),
  131. MACROSTR(LocalListConflict),
  132. MACROSTR(NoError),
  133. MACROSTR(OtherError),
  134. MACROSTR(OverCurrentFailure),
  135. MACROSTR(OverVoltage),
  136. MACROSTR(PowerMeterFailure),
  137. MACROSTR(PowerSwitchFailure),
  138. MACROSTR(ReaderFailure),
  139. MACROSTR(ResetFailure),
  140. MACROSTR(UnderVoltage),
  141. MACROSTR(WeakSignal)
  142. };
  143. #endif
  144. static char * ChargePointStatusStr[] = {
  145. MACROSTR(Available),
  146. MACROSTR(Preparing),
  147. MACROSTR(Charging),
  148. MACROSTR(SuspendedEVSE),
  149. MACROSTR(SuspendedEV),
  150. MACROSTR(Finishing),
  151. MACROSTR(Reserved),
  152. MACROSTR(Unavailable),
  153. MACROSTR(Faulted)
  154. };
  155. static char *RegistrationStatusStr[] = {
  156. MACROSTR(Accepted),
  157. MACROSTR(Pending),
  158. MACROSTR(Rejected)
  159. };
  160. static char *AvailabilityTypeStr[] = {
  161. MACROSTR(Inoperative),
  162. MACROSTR(Operative)
  163. };
  164. static char *AvailabilityStatusStr[] = {
  165. MACROSTR(Accepted),
  166. MACROSTR(Rejected),
  167. MACROSTR(Scheduled)
  168. };
  169. static char *ConfigurationStatusStr[] = {
  170. MACROSTR(Accepted),
  171. MACROSTR(Rejected),
  172. MACROSTR(RebootRequired),
  173. MACROSTR(NotSupported)
  174. };
  175. static char *ClearCacheStatusStr[] = {
  176. MACROSTR(Accepted),
  177. MACROSTR(Rejected)
  178. };
  179. static char *ChargingProfilePurposeTypeStr[] = {
  180. MACROSTR(ChargePointMaxProfile),
  181. MACROSTR(TxDefaultProfile),
  182. MACROSTR(TxProfile)
  183. };
  184. static char *ChargingProfileStatusStr[] = {
  185. MACROSTR(Accepted),
  186. MACROSTR(Rejected),
  187. MACROSTR(NotSupported)
  188. };
  189. static char *ClearChargingProfileStatusStr[] = {
  190. MACROSTR(Accepted),
  191. MACROSTR(Unknown)
  192. };
  193. static char *GetCompositeScheduleStatusStr[] = {
  194. MACROSTR(Accepted),
  195. MACROSTR(Rejected)
  196. };
  197. static char *UpdateTypeStr[] = {
  198. MACROSTR(Differential),
  199. MACROSTR(Full)
  200. };
  201. static char *UpdateStatusStr[] = {
  202. MACROSTR(Accepted),
  203. MACROSTR(Failed),
  204. MACROSTR(NotSupported),
  205. MACROSTR(VersionMismatch)
  206. };
  207. static char *RemoteStartStopStatusStr[] = {
  208. MACROSTR(Accepted),
  209. MACROSTR(Rejected)
  210. };
  211. static char *ReservationStatusStr[] = {
  212. MACROSTR(Accepted),
  213. MACROSTR(Faulted),
  214. MACROSTR(Occupied),
  215. MACROSTR(Rejected),
  216. MACROSTR(Unavailable)
  217. };
  218. static char *ResetTypeStr[] = {
  219. MACROSTR(Hard),
  220. MACROSTR(Soft)
  221. };
  222. static char *ResetStatusStr[] = {
  223. MACROSTR(Accepted),
  224. MACROSTR(Rejected)
  225. };
  226. static char * DiagnosticsStatusStr[] = {
  227. MACROSTR(Idle),
  228. MACROSTR(Uploaded),
  229. MACROSTR(UploadFailed),
  230. MACROSTR(Uploading)
  231. };
  232. static char * FirmwareStatusStr[] = {
  233. MACROSTR(Downloaded),
  234. MACROSTR(DownloadFailed),
  235. MACROSTR(Downloading),
  236. MACROSTR(Idle),
  237. MACROSTR(InstallationFailed),
  238. MACROSTR(Installing),
  239. MACROSTR(Installed)
  240. };
  241. static char * MessageTriggerStr[] = {
  242. MACROSTR(BootNotification),
  243. MACROSTR(DiagnosticsStatusNotification),
  244. MACROSTR(FirmwareStatusNotification),
  245. MACROSTR(Heartbeat),
  246. MACROSTR(MeterValues),
  247. MACROSTR(StatusNotification)
  248. };
  249. static char * TriggerMessageStatusStr[] = {
  250. MACROSTR(Accepted),
  251. MACROSTR(Rejected),
  252. MACROSTR(NotImplemented)
  253. };
  254. static char * UnlockStatusStr[] = {
  255. MACROSTR(Unlocked),
  256. MACROSTR(UnlockFailed),
  257. MACROSTR(NotSupported)
  258. };
  259. #if 0
  260. static char * StopTransactionReasonStr[] = {
  261. MACROSTR(EmergencyStop),
  262. MACROSTR(EVDisconnected),
  263. MACROSTR(HardReset),
  264. MACROSTR(Local),
  265. MACROSTR(Other),
  266. MACROSTR(PowerLoss),
  267. MACROSTR(Reboot),
  268. MACROSTR(Remote),
  269. MACROSTR(SoftReset),
  270. MACROSTR(UnlockCommand),
  271. MACROSTR(DeAuthorized)
  272. };
  273. #endif
  274. static char * CancelReservationStatusStr[] = {
  275. MACROSTR(Accepted),
  276. MACROSTR(Rejected)
  277. };
  278. static char * ReadingContextStr[] = {
  279. MACROSTR(Interruption.Begin),
  280. MACROSTR(Interruption.End),
  281. MACROSTR(Other),
  282. MACROSTR(Sample.Clock),
  283. MACROSTR(Sample.Periodic),
  284. MACROSTR(Transaction.Begin),
  285. MACROSTR(Transaction.End),
  286. MACROSTR(Trigger)
  287. };
  288. static char * ValueFormatStr[] = {
  289. MACROSTR(Raw),
  290. MACROSTR(SignedData)
  291. };
  292. static char * MeasurandStr[] = {
  293. MACROSTR(Current.Export),
  294. MACROSTR(Current.Import),
  295. MACROSTR(Current.Offered),
  296. MACROSTR(Energy.Active.Export.Register),
  297. MACROSTR(Energy.Active.Import.Register),
  298. MACROSTR(Energy.Reactive.Export.Register),
  299. MACROSTR(Energy.Reactive.Import.Register),
  300. MACROSTR(Energy.Active.Export.Interval),
  301. MACROSTR(Energy.Active.Import.Interval),
  302. MACROSTR(Energy.Reactive.Export.Interval),
  303. MACROSTR(Energy.Reactive.Import.Interval),
  304. MACROSTR(Frequency),
  305. MACROSTR(Power.Active.Export),
  306. MACROSTR(Power.Active.Import),
  307. MACROSTR(Power.Factor),
  308. MACROSTR(Power.Offered),
  309. MACROSTR(Power.Reactive.ExportMACROSTR),
  310. MACROSTR(Power.Reactive.Import),
  311. MACROSTR(RPM),
  312. MACROSTR(SoC),
  313. MACROSTR(Temperature),
  314. MACROSTR(Voltage)
  315. };
  316. static char * LocationStr[] = {
  317. MACROSTR(Body),
  318. MACROSTR(Cable),
  319. MACROSTR(EV),
  320. MACROSTR(Inlet),
  321. MACROSTR(Outlet)
  322. };
  323. static char * PhaseStr[] = {
  324. MACROSTR(L1),
  325. MACROSTR(L2),
  326. MACROSTR(L3),
  327. MACROSTR(N),
  328. MACROSTR(L1-N),
  329. MACROSTR(L2-N),
  330. MACROSTR(L3-N),
  331. MACROSTR(L1-L2),
  332. MACROSTR(L2-L3),
  333. MACROSTR(L3-L1)
  334. };
  335. static char * UnitOfMeasureStr[] = {
  336. MACROSTR(Wh),
  337. MACROSTR(kWh),
  338. MACROSTR(varh),
  339. MACROSTR(kvarh),
  340. MACROSTR(W),
  341. MACROSTR(kW),
  342. MACROSTR(VA),
  343. MACROSTR(kVA),
  344. MACROSTR(var),
  345. MACROSTR(kvar),
  346. MACROSTR(A),
  347. MACROSTR(V),
  348. MACROSTR(Celsius),
  349. MACROSTR(Fahrenheit),
  350. MACROSTR(K),
  351. MACROSTR(Percent)
  352. };
  353. //=========================================
  354. // Sqlite3 related function
  355. //=========================================
  356. static int selectSqlCount = 0;
  357. static int callback(void *data, int argc, char **argv, char **azColName){
  358. int i;
  359. //printf("%s: ", (const char*)data);
  360. selectSqlCount = argc;
  361. for(i = 0; i<argc; i++){
  362. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  363. }
  364. //printf("\n");
  365. return 0;
  366. }
  367. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  368. //int i;
  369. //printf("%s:\n", (const char*)data);
  370. localversion = argv[5] ? atoi(argv[5]) : 0;
  371. //printf("localversion=%d\n", localversion);
  372. return 0;
  373. }
  374. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  375. //printf("%s:\n", (const char*)data);
  376. //idTag
  377. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  378. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  379. //parentIdTag
  380. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  381. //expir_date
  382. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  383. //status
  384. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  385. //version
  386. if(columenCount > 5)
  387. idTagQuery.listVersionInt = atoi(columnValue[5]);
  388. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  389. return 0;
  390. }
  391. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  392. {
  393. // localversion = argv[5] ? atoi(argv[5]) : 0;
  394. // printf("localversion=%d\n", localversion);
  395. return 0;
  396. }
  397. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  398. {
  399. for (int i = 0; i < n_columns; i++)
  400. {
  401. DEBUG_INFO("%s\t", col_values[i]);
  402. }
  403. DEBUG_INFO("\n");
  404. return 0;
  405. }
  406. int OCPP_cleanLocalCache()
  407. {
  408. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  409. char *errMsg = 0;
  410. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  411. if (SQLITE_OK != rc)
  412. {
  413. DEBUG_INFO("SQL error: %s\n",errMsg);
  414. return FALSE;
  415. }
  416. return TRUE;
  417. }
  418. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  419. {
  420. int isSuccess = TRUE;
  421. int ret = 0;
  422. //const char* data = "Callback function called";
  423. char sql[300];
  424. char zErrMsg[200];
  425. memset(sql, 0, 300);
  426. memset(zErrMsg, 0, 200);
  427. sprintf(sql, "insert or replace into ocpp_auth_cache (idtag, parent_idtag, expir_date, status) " "VALUES ('%s', '%s', '%s', '%s'); ""SELECT * from ocpp_auth_cache", idTag, parentTage, expiryDate, status);
  428. //* Execute SQL statement */
  429. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  430. if( ret != SQLITE_OK )
  431. {
  432. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  433. isSuccess = FALSE;
  434. }
  435. return isSuccess;
  436. }
  437. void OCPP_getIdTagFromLocalCache(char idTag[])
  438. {
  439. int rc = 0;
  440. char sql[100];
  441. char zErrMsg[100];
  442. memset(sql, 0, 100);
  443. memset(zErrMsg, 0, 100);
  444. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  445. memset(&idTagQuery, 0, sizeof(idTagQuery));
  446. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  447. /* Execute SQL statement */
  448. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  449. if( rc != SQLITE_OK )
  450. {
  451. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  452. }
  453. }
  454. void OCPP_getListVerion()
  455. {
  456. int rc = 0;
  457. // const char* data = "Callback function called";
  458. char sql[100];
  459. char zErrMsg[100];
  460. memset(sql, 0, 100);
  461. memset(zErrMsg, 0, 100);
  462. strcpy(sql, "select * from ocpp_auth_local order by idx");
  463. /* Execute SQL statement */
  464. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  465. if( rc != SQLITE_OK )
  466. {
  467. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  468. }
  469. }
  470. void OCPP_get_TableAuthlocalAllData(void)
  471. {
  472. int rc = 0;
  473. char sql[100];
  474. char zErrMsg[100];
  475. memset(sql, 0, 100);
  476. memset(zErrMsg, 0, 100);
  477. sprintf(sql,"select * from ocpp_auth_local ");
  478. /* Execute SQL statement */
  479. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  480. if( rc != SQLITE_OK )
  481. {
  482. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  483. }
  484. //return ver;
  485. }
  486. int OCPP_cleanLocalList()
  487. {
  488. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  489. char *errMsg = 0;
  490. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  491. if (SQLITE_OK != rc)
  492. {
  493. DEBUG_INFO("%s\n",errMsg);
  494. return FALSE;
  495. }
  496. return TRUE;
  497. }
  498. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  499. {
  500. int isSuccess = FALSE;
  501. int ret = 0;
  502. //const char* data = "Callback function called";
  503. char sql[300];
  504. char zErrMsg[200];
  505. memset(sql, 0, 300);
  506. memset(zErrMsg, 0, 200);
  507. 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);
  508. //* Execute SQL statement */
  509. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  510. if( ret != SQLITE_OK )
  511. {
  512. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  513. return isSuccess;
  514. }
  515. memset(sql, 0, 300);
  516. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  517. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  518. if( ret != SQLITE_OK )
  519. {
  520. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  521. return isSuccess;
  522. }
  523. isSuccess = TRUE;
  524. return isSuccess;
  525. }
  526. void OCPP_getIdTagFromLocalList(char idTag[])
  527. {
  528. int rc = 0;
  529. // const char* data = "Callback function called";
  530. char sql[100];
  531. char zErrMsg[100];
  532. memset(sql, 0, 100);
  533. memset(zErrMsg, 0, 100);
  534. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  535. memset(&idTagQuery, 0, sizeof(idTagQuery));
  536. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  537. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  538. /* Execute SQL statement */
  539. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  540. if( rc != SQLITE_OK )
  541. {
  542. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  543. }
  544. //return ver;
  545. }
  546. void OCPP_deleteIdTagFromLocalList(char idTag[])
  547. {
  548. //int ver = 0;
  549. //int isSuccess = FALSE;
  550. int rc = 0;
  551. char sql[100];
  552. char zErrMsg[100];
  553. memset(sql, 0, 100);
  554. memset(zErrMsg, 0, 100);
  555. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  556. //* Execute SQL statement */
  557. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  558. if( rc != SQLITE_OK )
  559. {
  560. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  561. }
  562. }
  563. int getCurrentYear()
  564. {
  565. int result = 0;
  566. time_t CurrentTime;
  567. struct tm *tm;
  568. CurrentTime = time(NULL);
  569. tm=localtime(&CurrentTime);
  570. result = (tm->tm_year + 1900);
  571. return result;
  572. }
  573. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  574. {
  575. int result = PASS;
  576. char* errMsg = NULL;
  577. char sqlStr[8192];
  578. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  579. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  580. {
  581. result = FAIL;
  582. DEBUG_INFO( "Insert local transaction record error message: %s\n", errMsg);
  583. }
  584. sprintf(sqlStr, "delete from ocpp_transaction_record where (idx < (select idx from ocpp_transaction_record order by idx desc limit 1)-2000) and (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  585. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  586. {
  587. result = FAIL;
  588. DEBUG_INFO( "delete local transaction record error message: %s\n", errMsg);
  589. }
  590. return result;
  591. }
  592. //==========================================
  593. // Check time passed since today
  594. //==========================================
  595. long long DiffTimebWithNow(struct timeb ST)
  596. {
  597. //return milli-second
  598. struct timeb ET;
  599. long long StartTime,StopTime;
  600. ftime(&ET);
  601. StartTime=(long long)ST.time;
  602. StopTime=(long long)ET.time;
  603. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  604. }
  605. int getTimePassSinceToday()
  606. {
  607. int result = -1;
  608. static time_t lastTime;
  609. time_t t;
  610. struct tm *tmStartToday;
  611. struct timeb tbStartToday;
  612. t=time(NULL);
  613. if(difftime(t, lastTime)>0)
  614. {
  615. tmStartToday=localtime(&t);
  616. tmStartToday->tm_hour = 0;
  617. tmStartToday->tm_min = 0;
  618. tmStartToday->tm_sec = 0;
  619. tbStartToday.time = mktime(tmStartToday);
  620. tbStartToday.millitm = 0;
  621. result = DiffTimebWithNow(tbStartToday)/1000;
  622. lastTime = t;
  623. }
  624. return result;
  625. }
  626. void getNowDatetime(uint8_t *data)
  627. {
  628. time_t t = time(NULL);
  629. struct tm tm = *localtime(&t);
  630. sprintf((char*)data, "%04d-%02d-%02dT%02d:%02d:%02dZ", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
  631. }
  632. //==========================================
  633. // GetCompositeSchedule logic related function
  634. //==========================================
  635. int DiffTimebSec(struct timeb ST, struct timeb ET)
  636. {
  637. //return milli-second
  638. unsigned int StartTime,StopTime;
  639. StartTime=(unsigned int)ST.time;
  640. StopTime=(unsigned int)ET.time;
  641. return (StopTime-StartTime);
  642. }
  643. int DiffTimebWithNowSec(struct timeb ST)
  644. {
  645. //return milli-second
  646. struct timeb ET;
  647. unsigned int StartTime,StopTime;
  648. ftime(&ET);
  649. StartTime=(unsigned int)ST.time;
  650. StopTime=(unsigned int)ET.time;
  651. return (StopTime-StartTime);
  652. }
  653. int getStartStop(uint8_t *start, uint8_t *stop)
  654. {
  655. int result = -1;
  656. struct tm tmStart;
  657. struct timeb tbStart;
  658. struct tm tmStop;
  659. struct timeb tbStop;
  660. 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) &&
  661. (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))
  662. {
  663. //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);
  664. //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);
  665. tmStart.tm_year -= 1900;
  666. tmStart.tm_mon -= 1;
  667. tbStart.time = mktime(&tmStart);
  668. tbStart.millitm = 0;
  669. tmStop.tm_year -= 1900;
  670. tmStop.tm_mon -= 1;
  671. tbStop.time = mktime(&tmStop);
  672. tbStop.millitm = 0;
  673. result = DiffTimebSec(tbStart, tbStop);
  674. //DEBUG_INFO("getStartStop(): %d\n", result);
  675. }
  676. else
  677. {
  678. DEBUG_WARN("Start or stop date parsing error.\r\n");
  679. }
  680. return result;
  681. }
  682. int isOvertNow(uint8_t *start)
  683. {
  684. int result = NO;
  685. struct tm tmStart;
  686. struct timeb tbStart;
  687. 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))
  688. {
  689. //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);
  690. tmStart.tm_year -= 1900;
  691. tmStart.tm_mon -= 1;
  692. tbStart.time = mktime(&tmStart);
  693. tbStart.millitm = 0;
  694. if(DiffTimebWithNowSec(tbStart) <= 0)
  695. result = NO;
  696. else
  697. result = YES;
  698. }
  699. else
  700. {
  701. DEBUG_WARN("Start date parsing error.\n");
  702. }
  703. return result;
  704. }
  705. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  706. {
  707. int result = -1;
  708. struct tm tmStart;
  709. struct timeb tbStart;
  710. struct tm tmStop;
  711. struct timeb tbStop;
  712. 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) &&
  713. (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))
  714. {
  715. tmStart.tm_year -= 1900;
  716. tmStart.tm_mon -= 1;
  717. tbStart.time = mktime(&tmStart);
  718. tbStart.millitm = 0;
  719. tmStop.tm_year -= 1900;
  720. tmStop.tm_mon -= 1;
  721. tbStop.time = mktime(&tmStop);
  722. tbStop.millitm = 0;
  723. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  724. }
  725. return result;
  726. }
  727. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  728. {
  729. FILE *fp;
  730. char profileFileName[128];
  731. char *line = NULL;
  732. size_t len = 0;
  733. time_t CurrentTime;
  734. struct tm *tmComposite;
  735. struct StructChargingProfile maxProfile;
  736. struct StructChargingProfile defaultTxProfile;
  737. struct StructChargingProfile txProfile;
  738. struct StructChargingSchedulePeriod tmpPeriod;
  739. uint8_t limitMax=0;
  740. uint8_t limitDef=0;
  741. uint8_t limitTx=0;
  742. int compositePeriodIdx = 0;
  743. CurrentTime = time(NULL);
  744. tmComposite=localtime(&CurrentTime);
  745. 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);
  746. if(isUnitA)
  747. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  748. else
  749. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  750. compositeProfile->ChargingSchedule.Duration = durationReq;
  751. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  752. {
  753. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  754. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  755. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  756. }
  757. compositeProfile->ChargingProfileId = 0;
  758. compositeProfile->StackLevel = 99 ;
  759. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  760. maxProfile.ChargingProfileId = -1;
  761. defaultTxProfile.ChargingProfileId = -1;
  762. txProfile.ChargingProfileId = -1;
  763. maxProfile.ChargingSchedule.Duration = -1;
  764. defaultTxProfile.ChargingSchedule.Duration = -1;
  765. txProfile.ChargingSchedule.Duration = -1;
  766. system("yes|rm /tmp/*.json");
  767. system("cp /Storage/OCPP/*.json /tmp");
  768. /*
  769. * Search valid charging profile
  770. */
  771. //DEBUG_INFO("====================================\n");
  772. // Search tx profile
  773. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  774. if((access(profileFileName, F_OK))!=-1)
  775. {
  776. fp = fopen(profileFileName, "r");
  777. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  778. {
  779. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  780. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  781. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  782. }
  783. txProfile.ChargingProfileId = -1;
  784. txProfile.StackLevel = -1;
  785. while(getline(&line, &len, fp) != -1)
  786. {
  787. json_object *obj = NULL;
  788. obj = json_tokener_parse(line);
  789. if(is_error(obj))
  790. {
  791. DEBUG_ERROR("Parse txProfile from file error.\n");
  792. }
  793. else
  794. {
  795. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  796. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  797. )
  798. {
  799. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  800. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  801. )
  802. {
  803. struct tm tmFrom, tmTo;
  804. struct timeb tbFrom, tbTo;
  805. 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) &&
  806. (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))
  807. {
  808. tmFrom.tm_year -= 1900;
  809. tmFrom.tm_mon -= 1;
  810. tbFrom.time = mktime(&tmFrom);
  811. tmTo.tm_year -= 1900;
  812. tmTo.tm_mon -= 1;
  813. tbTo.time = mktime(&tmTo);
  814. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  815. {
  816. if(txProfile.ChargingProfileId == -1)
  817. DEBUG_INFO("TxProfile found.\n");
  818. else
  819. DEBUG_INFO("TxProfile updated.\n");
  820. // Required item
  821. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  822. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  823. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  824. if(isUnitA)
  825. {
  826. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  827. 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++)
  828. {
  829. 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"));
  830. 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?
  831. 3:
  832. 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")));
  833. 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*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):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")));
  834. }
  835. }
  836. else
  837. {
  838. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  839. 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++)
  840. {
  841. 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"));
  842. 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?
  843. 3:
  844. 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")));
  845. 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")):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*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  846. }
  847. }
  848. // Optional item
  849. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  850. {
  851. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  852. }
  853. else
  854. {
  855. sprintf((char*)txProfile.ValidFrom, " ");
  856. }
  857. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  858. {
  859. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  860. }
  861. else
  862. {
  863. sprintf((char*)txProfile.ValidTo, " ");
  864. }
  865. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  866. {
  867. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  868. }
  869. else
  870. {
  871. sprintf((char*)txProfile.RecurrencyKind, " ");
  872. }
  873. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  874. {
  875. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  876. }
  877. else
  878. {
  879. txProfile.TransactionId = -1;
  880. }
  881. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  882. {
  883. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  884. }
  885. else
  886. {
  887. txProfile.ChargingSchedule.Duration = 86400;
  888. }
  889. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  890. {
  891. 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")));
  892. }
  893. else
  894. {
  895. 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));
  896. }
  897. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  898. {
  899. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  900. }
  901. else
  902. {
  903. txProfile.ChargingSchedule.MinChargingRate = -1;
  904. }
  905. }
  906. }
  907. }
  908. else
  909. {
  910. if(txProfile.ChargingProfileId == -1)
  911. DEBUG_INFO("TxProfile found.\n");
  912. else
  913. DEBUG_INFO("TxProfile updated.\n");
  914. // Required item
  915. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  916. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  917. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  918. if(isUnitA)
  919. {
  920. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  921. 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++)
  922. {
  923. 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"));
  924. 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?
  925. 3:
  926. 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")));
  927. 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*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):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")));
  928. }
  929. }
  930. else
  931. {
  932. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  933. 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++)
  934. {
  935. 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"));
  936. 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?
  937. 3:
  938. 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")));
  939. 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")):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*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  940. }
  941. }
  942. // Optional item
  943. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  944. {
  945. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  946. }
  947. else
  948. {
  949. sprintf((char*)txProfile.ValidFrom, " ");
  950. }
  951. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  952. {
  953. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  954. }
  955. else
  956. {
  957. sprintf((char*)txProfile.ValidTo, " ");
  958. }
  959. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  960. {
  961. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  962. }
  963. else
  964. {
  965. sprintf((char*)txProfile.RecurrencyKind, " ");
  966. }
  967. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  968. {
  969. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  970. }
  971. else
  972. {
  973. txProfile.TransactionId = -1;
  974. }
  975. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  976. {
  977. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  978. }
  979. else
  980. {
  981. txProfile.ChargingSchedule.Duration = 86400;
  982. }
  983. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  984. {
  985. 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")));
  986. }
  987. else
  988. {
  989. 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));
  990. }
  991. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  992. {
  993. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  994. }
  995. else
  996. {
  997. txProfile.ChargingSchedule.MinChargingRate = -1;
  998. }
  999. }
  1000. }
  1001. }
  1002. json_object_put(obj);
  1003. }
  1004. fclose(fp);
  1005. /*
  1006. if(txProfile.ChargingProfileId != -1)
  1007. {
  1008. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1009. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1010. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1011. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1012. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1013. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1014. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1015. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1016. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1017. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1018. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1019. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1020. {
  1021. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1022. {
  1023. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1024. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1025. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1026. }
  1027. }
  1028. }
  1029. else
  1030. DEBUG_INFO("TxProfile not found.\n");*/
  1031. }
  1032. // Search default tx profile
  1033. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1034. if((access(profileFileName, F_OK))==-1)
  1035. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1036. if((access(profileFileName, F_OK))!=-1)
  1037. {
  1038. fp = fopen(profileFileName, "r");
  1039. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1040. {
  1041. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1042. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1043. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1044. }
  1045. defaultTxProfile.ChargingProfileId = -1;
  1046. defaultTxProfile.StackLevel = -1;
  1047. while(getline(&line, &len, fp) != -1)
  1048. {
  1049. json_object *obj = NULL;
  1050. obj = json_tokener_parse(line);
  1051. if(is_error(obj))
  1052. {
  1053. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1054. }
  1055. else
  1056. {
  1057. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1058. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1059. )
  1060. {
  1061. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1062. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1063. )
  1064. {
  1065. struct tm tmFrom, tmTo;
  1066. struct timeb tbFrom, tbTo;
  1067. 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) &&
  1068. (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))
  1069. {
  1070. tmFrom.tm_year -= 1900;
  1071. tmFrom.tm_mon -= 1;
  1072. tbFrom.time = mktime(&tmFrom);
  1073. tmTo.tm_year -= 1900;
  1074. tmTo.tm_mon -= 1;
  1075. tbTo.time = mktime(&tmTo);
  1076. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1077. {
  1078. if(defaultTxProfile.ChargingProfileId == -1)
  1079. DEBUG_INFO("TxDefaultProfile found.\n");
  1080. else
  1081. DEBUG_INFO("TxDefaultProfile updated.\n");
  1082. // Required item
  1083. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1084. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1085. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1086. if(isUnitA)
  1087. {
  1088. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1089. 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++)
  1090. {
  1091. 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"));
  1092. 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?
  1093. 3:
  1094. 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")));
  1095. 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*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):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")));
  1096. }
  1097. }
  1098. else
  1099. {
  1100. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1101. 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++)
  1102. {
  1103. 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"));
  1104. 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?
  1105. 3:
  1106. 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")));
  1107. 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")):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*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1108. }
  1109. }
  1110. // Optional item
  1111. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1112. {
  1113. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1114. }
  1115. else
  1116. {
  1117. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1118. }
  1119. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1120. {
  1121. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1122. }
  1123. else
  1124. {
  1125. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1126. }
  1127. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1128. {
  1129. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1130. }
  1131. else
  1132. {
  1133. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1134. }
  1135. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1136. {
  1137. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1138. }
  1139. else
  1140. {
  1141. defaultTxProfile.TransactionId = -1;
  1142. }
  1143. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1144. {
  1145. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1146. }
  1147. else
  1148. {
  1149. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1150. }
  1151. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1152. {
  1153. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1154. }
  1155. else
  1156. {
  1157. sprintf((char*)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));
  1158. }
  1159. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1160. {
  1161. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1162. }
  1163. else
  1164. {
  1165. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1166. }
  1167. }
  1168. }
  1169. }
  1170. else
  1171. {
  1172. if(defaultTxProfile.ChargingProfileId == -1)
  1173. DEBUG_INFO("TxDefaultProfile found.\n");
  1174. else
  1175. DEBUG_INFO("TxDefaultProfile updated.\n");
  1176. // Required item
  1177. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1178. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1179. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1180. if(isUnitA)
  1181. {
  1182. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1183. 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++)
  1184. {
  1185. 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"));
  1186. 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?
  1187. 3:
  1188. 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")));
  1189. 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*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):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")));
  1190. }
  1191. }
  1192. else
  1193. {
  1194. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1195. 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++)
  1196. {
  1197. 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"));
  1198. 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?
  1199. 3:
  1200. 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")));
  1201. 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")):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*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1202. }
  1203. }
  1204. // Optional item
  1205. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1206. {
  1207. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1208. }
  1209. else
  1210. {
  1211. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1212. }
  1213. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1214. {
  1215. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1216. }
  1217. else
  1218. {
  1219. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1220. }
  1221. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1222. {
  1223. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1224. }
  1225. else
  1226. {
  1227. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1228. }
  1229. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1230. {
  1231. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1232. }
  1233. else
  1234. {
  1235. defaultTxProfile.TransactionId = -1;
  1236. }
  1237. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1238. {
  1239. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1240. }
  1241. else
  1242. {
  1243. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1244. }
  1245. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1246. {
  1247. 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")));
  1248. }
  1249. else
  1250. {
  1251. 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));
  1252. }
  1253. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1254. {
  1255. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1256. }
  1257. else
  1258. {
  1259. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1260. }
  1261. }
  1262. }
  1263. }
  1264. json_object_put(obj);
  1265. }
  1266. fclose(fp);
  1267. /*
  1268. if(defaultTxProfile.ChargingProfileId != -1)
  1269. {
  1270. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1271. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1272. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1273. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1274. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1275. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1276. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1277. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  1278. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1279. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1280. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1281. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1282. {
  1283. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1284. {
  1285. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1286. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1287. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1288. }
  1289. }
  1290. }
  1291. else
  1292. DEBUG_INFO("TxDefaultProfile not found.\n");
  1293. DEBUG_INFO("------------------------------------\n");*/
  1294. }
  1295. // Search max profile
  1296. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1297. if((access(profileFileName, F_OK))!=-1)
  1298. {
  1299. fp = fopen(profileFileName, "r");
  1300. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1301. {
  1302. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1303. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1304. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1305. }
  1306. maxProfile.ChargingProfileId = -1;
  1307. maxProfile.StackLevel = -1;
  1308. while(getline(&line, &len, fp) != -1)
  1309. {
  1310. json_object *obj = NULL;
  1311. obj = json_tokener_parse(line);
  1312. if(is_error(obj))
  1313. {
  1314. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1315. }
  1316. else
  1317. {
  1318. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1319. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1320. )
  1321. {
  1322. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1323. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1324. )
  1325. {
  1326. struct tm tmFrom, tmTo;
  1327. struct timeb tbFrom, tbTo;
  1328. 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) &&
  1329. (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))
  1330. {
  1331. tmFrom.tm_year -= 1900;
  1332. tmFrom.tm_mon -= 1;
  1333. tbFrom.time = mktime(&tmFrom);
  1334. tmTo.tm_year -= 1900;
  1335. tmTo.tm_mon -= 1;
  1336. tbTo.time = mktime(&tmTo);
  1337. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1338. {
  1339. if(maxProfile.ChargingProfileId == -1)
  1340. DEBUG_INFO("MaxProfile found.\n");
  1341. else
  1342. DEBUG_INFO("MaxProfile updated.\n");
  1343. // Required item
  1344. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1345. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1346. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1347. if(isUnitA)
  1348. {
  1349. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1350. 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++)
  1351. {
  1352. 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"));
  1353. 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?
  1354. 3:
  1355. 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")));
  1356. 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*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):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")));
  1357. }
  1358. }
  1359. else
  1360. {
  1361. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1362. 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++)
  1363. {
  1364. 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"));
  1365. 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?
  1366. 3:
  1367. 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")));
  1368. 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")):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*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1369. }
  1370. }
  1371. // Optional item
  1372. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1373. {
  1374. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1375. }
  1376. else
  1377. {
  1378. sprintf((char*)maxProfile.ValidFrom, " ");
  1379. }
  1380. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1381. {
  1382. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1383. }
  1384. else
  1385. {
  1386. sprintf((char*)maxProfile.ValidTo, " ");
  1387. }
  1388. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1389. {
  1390. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1391. }
  1392. else
  1393. {
  1394. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1395. }
  1396. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1397. {
  1398. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1399. }
  1400. else
  1401. {
  1402. maxProfile.TransactionId = -1;
  1403. }
  1404. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1405. {
  1406. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1407. }
  1408. else
  1409. {
  1410. maxProfile.ChargingSchedule.Duration = 86400;
  1411. }
  1412. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1413. {
  1414. 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")));
  1415. }
  1416. else
  1417. {
  1418. 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));
  1419. }
  1420. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1421. {
  1422. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1423. }
  1424. else
  1425. {
  1426. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1427. }
  1428. }
  1429. }
  1430. }
  1431. else
  1432. {
  1433. if(maxProfile.ChargingProfileId == -1)
  1434. DEBUG_INFO("MaxProfile found.\n");
  1435. else
  1436. DEBUG_INFO("MaxProfile updated.\n");
  1437. // Required item
  1438. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1439. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1440. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1441. if(isUnitA)
  1442. {
  1443. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1444. 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++)
  1445. {
  1446. 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"));
  1447. 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?
  1448. 3:
  1449. 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")));
  1450. 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*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):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")));
  1451. }
  1452. }
  1453. else
  1454. {
  1455. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1456. 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++)
  1457. {
  1458. 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"));
  1459. 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?
  1460. 3:
  1461. 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")));
  1462. 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")):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*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  1463. }
  1464. }
  1465. // Optional item
  1466. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1467. {
  1468. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1469. }
  1470. else
  1471. {
  1472. sprintf((char*)maxProfile.ValidFrom, " ");
  1473. }
  1474. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1475. {
  1476. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1477. }
  1478. else
  1479. {
  1480. sprintf((char*)maxProfile.ValidTo, " ");
  1481. }
  1482. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1483. {
  1484. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1485. }
  1486. else
  1487. {
  1488. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1489. }
  1490. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1491. {
  1492. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1493. }
  1494. else
  1495. {
  1496. maxProfile.TransactionId = -1;
  1497. }
  1498. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1499. {
  1500. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1501. }
  1502. else
  1503. {
  1504. maxProfile.ChargingSchedule.Duration = 86400;
  1505. }
  1506. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1507. {
  1508. 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")));
  1509. }
  1510. else
  1511. {
  1512. 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));
  1513. }
  1514. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1515. {
  1516. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1517. }
  1518. else
  1519. {
  1520. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1521. }
  1522. }
  1523. }
  1524. }
  1525. json_object_put(obj);
  1526. }
  1527. fclose(fp);
  1528. /*
  1529. if(maxProfile.ChargingProfileId !=-1)
  1530. {
  1531. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1532. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1533. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1534. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1535. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1536. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1537. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1538. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1539. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1540. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1541. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1542. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1543. {
  1544. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1545. {
  1546. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1547. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1548. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1549. }
  1550. }
  1551. }
  1552. else
  1553. DEBUG_INFO("MaxProfile not found.\n");
  1554. DEBUG_INFO("------------------------------------\n");*/
  1555. }
  1556. /*
  1557. * Align found profile start schedule & periods
  1558. */
  1559. //DEBUG_INFO("====================================\n");
  1560. /*
  1561. // For local test usage, force modify found profile start schedule info
  1562. 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);
  1563. 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);
  1564. 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);
  1565. */
  1566. if(txProfile.ChargingProfileId != -1)
  1567. {
  1568. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1569. {
  1570. if(txProfile.ChargingSchedule.Duration != -1)
  1571. {
  1572. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1573. 0:
  1574. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1575. }
  1576. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1577. {
  1578. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1579. {
  1580. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1581. 0:
  1582. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1583. if(idxPeriod > 0)
  1584. {
  1585. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1586. {
  1587. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1588. }
  1589. }
  1590. }
  1591. }
  1592. }
  1593. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1594. {
  1595. if(txProfile.ChargingSchedule.Duration != -1)
  1596. {
  1597. 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?
  1598. 0:
  1599. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1600. }
  1601. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1602. {
  1603. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1604. {
  1605. 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?
  1606. 0:
  1607. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1608. if(idxPeriod > 0)
  1609. {
  1610. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1611. {
  1612. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1613. }
  1614. }
  1615. }
  1616. }
  1617. }
  1618. else
  1619. {
  1620. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1621. {
  1622. if(txProfile.ChargingSchedule.Duration != -1)
  1623. {
  1624. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1625. 0:
  1626. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1627. }
  1628. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1629. {
  1630. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1631. {
  1632. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1633. 0:
  1634. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1635. if(idxPeriod > 0)
  1636. {
  1637. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1638. {
  1639. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1640. }
  1641. }
  1642. }
  1643. }
  1644. }
  1645. else
  1646. {
  1647. if(txProfile.ChargingSchedule.Duration != -1)
  1648. {
  1649. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1650. 0:
  1651. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1652. }
  1653. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1654. {
  1655. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1656. {
  1657. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1658. 0:
  1659. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1660. if(idxPeriod > 0)
  1661. {
  1662. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1663. {
  1664. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1665. }
  1666. }
  1667. }
  1668. }
  1669. }
  1670. }
  1671. /*
  1672. DEBUG_INFO("txProfile after align.\n");
  1673. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1674. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1675. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1676. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1677. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1678. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1679. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1680. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1681. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1682. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1683. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1684. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1685. {
  1686. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1687. {
  1688. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1689. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1690. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1691. }
  1692. }*/
  1693. }
  1694. if(defaultTxProfile.ChargingProfileId != -1)
  1695. {
  1696. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1697. {
  1698. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1699. {
  1700. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1701. 0:
  1702. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1703. }
  1704. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1705. {
  1706. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1707. {
  1708. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1709. 0:
  1710. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1711. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1712. {
  1713. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1714. }
  1715. if(idxPeriod > 0)
  1716. {
  1717. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1718. {
  1719. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1720. }
  1721. }
  1722. }
  1723. }
  1724. }
  1725. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1726. {
  1727. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1728. {
  1729. 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?
  1730. 0:
  1731. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1732. }
  1733. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1734. {
  1735. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1736. {
  1737. 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?
  1738. 0:
  1739. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1740. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1741. {
  1742. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1743. }
  1744. if(idxPeriod > 0)
  1745. {
  1746. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1747. {
  1748. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1749. }
  1750. }
  1751. }
  1752. }
  1753. }
  1754. else
  1755. {
  1756. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1757. {
  1758. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1759. {
  1760. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1761. 0:
  1762. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1763. }
  1764. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1765. {
  1766. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1767. {
  1768. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1769. 0:
  1770. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1771. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1772. {
  1773. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1774. }
  1775. if(idxPeriod > 0)
  1776. {
  1777. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1778. {
  1779. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1780. }
  1781. }
  1782. }
  1783. }
  1784. }
  1785. else
  1786. {
  1787. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1788. {
  1789. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1790. 0:
  1791. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1792. }
  1793. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1794. {
  1795. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1796. {
  1797. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1798. 0:
  1799. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1800. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1801. {
  1802. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1803. }
  1804. if(idxPeriod > 0)
  1805. {
  1806. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1807. {
  1808. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1809. }
  1810. }
  1811. }
  1812. }
  1813. }
  1814. }
  1815. /*
  1816. DEBUG_INFO("defaultTxProfile after align.\n");
  1817. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1818. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1819. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1820. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1821. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1822. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1823. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1824. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1825. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1826. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1827. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1828. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1829. {
  1830. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1831. {
  1832. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1833. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1834. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1835. }
  1836. }
  1837. DEBUG_INFO("------------------------------------\n");*/
  1838. }
  1839. if(maxProfile.ChargingProfileId != -1)
  1840. {
  1841. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1842. {
  1843. if(maxProfile.ChargingSchedule.Duration != -1)
  1844. {
  1845. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1846. 0:
  1847. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1848. }
  1849. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1850. {
  1851. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1852. {
  1853. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1854. 0:
  1855. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1856. if(idxPeriod > 0)
  1857. {
  1858. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1859. {
  1860. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1861. }
  1862. }
  1863. }
  1864. }
  1865. }
  1866. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1867. {
  1868. if(maxProfile.ChargingSchedule.Duration != -1)
  1869. {
  1870. 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?
  1871. 0:
  1872. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1873. }
  1874. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1875. {
  1876. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1877. {
  1878. 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?
  1879. 0:
  1880. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1881. if(idxPeriod > 0)
  1882. {
  1883. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1884. {
  1885. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1886. }
  1887. }
  1888. }
  1889. }
  1890. }
  1891. else
  1892. {
  1893. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1894. {
  1895. if(maxProfile.ChargingSchedule.Duration != -1)
  1896. {
  1897. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1898. 0:
  1899. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1900. }
  1901. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1902. {
  1903. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1904. {
  1905. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1906. 0:
  1907. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1908. if(idxPeriod > 0)
  1909. {
  1910. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1911. {
  1912. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1913. }
  1914. }
  1915. }
  1916. }
  1917. }
  1918. else
  1919. {
  1920. if(maxProfile.ChargingSchedule.Duration != -1)
  1921. {
  1922. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1923. 0:
  1924. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1925. }
  1926. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1927. {
  1928. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1929. {
  1930. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1931. 0:
  1932. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1933. if(idxPeriod > 0)
  1934. {
  1935. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1936. {
  1937. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1938. }
  1939. }
  1940. }
  1941. }
  1942. }
  1943. }
  1944. /*
  1945. DEBUG_INFO("MaxProfile after align.\n");
  1946. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1947. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1948. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1949. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1950. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1951. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1952. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1953. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1954. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1955. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1956. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1957. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1958. {
  1959. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1960. {
  1961. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1962. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1963. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1964. }
  1965. }
  1966. DEBUG_INFO("------------------------------------\n");*/
  1967. }
  1968. /*
  1969. * Merge to conposite schedule
  1970. */
  1971. //DEBUG_INFO("====================================\n");
  1972. // Find each profile period quantity
  1973. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1974. {
  1975. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1976. limitMax = idx+1;
  1977. }
  1978. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1979. {
  1980. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1981. limitDef = idx+1;
  1982. }
  1983. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1984. {
  1985. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1986. limitTx = idx+1;
  1987. }
  1988. // TxProfile found, composite schedule based on it
  1989. if(txProfile.ChargingProfileId != -1)
  1990. {
  1991. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  1992. {
  1993. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  1994. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  1995. (txProfile.ChargingSchedule.Duration > 0))
  1996. {
  1997. if(maxProfile.ChargingProfileId != -1)
  1998. {
  1999. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2000. {
  2001. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2002. {
  2003. if((maxProfile.ChargingSchedule.Duration > 0))
  2004. {
  2005. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2006. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2007. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2008. }
  2009. else
  2010. {
  2011. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2012. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2013. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2014. }
  2015. }
  2016. if(idxMaxPeriod == (limitMax-1))
  2017. {
  2018. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2019. {
  2020. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2021. {
  2022. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2023. compositePeriodIdx++;
  2024. }
  2025. else
  2026. {
  2027. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2028. }
  2029. }
  2030. }
  2031. }
  2032. }
  2033. else
  2034. {
  2035. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2036. {
  2037. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2038. compositePeriodIdx++;
  2039. }
  2040. else
  2041. {
  2042. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2043. }
  2044. }
  2045. }
  2046. if(idxTxPeriod == (limitTx-1))
  2047. {
  2048. if(defaultTxProfile.ChargingProfileId != -1)
  2049. {
  2050. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2051. {
  2052. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  2053. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2054. (defaultTxProfile.ChargingSchedule.Duration>0))
  2055. {
  2056. if(maxProfile.ChargingProfileId != -1)
  2057. {
  2058. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2059. {
  2060. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2061. {
  2062. if((maxProfile.ChargingSchedule.Duration > 0))
  2063. {
  2064. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2065. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2066. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2067. }
  2068. else
  2069. {
  2070. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2071. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2072. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2073. }
  2074. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2075. {
  2076. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2077. {
  2078. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2079. compositePeriodIdx++;
  2080. }
  2081. else
  2082. {
  2083. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2084. }
  2085. }
  2086. break;
  2087. }
  2088. }
  2089. }
  2090. else
  2091. {
  2092. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2093. {
  2094. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2095. compositePeriodIdx++;
  2096. }
  2097. else
  2098. {
  2099. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2100. }
  2101. }
  2102. }
  2103. }
  2104. }
  2105. }
  2106. }
  2107. }
  2108. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2109. else if(defaultTxProfile.ChargingProfileId != -1)
  2110. {
  2111. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2112. {
  2113. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2114. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2115. (defaultTxProfile.ChargingSchedule.Duration > 0))
  2116. {
  2117. if(maxProfile.ChargingProfileId != -1)
  2118. {
  2119. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2120. {
  2121. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2122. {
  2123. if((maxProfile.ChargingSchedule.Duration > 0))
  2124. {
  2125. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2126. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2127. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  2128. }
  2129. else
  2130. {
  2131. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2132. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2133. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2134. }
  2135. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2136. {
  2137. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2138. {
  2139. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2140. compositePeriodIdx++;
  2141. }
  2142. else
  2143. {
  2144. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2145. }
  2146. }
  2147. break;
  2148. }
  2149. }
  2150. }
  2151. else
  2152. {
  2153. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2154. {
  2155. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2156. compositePeriodIdx++;
  2157. }
  2158. else
  2159. {
  2160. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2161. }
  2162. }
  2163. }
  2164. }
  2165. }
  2166. // Fill other period by MaxProfile
  2167. if(maxProfile.ChargingProfileId != -1)
  2168. {
  2169. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2170. {
  2171. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2172. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2173. (maxProfile.ChargingSchedule.Duration > 0))
  2174. {
  2175. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  2176. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2177. {
  2178. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  2179. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  2180. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2181. }
  2182. if((maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2183. {
  2184. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.Duration;
  2185. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  2186. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2187. }
  2188. if(tmpPeriod.Limit != -1)
  2189. {
  2190. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2191. {
  2192. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2193. {
  2194. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2195. compositePeriodIdx++;
  2196. }
  2197. else
  2198. {
  2199. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2200. }
  2201. }
  2202. }
  2203. }
  2204. }
  2205. }
  2206. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  2207. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2208. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  2209. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  2210. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2211. {
  2212. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2213. {
  2214. compositeProfile->ChargingProfileId = 1;
  2215. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2216. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2217. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2218. }
  2219. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2220. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2221. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2222. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2223. }
  2224. if(line)
  2225. free(line);
  2226. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  2227. }
  2228. //==========================================
  2229. // Init all share memory
  2230. //==========================================
  2231. int InitShareMemory()
  2232. {
  2233. int result = PASS;
  2234. int MeterSMId;
  2235. //creat ShmSysConfigAndInfo
  2236. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  2237. {
  2238. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  2239. result = FAIL;
  2240. }
  2241. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2242. {
  2243. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  2244. result = FAIL;
  2245. }
  2246. else
  2247. {}
  2248. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  2249. {
  2250. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  2251. result = FAIL;
  2252. }
  2253. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2254. {
  2255. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  2256. result = FAIL;
  2257. }
  2258. else
  2259. {}
  2260. //creat ShmPsuData
  2261. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  2262. {
  2263. DEBUG_ERROR("shmget ShmPsuData NG\n");
  2264. result = FAIL;
  2265. }
  2266. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2267. {
  2268. DEBUG_ERROR("shmat ShmPsuData NG\n");
  2269. result = FAIL;
  2270. }
  2271. else
  2272. {}
  2273. //creat ShmOCPP16Data
  2274. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  2275. {
  2276. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  2277. result = FAIL;
  2278. }
  2279. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2280. {
  2281. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  2282. result = FAIL;
  2283. }
  2284. else
  2285. {}
  2286. /****************************** For Initial Settings************************************************/
  2287. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  2288. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  2289. // allocate Configuration memory address
  2290. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  2291. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  2292. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  2293. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  2294. //offline MeterValue Interval
  2295. TempMeterValueInterval = 0;
  2296. return result;
  2297. }
  2298. int ProcessShareMemory()
  2299. {
  2300. if(InitShareMemory() == FAIL)
  2301. {
  2302. DEBUG_ERROR("InitShareMemory NG\n");
  2303. if(ShmStatusCodeData!=NULL)
  2304. {
  2305. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  2306. }
  2307. sleep(5);
  2308. return FAIL;
  2309. }
  2310. return PASS;
  2311. }
  2312. void CheckSystemValue(void)
  2313. {
  2314. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  2315. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  2316. char filenmae[100]={0};
  2317. char str[100]={0};
  2318. int tempIndex = 0;
  2319. //===============================
  2320. // send Heartbeat
  2321. //===============================
  2322. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2323. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2324. {
  2325. clientTime.Heartbeat=time((time_t*)NULL);
  2326. if(server_sign == TRUE)
  2327. {
  2328. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2329. }
  2330. else
  2331. {
  2332. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2333. }
  2334. }
  2335. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  2336. {
  2337. //parameter for test
  2338. sendHeartbeatRequest(0);
  2339. //==============================================
  2340. // Reset Waiting Time
  2341. //==============================================
  2342. HeartBeatWithNOResponse += 1;
  2343. }
  2344. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2345. {
  2346. //==========================================
  2347. // csu trigger DataTransferReq
  2348. //==========================================
  2349. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2350. {
  2351. sendDataTransferRequest(gun_index);
  2352. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2353. }
  2354. //===============================
  2355. // CSU Trigger Reset Conf
  2356. //===============================
  2357. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  2358. {
  2359. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  2360. }
  2361. //===============================
  2362. // CSU Trigger Authorize Request
  2363. //===============================
  2364. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2365. {
  2366. sendAuthorizeRequest(0);
  2367. authorizeRetryTimes = authorizeRetryTimes + 1;
  2368. if(authorizeRetryTimes < 3)
  2369. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2370. }
  2371. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  2372. {
  2373. authorizeRetryTimes = 0;
  2374. SetOcppConnStatus(FALSE);
  2375. server_sign = FALSE;
  2376. }
  2377. 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))
  2378. {
  2379. sendAuthorizeRequest(0);
  2380. }
  2381. //==============================================
  2382. // CSU Trigger Smart Charging Profilw
  2383. //==============================================
  2384. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2385. {
  2386. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  2387. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2388. }
  2389. //==============================================
  2390. // Charger start transaction
  2391. //==============================================
  2392. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2393. {
  2394. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  2395. sendStartTransactionRequest(gun_index);
  2396. clientTime.StartTransaction = time((time_t*)NULL);
  2397. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2398. storeTempStopTransaction(gun_index);
  2399. }
  2400. //==============================================
  2401. // Charger stop transaction
  2402. //==============================================
  2403. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2404. {
  2405. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2406. sendStopTransactionRequest(gun_index);
  2407. clientTime.StopTransaction = time((time_t*)NULL);
  2408. }
  2409. //==============================================
  2410. // Charger status report
  2411. //==============================================
  2412. //--- Check Mode Change ---//
  2413. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2414. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2415. {
  2416. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2417. {
  2418. tempIndex = ((gun_index==2) ? 1: 0);
  2419. }
  2420. else
  2421. {
  2422. tempIndex = gun_index;
  2423. }
  2424. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2425. {
  2426. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2427. {
  2428. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  2429. {
  2430. // Sent unplug message for California pricing logic
  2431. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  2432. {
  2433. uint8_t ts[20];
  2434. getNowDatetime(ts);
  2435. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2436. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2437. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2438. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2439. }
  2440. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2441. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2442. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2443. statusModeChage[gun_index] = TRUE;
  2444. }
  2445. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2446. {
  2447. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2448. if((access(filenmae,F_OK))!=-1)
  2449. {
  2450. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2451. sprintf(str,"rm -f %s",filenmae);
  2452. system(str);
  2453. }
  2454. }
  2455. #if 1 // for TempStopTransaction
  2456. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2457. {
  2458. checkTempStopTransaction(gun_index);
  2459. }
  2460. #endif
  2461. }
  2462. }
  2463. }
  2464. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2465. {
  2466. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2467. {
  2468. tempIndex = ((gun_index==2) ? 1: 0);
  2469. }
  2470. else
  2471. {
  2472. tempIndex = gun_index;
  2473. }
  2474. for (int index = 0; index < CCS_QUANTITY; index++)
  2475. {
  2476. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2477. {
  2478. 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]*/ )
  2479. {
  2480. // Sent unplug message for California pricing logic
  2481. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  2482. {
  2483. uint8_t ts[20];
  2484. getNowDatetime(ts);
  2485. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2486. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2487. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2488. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2489. }
  2490. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2491. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2492. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2493. statusModeChage[gun_index] = TRUE;
  2494. }
  2495. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2496. {
  2497. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2498. if((access(filenmae,F_OK))!=-1)
  2499. {
  2500. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2501. sprintf(str,"rm -f %s",filenmae);
  2502. system(str);
  2503. }
  2504. }
  2505. #if 1 // for TempStopTransaction
  2506. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2507. {
  2508. checkTempStopTransaction(gun_index);
  2509. }
  2510. #endif
  2511. }
  2512. }
  2513. }
  2514. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2515. {
  2516. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2517. {
  2518. tempIndex = ((gun_index==2) ? 1: 0);
  2519. }
  2520. else
  2521. {
  2522. tempIndex = gun_index;
  2523. }
  2524. for (int index = 0; index < GB_QUANTITY; index++)
  2525. {
  2526. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2527. {
  2528. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2529. {
  2530. // Sent unplug message for California pricing logic
  2531. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  2532. {
  2533. uint8_t ts[20];
  2534. getNowDatetime(ts);
  2535. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2536. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2537. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2538. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2539. }
  2540. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2541. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2542. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2543. statusModeChage[gun_index] = TRUE;
  2544. }
  2545. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2546. {
  2547. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2548. if((access(filenmae,F_OK))!=-1)
  2549. {
  2550. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2551. sprintf(str,"rm -f %s",filenmae);
  2552. system(str);
  2553. }
  2554. }
  2555. #if 1 // for TempStopTransaction
  2556. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2557. {
  2558. checkTempStopTransaction(gun_index);
  2559. }
  2560. #endif
  2561. }
  2562. }
  2563. }
  2564. else if(gunType[gun_index] == GUN_TYPE_DO)
  2565. {
  2566. tempIndex = gun_index;
  2567. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2568. {
  2569. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2570. {
  2571. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  2572. {
  2573. // Sent unplug message for California pricing logic
  2574. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  2575. {
  2576. uint8_t ts[20];
  2577. getNowDatetime(ts);
  2578. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2579. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2580. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2581. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2582. }
  2583. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  2584. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  2585. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2586. statusModeChage[gun_index] = TRUE;
  2587. }
  2588. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARING))) // complete
  2589. {
  2590. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2591. if((access(filenmae,F_OK))!=-1)
  2592. {
  2593. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2594. sprintf(str,"rm -f %s",filenmae);
  2595. system(str);
  2596. }
  2597. }
  2598. #if 1 // for TempStopTransaction
  2599. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2600. {
  2601. checkTempStopTransaction(gun_index);
  2602. }
  2603. #endif
  2604. }
  2605. }
  2606. }
  2607. else
  2608. {
  2609. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2610. {
  2611. tempIndex = 2;
  2612. }
  2613. else
  2614. {
  2615. tempIndex = gun_index;
  2616. }
  2617. for (int index = 0; index < AC_QUANTITY; index++)
  2618. {
  2619. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2620. {
  2621. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2622. {
  2623. // Sent unplug message for California pricing logic
  2624. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)
  2625. {
  2626. uint8_t ts[20];
  2627. getNowDatetime(ts);
  2628. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2629. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2630. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2631. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2632. }
  2633. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2634. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2635. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2636. statusModeChage[gun_index] = TRUE;
  2637. }
  2638. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2639. {
  2640. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2641. if((access(filenmae,F_OK))!=-1)
  2642. {
  2643. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2644. sprintf(str,"rm -f %s",filenmae);
  2645. system(str);
  2646. }
  2647. }
  2648. #if 1 // for TempStopTransaction
  2649. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2650. {
  2651. checkTempStopTransaction(gun_index);
  2652. }
  2653. #endif
  2654. }
  2655. }// END
  2656. }
  2657. if(isWebsocketSendable && (server_sign == TRUE) &&
  2658. (
  2659. (statusModeChage[gun_index] == TRUE) ||
  2660. //((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index))) ||
  2661. ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 10))
  2662. )
  2663. )
  2664. {
  2665. if(SystemInitial > 0)
  2666. SystemInitial -= 1;
  2667. sendStatusNotificationRequest(gun_index);
  2668. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2669. statusModeChage[gun_index] = FALSE;
  2670. }
  2671. //==============================================
  2672. // Meter report
  2673. //==============================================
  2674. // Trigger MeterValue
  2675. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  2676. {
  2677. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  2678. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  2679. }
  2680. // ClockAlign MeterValue
  2681. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  2682. {
  2683. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2684. {
  2685. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2686. {
  2687. tempIndex = ((gun_index==2) ? 1: 0);
  2688. }
  2689. else
  2690. {
  2691. tempIndex = gun_index;
  2692. }
  2693. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2694. {
  2695. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2696. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2697. {
  2698. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2699. {
  2700. reqClockAlignMeter[gun_index] = 1;
  2701. }
  2702. }
  2703. }// End for CHAdeMO
  2704. }
  2705. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2706. {
  2707. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2708. {
  2709. tempIndex = ((gun_index==2) ? 1: 0);
  2710. }
  2711. else
  2712. {
  2713. tempIndex = gun_index;
  2714. }
  2715. for (int index = 0; index < CCS_QUANTITY; index++)
  2716. {
  2717. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2718. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2719. {
  2720. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2721. {
  2722. reqClockAlignMeter[gun_index] = 1;
  2723. }
  2724. }
  2725. } // End for CCS
  2726. }
  2727. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2728. {
  2729. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2730. {
  2731. tempIndex = ((gun_index==2) ? 1: 0);
  2732. }
  2733. else
  2734. {
  2735. tempIndex = gun_index;
  2736. }
  2737. for (int index = 0; index < GB_QUANTITY; index++)
  2738. {
  2739. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2740. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2741. {
  2742. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2743. {
  2744. reqClockAlignMeter[gun_index] = 1;
  2745. }
  2746. }
  2747. }// End for GB
  2748. }
  2749. else if(gunType[gun_index] == GUN_TYPE_DO)
  2750. {
  2751. tempIndex = gun_index;
  2752. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2753. {
  2754. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2755. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2756. {
  2757. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_CHARGING)
  2758. {
  2759. reqClockAlignMeter[gun_index] = 1;
  2760. }
  2761. }
  2762. }
  2763. }
  2764. else
  2765. {
  2766. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2767. {
  2768. tempIndex = 2;
  2769. }
  2770. else
  2771. {
  2772. tempIndex = gun_index;
  2773. }
  2774. for (int index = 0; index < AC_QUANTITY; index++)
  2775. {
  2776. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2777. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2778. {
  2779. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2780. {
  2781. reqClockAlignMeter[gun_index] = 1;
  2782. }
  2783. }
  2784. }//End for AC
  2785. }
  2786. if(reqClockAlignMeter[gun_index] == 1)
  2787. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2788. }
  2789. // Sample period MeterValue
  2790. if((((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1))))
  2791. {
  2792. //check Transaction active
  2793. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2794. {
  2795. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2796. {
  2797. tempIndex = ((gun_index==2) ? 1: 0);
  2798. }
  2799. else
  2800. {
  2801. tempIndex = gun_index;
  2802. }
  2803. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2804. {
  2805. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2806. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2807. {
  2808. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2809. {
  2810. reqSampleMeter[gun_index] = 1;
  2811. }
  2812. }
  2813. }// End for CHAdeMO
  2814. }
  2815. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2816. {
  2817. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2818. {
  2819. tempIndex = ((gun_index==2) ? 1: 0);
  2820. }
  2821. else
  2822. {
  2823. tempIndex = gun_index;
  2824. }
  2825. for (int index = 0; index < CCS_QUANTITY; index++)
  2826. {
  2827. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2828. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2829. {
  2830. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2831. {
  2832. reqSampleMeter[gun_index] = 1;
  2833. }
  2834. }
  2835. } // End for CCS
  2836. }
  2837. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2838. {
  2839. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2840. {
  2841. tempIndex = ((gun_index==2) ? 1: 0);
  2842. }
  2843. else
  2844. {
  2845. tempIndex = gun_index;
  2846. }
  2847. for (int index = 0; index < GB_QUANTITY; index++)
  2848. {
  2849. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2850. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2851. {
  2852. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2853. {
  2854. reqSampleMeter[gun_index] = 1;
  2855. }
  2856. }
  2857. }// End for GB
  2858. }
  2859. else if(gunType[gun_index] == GUN_TYPE_DO)
  2860. {
  2861. tempIndex = gun_index;
  2862. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2863. {
  2864. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2865. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2866. {
  2867. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  2868. {
  2869. reqSampleMeter[gun_index] = 1;
  2870. }
  2871. }
  2872. }
  2873. }
  2874. else
  2875. {
  2876. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2877. {
  2878. tempIndex = 2;
  2879. }
  2880. else
  2881. {
  2882. tempIndex = gun_index;
  2883. }
  2884. for (int index = 0; index < AC_QUANTITY; index++)
  2885. {
  2886. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2887. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2888. {
  2889. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  2890. {
  2891. reqSampleMeter[gun_index] = 1;
  2892. }
  2893. }
  2894. }//End for AC
  2895. }
  2896. if(reqSampleMeter[gun_index] == 1)
  2897. {
  2898. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  2899. storeTempStopTransaction(gun_index);
  2900. }
  2901. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2902. }
  2903. //==============================================
  2904. // Check Connector reserved
  2905. //==============================================
  2906. //===============================
  2907. // Check if Reserve is expired
  2908. //===============================
  2909. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  2910. {
  2911. double diff_t;
  2912. struct tm tp;
  2913. // current time
  2914. time_t t = time(NULL);
  2915. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  2916. tp.tm_isdst = -1;
  2917. time_t utc = mktime(&tp);
  2918. diff_t = difftime(utc, t);
  2919. if(diff_t <= 0)
  2920. {
  2921. DEBUG_INFO("reserve expired.\n");
  2922. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  2923. }
  2924. }//END OF Check if Reserve is expired
  2925. //==========================================
  2926. // csu trigger FirmwareStatusNotificationReq
  2927. //==========================================
  2928. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  2929. {
  2930. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  2931. }
  2932. //==========================================
  2933. // csu trigger CancelReservationConf
  2934. //==========================================
  2935. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  2936. {
  2937. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  2938. }
  2939. //==========================================
  2940. // csu trigger ChangeAvailabilityConf
  2941. //==========================================
  2942. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  2943. {
  2944. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  2945. }
  2946. //==========================================
  2947. // csu trigger UnlockConnectorConf
  2948. //==========================================
  2949. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  2950. {
  2951. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  2952. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  2953. }
  2954. //==========================================
  2955. // csu trigger ReserveNowConf
  2956. //==========================================
  2957. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  2958. {
  2959. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  2960. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  2961. }
  2962. }
  2963. }
  2964. //==========================================
  2965. // send request routine
  2966. //==========================================
  2967. int sendAuthorizeRequest(int gun_index)
  2968. {
  2969. mtrace();
  2970. int result = FAIL;
  2971. char message[100]={0};
  2972. char guid[37];
  2973. char tempdata[65]={0};
  2974. DEBUG_INFO("sendAuthorizeRequest...\n");
  2975. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  2976. //Local Authorize
  2977. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  2978. {
  2979. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  2980. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2981. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  2982. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  2983. result = PASS;
  2984. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2985. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2986. authorizeRetryTimes = 0;
  2987. return result;
  2988. }
  2989. 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))||
  2990. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  2991. {
  2992. // Query from cache
  2993. DEBUG_INFO("Authorize from cache.\n");
  2994. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2995. // Query from list
  2996. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  2997. {
  2998. DEBUG_INFO("Authorize from list.\n");
  2999. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3000. }
  3001. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3002. {
  3003. if(strcmp(idTagQuery.idTagstr,"") == 0)
  3004. {
  3005. DEBUG_INFO("off-line Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  3006. }
  3007. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  3008. {
  3009. DEBUG_INFO("off-line Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  3010. }
  3011. DEBUG_INFO("off-line Local Authorization Fail !!!!\n");
  3012. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  3013. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3014. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  3015. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3016. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3017. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3018. authorizeRetryTimes = 0;
  3019. return result;
  3020. }
  3021. else
  3022. {
  3023. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  3024. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3025. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3026. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  3027. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  3028. else
  3029. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  3030. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3031. result = PASS;
  3032. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3033. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3034. authorizeRetryTimes = 0;
  3035. return result;
  3036. }
  3037. }
  3038. //initialize struct Authorize
  3039. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  3040. //get data from shared memory
  3041. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3042. random_uuid(guid);
  3043. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  3044. LWS_Send(message);
  3045. sprintf(tempdata, "Authorize,%d", gun_index);
  3046. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3047. {
  3048. result = PASS;
  3049. DEBUG_INFO("Authorize mapItem pass\n");
  3050. }
  3051. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3052. return result;
  3053. }
  3054. int sendBootNotificationRequest(void)
  3055. {
  3056. mtrace();
  3057. int result = FAIL;
  3058. char message[500]={0}, payload[700]={0};
  3059. char guid[37]={0};
  3060. char tempdata[65]={0};
  3061. // Fill BootNotification fields
  3062. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  3063. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  3064. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  3065. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3066. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  3067. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  3068. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  3069. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  3070. ShmOCPP16Data->ChargeBoxId
  3071. ,ShmSysConfigAndInfo->SysConfig.ModelName
  3072. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  3073. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  3074. ,ShmOCPP16Data->BootNotification.CpFwVersion
  3075. ,ShmOCPP16Data->BootNotification.CpIccid
  3076. ,ShmOCPP16Data->BootNotification.CpImsi);
  3077. random_uuid(guid);
  3078. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  3079. LWS_Send(message);
  3080. sprintf(tempdata, "BootNotification,0");
  3081. 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*/)
  3082. {
  3083. result = PASS;
  3084. }
  3085. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3086. strcpy(queuedata,message);
  3087. return result;
  3088. }
  3089. int sendDataTransferRequest(int gun_index)
  3090. {
  3091. mtrace();
  3092. char message[1000]={0};
  3093. char guid[37]={0};
  3094. char tempdata[65]={0};
  3095. int result = FAIL;
  3096. random_uuid(guid);
  3097. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  3098. MESSAGE_TYPE_CALL,
  3099. guid,
  3100. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  3101. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  3102. ShmOCPP16Data->DataTransfer[gun_index].Data);
  3103. LWS_Send(message);
  3104. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  3105. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3106. {
  3107. result = PASS;
  3108. DEBUG_INFO("DataTransfer mapItem pass\n");
  3109. }
  3110. return result;
  3111. }
  3112. int sendDiagnosticsStatusNotificationRequest(char *status)
  3113. {
  3114. mtrace();
  3115. int result = FAIL;
  3116. char message[110]={0};
  3117. char guid[37]={0};
  3118. char tempdata[65]={0};
  3119. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  3120. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  3121. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  3122. random_uuid(guid);
  3123. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  3124. LWS_SendNow(message);
  3125. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  3126. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3127. {
  3128. result = PASS;
  3129. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  3130. }
  3131. //#ifdef SystemLogMessage
  3132. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  3133. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3134. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  3135. //#endif
  3136. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  3137. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  3138. //record status
  3139. if(strcmp(status,"Idle")==0)
  3140. {
  3141. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  3142. }
  3143. else if(strcmp(status,"Uploaded")==0)
  3144. {
  3145. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  3146. }
  3147. else if(strcmp(status,"UploadFailed")==0)
  3148. {
  3149. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  3150. }
  3151. else if(strcmp(status,"Uploading")==0)
  3152. {
  3153. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  3154. }
  3155. return result;
  3156. }
  3157. int sendFirmwareStatusNotificationRequest(char *status)
  3158. {
  3159. mtrace();
  3160. int result = FAIL;
  3161. char message[110]={0};
  3162. char guid[37]={0};
  3163. char tempdata[65]={0};
  3164. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  3165. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  3166. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  3167. random_uuid(guid);
  3168. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  3169. LWS_SendNow(message);
  3170. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  3171. 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*/)
  3172. {
  3173. result = PASS;
  3174. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  3175. }
  3176. //#ifdef SystemLogMessage
  3177. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  3178. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3179. //#endif
  3180. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  3181. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  3182. //record status
  3183. if(strcmp(status,"Downloaded")==0)
  3184. {
  3185. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  3186. }
  3187. else if(strcmp(status,"DownloadFailed")==0)
  3188. {
  3189. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  3190. }
  3191. else if(strcmp(status,"Downloading")==0)
  3192. {
  3193. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  3194. }
  3195. else if(strcmp(status,"Idle")==0)
  3196. {
  3197. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  3198. }
  3199. else if(strcmp(status,"InstallationFailed")==0)
  3200. {
  3201. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  3202. }
  3203. else if(strcmp(status,"Installing")==0)
  3204. {
  3205. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  3206. }
  3207. else if(strcmp(status,"Installed")==0)
  3208. {
  3209. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  3210. }
  3211. return result;
  3212. }
  3213. int sendHeartbeatRequest(int gun_index)
  3214. {
  3215. mtrace();
  3216. int result = FAIL;
  3217. char message[80]={0};
  3218. char guid[37]={0};
  3219. char tempdata[65]={0};
  3220. random_uuid(guid);
  3221. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  3222. , MESSAGE_TYPE_CALL
  3223. , guid );
  3224. LWS_Send(message);
  3225. sprintf(tempdata, "Heartbeat,%d", 0);
  3226. 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*/)
  3227. {
  3228. result = PASS;
  3229. }
  3230. return result;
  3231. }
  3232. int sendStartTransactionRequest(int gun_index)
  3233. {
  3234. mtrace();
  3235. int result = FAIL;
  3236. char message[250]={0};
  3237. char guid[37]={0};
  3238. struct timeval tmnow;
  3239. struct tm *tm;
  3240. char buf[28];//, usec_buf[6];
  3241. char tempdata[65]={0};
  3242. int tempIndex = 0;
  3243. DEBUG_INFO("sendStartTransactionRequest...\n");
  3244. gettimeofday(&tmnow, NULL);
  3245. time_t t;
  3246. t = time(NULL);
  3247. /*UTC time and date*/
  3248. tm = gmtime(&t);
  3249. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3250. #if 0 // remove temporally
  3251. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3252. strcat(buf,".");
  3253. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3254. strcat(buf,usec_buf);
  3255. #endif
  3256. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  3257. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  3258. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3259. // clear StartTransaction Response
  3260. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  3261. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  3262. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  3263. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  3264. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3265. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3266. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3267. {
  3268. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3269. {
  3270. tempIndex = ((gun_index==2) ? 1: 0);
  3271. }
  3272. else
  3273. {
  3274. tempIndex = gun_index;
  3275. }
  3276. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3277. {
  3278. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3279. {
  3280. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3281. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  3282. }
  3283. }
  3284. }
  3285. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3286. {
  3287. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3288. {
  3289. tempIndex = ((gun_index==2) ? 1: 0);
  3290. }
  3291. else
  3292. {
  3293. tempIndex = gun_index;
  3294. }
  3295. for (int index = 0; index < CCS_QUANTITY; index++)
  3296. {
  3297. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3298. {
  3299. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3300. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  3301. }
  3302. }
  3303. }
  3304. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3305. {
  3306. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3307. {
  3308. tempIndex = ((gun_index==2) ? 1: 0);
  3309. }
  3310. else
  3311. {
  3312. tempIndex = gun_index;
  3313. }
  3314. for (int index = 0; index < GB_QUANTITY; index++)
  3315. {
  3316. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3317. {
  3318. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3319. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  3320. }
  3321. }
  3322. }
  3323. else if(gunType[gun_index] == GUN_TYPE_DO)
  3324. {
  3325. tempIndex = gun_index;
  3326. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3327. {
  3328. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3329. {
  3330. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3331. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  3332. }
  3333. }
  3334. }
  3335. else
  3336. {
  3337. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3338. {
  3339. tempIndex = 2;
  3340. }
  3341. else
  3342. {
  3343. tempIndex = gun_index;
  3344. }
  3345. for (int index = 0; index < AC_QUANTITY; index++)
  3346. {
  3347. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3348. {
  3349. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3350. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  3351. }
  3352. }
  3353. }
  3354. random_uuid(guid);
  3355. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  3356. {
  3357. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  3358. , gun_index +1
  3359. , MESSAGE_TYPE_CALL
  3360. , guid
  3361. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3362. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3363. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3364. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3365. }
  3366. else
  3367. {
  3368. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  3369. , gun_index +1
  3370. , MESSAGE_TYPE_CALL
  3371. , guid
  3372. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3373. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3374. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3375. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  3376. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3377. }
  3378. #if 1
  3379. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  3380. 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*/)
  3381. {
  3382. result = PASS;
  3383. }
  3384. #endif
  3385. strcpy(queuedata, message);
  3386. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3387. OCPP_insert_transaction_msg(YES, queuedata);
  3388. return result;
  3389. }
  3390. int sendStatusNotificationRequest(int gun_index)
  3391. {
  3392. mtrace();
  3393. int result = FAIL;
  3394. char message[600]={0};
  3395. char guid[37];
  3396. int currentStatus = 0;
  3397. struct timeval tmnow;
  3398. struct tm *tm;
  3399. char buf[28];//, usec_buf[6];
  3400. char tempdata[65]={0};
  3401. int tempIndex = 0;
  3402. DEBUG_INFO("sendStatusNotificationRequest...\n");
  3403. gettimeofday(&tmnow, NULL);
  3404. time_t t;
  3405. t = time(NULL);
  3406. /*UTC time and date*/
  3407. tm = gmtime(&t);
  3408. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3409. #if 0 // remove temporally
  3410. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3411. strcat(buf,".");
  3412. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3413. strcat(buf,usec_buf);
  3414. #endif
  3415. printf("%s",buf);
  3416. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  3417. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  3418. // it's option
  3419. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  3420. /*
  3421. enum _SYSTEM_STATUS
  3422. {
  3423. S_BOOTING = 0,
  3424. S_IDLE, = 1
  3425. S_AUTHORIZING, =2
  3426. S_REASSIGN_CHECK, =3
  3427. S_REASSIGN, =4
  3428. S_PRECHARGE, =5
  3429. S_PREPARING_FOR_EV, =6
  3430. S_PREPARING_FOR_EVSE, =7
  3431. S_CHARGING, =8
  3432. S_TERMINATING, =9
  3433. S_COMPLETE, =10
  3434. S_ALARM, =11
  3435. S_FAULT =12
  3436. }
  3437. */
  3438. //check Transaction active
  3439. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3440. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3441. {
  3442. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3443. {
  3444. tempIndex = ((gun_index==2) ? 1: 0);
  3445. }
  3446. else
  3447. {
  3448. tempIndex = gun_index;
  3449. }
  3450. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3451. {
  3452. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  3453. {
  3454. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  3455. {
  3456. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3457. {
  3458. currentStatus = Preparing; //OCPP Status: Preparing
  3459. }
  3460. else
  3461. {
  3462. currentStatus = Available; //OCPP Status: Available
  3463. }
  3464. }
  3465. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3466. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3467. ) //S_PRECHARGE
  3468. {
  3469. currentStatus = Preparing; //OCPP Status: Preparing
  3470. }
  3471. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3472. {
  3473. currentStatus = Charging; //OCPP Status: Charging
  3474. }
  3475. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3476. {
  3477. currentStatus = Finishing; //OCPP Status: Finishing
  3478. }
  3479. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3480. {
  3481. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3482. }
  3483. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (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
  3484. {
  3485. currentStatus = Unavailable; //OCPP Status: Unavailable
  3486. }
  3487. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3488. {
  3489. currentStatus = Faulted; //OCPP Status: Faulted
  3490. }
  3491. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3492. {
  3493. currentStatus = Reserved; //OCPP Status: Reserved
  3494. }
  3495. } //end of the same index
  3496. }//end of for CHAdeMO_QUANTITY
  3497. }
  3498. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3499. {
  3500. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3501. {
  3502. tempIndex = ((gun_index==2) ? 1: 0);
  3503. }
  3504. else
  3505. {
  3506. tempIndex = gun_index;
  3507. }
  3508. for (int index = 0; index < CCS_QUANTITY; index++)
  3509. {
  3510. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3511. {
  3512. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3513. {
  3514. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3515. {
  3516. currentStatus = Preparing; //OCPP Status: Preparing
  3517. }
  3518. else
  3519. {
  3520. currentStatus = Available; //OCPP Status: Available
  3521. }
  3522. }
  3523. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3524. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3525. ) //S_PRECHARGE
  3526. {
  3527. currentStatus = Preparing; //OCPP Status: Preparing
  3528. }
  3529. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3530. {
  3531. currentStatus = Charging; //OCPP Status: Charging
  3532. }
  3533. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3534. {
  3535. currentStatus = Finishing; //OCPP Status: Finishing
  3536. }
  3537. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3538. {
  3539. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3540. }
  3541. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (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
  3542. {
  3543. currentStatus = Unavailable; //OCPP Status : Unavailable
  3544. }
  3545. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3546. {
  3547. currentStatus = Faulted; //OCPP Status: Faulted
  3548. }
  3549. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3550. {
  3551. currentStatus = Reserved; //OCPP Status: Reserved
  3552. }
  3553. } //end of the same index
  3554. } // end of for CCS_QUANTITY
  3555. }
  3556. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3557. {
  3558. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3559. {
  3560. tempIndex = ((gun_index==2) ? 1: 0);
  3561. }
  3562. else
  3563. {
  3564. tempIndex = gun_index;
  3565. }
  3566. for (int index = 0; index < GB_QUANTITY; index++)
  3567. {
  3568. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3569. {
  3570. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3571. {
  3572. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3573. {
  3574. currentStatus = Preparing; //OCPP Status: Preparing
  3575. }
  3576. else
  3577. {
  3578. currentStatus = Available; //OCPP Status: Available
  3579. }
  3580. }
  3581. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3582. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3583. ) //S_PRECHARGE
  3584. {
  3585. currentStatus = Preparing; //OCPP Status: Preparing
  3586. }
  3587. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3588. {
  3589. currentStatus = Charging; //OCPP Status: Charging
  3590. }
  3591. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3592. {
  3593. currentStatus = Finishing; //OCPP Status: Finishing
  3594. }
  3595. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3596. {
  3597. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3598. }
  3599. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (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
  3600. {
  3601. currentStatus = Unavailable; //OCPP Status: Unavailable
  3602. }
  3603. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3604. {
  3605. currentStatus = Faulted; //OCPP Status: Faulted
  3606. }
  3607. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3608. {
  3609. currentStatus = Reserved; //OCPP Status: Reserved
  3610. }
  3611. } //end of the same index
  3612. } // end of for GB_QUANTITY
  3613. }
  3614. else if(gunType[gun_index] == GUN_TYPE_DO)
  3615. {
  3616. tempIndex = gun_index;
  3617. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3618. {
  3619. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3620. {
  3621. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3622. {
  3623. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3624. {
  3625. currentStatus = Preparing; //OCPP Status: Preparing
  3626. }
  3627. else
  3628. {
  3629. currentStatus = Available; //OCPP Status: Available
  3630. }
  3631. }
  3632. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3633. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3634. ) //S_PRECHARGE
  3635. {
  3636. currentStatus = Preparing; //OCPP Status: Preparing
  3637. }
  3638. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3639. {
  3640. currentStatus = Charging; //OCPP Status: Charging
  3641. }
  3642. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3643. {
  3644. currentStatus = Finishing; //OCPP Status: Finishing
  3645. }
  3646. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3647. {
  3648. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3649. }
  3650. else if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  3651. {
  3652. currentStatus = Unavailable; //OCPP Status: Unavailable
  3653. }
  3654. else if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3655. {
  3656. currentStatus = Faulted; //OCPP Status: Faulted
  3657. }
  3658. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3659. {
  3660. currentStatus = Reserved; //OCPP Status: Reserved
  3661. }
  3662. } //end of the same index
  3663. }
  3664. }
  3665. else
  3666. {
  3667. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3668. {
  3669. tempIndex = 2;
  3670. }
  3671. else
  3672. {
  3673. tempIndex = gun_index;
  3674. }
  3675. for (int index = 0; index < AC_QUANTITY; index++)
  3676. {
  3677. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3678. {
  3679. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3680. {
  3681. 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))
  3682. {
  3683. currentStatus = Preparing; //OCPP Status: Preparing
  3684. }
  3685. else
  3686. {
  3687. currentStatus = Available; //OCPP Status: Available
  3688. }
  3689. }
  3690. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3691. {
  3692. currentStatus = Preparing; //OCPP Status: Preparing
  3693. }
  3694. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3695. {
  3696. currentStatus = Charging; //OCPP Status: Charging
  3697. }
  3698. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3699. {
  3700. currentStatus = Finishing; //OCPP Status: Finishing
  3701. }
  3702. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3703. {
  3704. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3705. }
  3706. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (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
  3707. {
  3708. currentStatus = Unavailable; //OCPP Status: Unavailable
  3709. }
  3710. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3711. {
  3712. currentStatus = Faulted; //OCPP Status: Faulted
  3713. }
  3714. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3715. {
  3716. currentStatus = Reserved; //OCPP Status: Reserved
  3717. }
  3718. }//end of the same index
  3719. }//end of for AC_QUANTITY
  3720. }
  3721. //it's option
  3722. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3723. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3724. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3725. random_uuid(guid);
  3726. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3727. , MESSAGE_TYPE_CALL
  3728. , guid
  3729. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3730. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3731. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3732. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3733. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3734. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3735. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3736. if((server_sign == TRUE))
  3737. {
  3738. LWS_Send(message);
  3739. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3740. 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*/)
  3741. {
  3742. //DEBUG_ERROR("statusNotification mapitem pass");
  3743. result = PASS;
  3744. }
  3745. }
  3746. else
  3747. {
  3748. result = PASS;
  3749. }
  3750. return result;
  3751. }
  3752. int sendStopTransactionRequest(int gun_index)
  3753. {
  3754. mtrace();
  3755. int result = FAIL;
  3756. //char message[1500]={0};
  3757. char guid[37]={0};
  3758. char tempdata[65]={0};
  3759. int tempIndex = 0;
  3760. char TempStopTransaction[256];
  3761. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  3762. //int idx_sample=0;
  3763. DEBUG_INFO("sendStopTransactionRequest \n");
  3764. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3765. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  3766. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3767. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3768. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3769. {
  3770. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3771. {
  3772. tempIndex = ((gun_index==2) ? 1: 0);
  3773. }
  3774. else
  3775. {
  3776. tempIndex = gun_index;
  3777. }
  3778. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3779. {
  3780. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3781. {
  3782. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3783. }
  3784. }// END OF CHAdeMO_QUANTITY
  3785. }
  3786. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3787. {
  3788. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3789. {
  3790. tempIndex = ((gun_index==2) ? 1: 0);
  3791. }
  3792. else
  3793. {
  3794. tempIndex = gun_index;
  3795. }
  3796. for (int index = 0; index < CCS_QUANTITY; index++)
  3797. {
  3798. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3799. {
  3800. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3801. }
  3802. }// END OF CCS_QUANTITY
  3803. }
  3804. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3805. {
  3806. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3807. {
  3808. tempIndex = ((gun_index==2) ? 1: 0);
  3809. }
  3810. else
  3811. {
  3812. tempIndex = gun_index;
  3813. }
  3814. for (int index = 0; index < GB_QUANTITY; index++)
  3815. {
  3816. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3817. {
  3818. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3819. }
  3820. }// END OF GB_QUANTITY
  3821. }
  3822. else if(gunType[gun_index] == GUN_TYPE_DO)
  3823. {
  3824. tempIndex = gun_index;
  3825. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3826. {
  3827. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3828. {
  3829. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3830. }
  3831. }// END OF GB_QUANTITY
  3832. }
  3833. else
  3834. {
  3835. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3836. {
  3837. tempIndex = 2;
  3838. }
  3839. else
  3840. {
  3841. tempIndex = gun_index;
  3842. }
  3843. for (int index = 0; index < AC_QUANTITY; index++)
  3844. {
  3845. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3846. {
  3847. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3848. }
  3849. }// END OF AC_QUANTITY
  3850. }
  3851. //====================================== Stop Transaction Time =====================================================
  3852. struct timeval tmnow;
  3853. struct tm *tm;
  3854. char buf[28];//, usec_buf[6];
  3855. gettimeofday(&tmnow, NULL);
  3856. time_t t;
  3857. t = time(NULL);
  3858. /*UTC time and date*/
  3859. tm = gmtime(&t);
  3860. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3861. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  3862. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  3863. random_uuid(guid);
  3864. /***********************************transactionData******************************************************/
  3865. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  3866. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  3867. //=================================
  3868. // Transaction_Begin
  3869. //=================================
  3870. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  3871. {
  3872. //============================================ Energy.Active.Import.Interval ================================
  3873. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  3874. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  3875. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  3876. 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*/]);
  3877. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3878. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  3879. {
  3880. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  3881. }
  3882. else
  3883. {
  3884. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  3885. }
  3886. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  3887. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3888. }
  3889. //=================================
  3890. // Transaction_End
  3891. //=================================
  3892. // ================================= Current.Import L1 ===============================================
  3893. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  3894. {
  3895. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  3896. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3897. {
  3898. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3899. {
  3900. tempIndex = ((gun_index==2) ? 1: 0);
  3901. }
  3902. else
  3903. {
  3904. tempIndex = gun_index;
  3905. }
  3906. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3907. {
  3908. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3909. {
  3910. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3911. }
  3912. }// End of for CHAdeMO_QUANTITY
  3913. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3914. }
  3915. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3916. {
  3917. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3918. {
  3919. tempIndex = ((gun_index==2) ? 1: 0);
  3920. }
  3921. else
  3922. {
  3923. tempIndex = gun_index;
  3924. }
  3925. for (int index = 0; index < CCS_QUANTITY; index++)
  3926. {
  3927. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3928. {
  3929. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3930. }
  3931. }// End of for CCS_QUANTITY
  3932. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3933. }
  3934. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3935. {
  3936. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3937. {
  3938. tempIndex = ((gun_index==2) ? 1: 0);
  3939. }
  3940. else
  3941. {
  3942. tempIndex = gun_index;
  3943. }
  3944. for (int index = 0; index < GB_QUANTITY; index++)
  3945. {
  3946. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3947. {
  3948. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3949. }
  3950. }// End of for GB_QUANTITY
  3951. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3952. }
  3953. else if(gunType[gun_index] == GUN_TYPE_DO)
  3954. {
  3955. tempIndex = gun_index;
  3956. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3957. {
  3958. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3959. {
  3960. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3961. }
  3962. }
  3963. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3964. }
  3965. else
  3966. {
  3967. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3968. {
  3969. tempIndex = 2;
  3970. }
  3971. else
  3972. {
  3973. tempIndex = gun_index;
  3974. }
  3975. for (int index = 0; index < AC_QUANTITY; index++)
  3976. {
  3977. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3978. {
  3979. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  3980. }
  3981. }// End of for AC_QUANTITY
  3982. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  3983. }
  3984. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3985. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  3986. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  3987. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  3988. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3989. }
  3990. // ================================= Energy.Active.Import.Interval ==============================================
  3991. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  3992. {
  3993. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3994. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3995. {
  3996. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3997. {
  3998. tempIndex = ((gun_index==2) ? 1: 0);
  3999. }
  4000. else
  4001. {
  4002. tempIndex = gun_index;
  4003. }
  4004. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4005. {
  4006. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4007. {
  4008. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4009. }
  4010. }// END OF CHAdeMO_QUANTITY
  4011. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4012. }
  4013. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4014. {
  4015. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4016. {
  4017. tempIndex = ((gun_index==2) ? 1: 0);
  4018. }
  4019. else
  4020. {
  4021. tempIndex = gun_index;
  4022. }
  4023. for (int index = 0; index < CCS_QUANTITY; index++)
  4024. {
  4025. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4026. {
  4027. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4028. }
  4029. }// END OF CCS_QUANTITY
  4030. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4031. }
  4032. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4033. {
  4034. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4035. {
  4036. tempIndex = ((gun_index==2) ? 1: 0);
  4037. }
  4038. else
  4039. {
  4040. tempIndex = gun_index;
  4041. }
  4042. for (int index = 0; index < GB_QUANTITY; index++)
  4043. {
  4044. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4045. {
  4046. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4047. }
  4048. }// END OF GB_QUANTITY
  4049. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4050. }
  4051. else if(gunType[gun_index] == GUN_TYPE_DO)
  4052. {
  4053. tempIndex = gun_index;
  4054. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4055. {
  4056. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4057. {
  4058. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4059. }
  4060. }
  4061. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4062. }
  4063. else
  4064. {
  4065. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4066. {
  4067. tempIndex = 2;
  4068. }
  4069. else
  4070. {
  4071. tempIndex = gun_index;
  4072. }
  4073. for (int index = 0; index < AC_QUANTITY; index++)
  4074. {
  4075. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4076. {
  4077. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4078. }
  4079. }// END OF AC_QUANTITY
  4080. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  4081. }
  4082. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4083. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  4084. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  4085. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  4086. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4087. }
  4088. //=================================== Power.Active.Import ==================================================
  4089. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  4090. {
  4091. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4092. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4093. {
  4094. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4095. {
  4096. tempIndex = ((gun_index==2) ? 1: 0);
  4097. }
  4098. else
  4099. {
  4100. tempIndex = gun_index;
  4101. }
  4102. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4103. {
  4104. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4105. {
  4106. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4107. }
  4108. } // End for CHAdeMO_QUANTITY
  4109. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4110. }
  4111. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4112. {
  4113. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4114. {
  4115. tempIndex = ((gun_index==2) ? 1: 0);
  4116. }
  4117. else
  4118. {
  4119. tempIndex = gun_index;
  4120. }
  4121. for (int index = 0; index < CCS_QUANTITY; index++)
  4122. {
  4123. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4124. {
  4125. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4126. }
  4127. } // END for CCS_QUANTITY
  4128. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4129. }
  4130. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4131. {
  4132. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4133. {
  4134. tempIndex = ((gun_index==2) ? 1: 0);
  4135. }
  4136. else
  4137. {
  4138. tempIndex = gun_index;
  4139. }
  4140. for (int index = 0; index < GB_QUANTITY; index++)
  4141. {
  4142. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4143. {
  4144. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4145. }
  4146. }// END for GB_QUANTITY
  4147. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4148. }
  4149. else if(gunType[gun_index] == GUN_TYPE_DO)
  4150. {
  4151. tempIndex = gun_index;
  4152. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4153. {
  4154. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4155. {
  4156. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4157. }
  4158. }
  4159. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4160. }
  4161. else
  4162. {
  4163. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4164. {
  4165. tempIndex = 2;
  4166. }
  4167. else
  4168. {
  4169. tempIndex = gun_index;
  4170. }
  4171. for (int index = 0; index < AC_QUANTITY; index++)
  4172. {
  4173. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4174. {
  4175. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4176. }
  4177. } // END for AC_QUANTITY
  4178. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  4179. }
  4180. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4181. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  4182. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  4183. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  4184. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  4185. }
  4186. //============================ Voltage L1 ====================================
  4187. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4188. {
  4189. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4190. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4191. {
  4192. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4193. {
  4194. tempIndex = ((gun_index==2) ? 1: 0);
  4195. }
  4196. else
  4197. {
  4198. tempIndex = gun_index;
  4199. }
  4200. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4201. {
  4202. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4203. {
  4204. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4205. }
  4206. } // END OF FOR CHAdeMO_QUANTITY
  4207. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4208. }
  4209. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4210. {
  4211. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4212. {
  4213. tempIndex = ((gun_index==2) ? 1: 0);
  4214. }
  4215. else
  4216. {
  4217. tempIndex = gun_index;
  4218. }
  4219. for (int index = 0; index < CCS_QUANTITY; index++)
  4220. {
  4221. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4222. {
  4223. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4224. }
  4225. } // END OF FOR CCS_QUANTITY
  4226. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4227. }
  4228. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4229. {
  4230. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4231. {
  4232. tempIndex = ((gun_index==2) ? 1: 0);
  4233. }
  4234. else
  4235. {
  4236. tempIndex = gun_index;
  4237. }
  4238. for (int index = 0; index < GB_QUANTITY; index++)
  4239. {
  4240. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4241. {
  4242. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4243. }
  4244. } // END OF FOR GB_QUANTITY
  4245. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4246. }
  4247. else if(gunType[gun_index] == GUN_TYPE_DO)
  4248. {
  4249. tempIndex = gun_index;
  4250. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4251. {
  4252. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4253. {
  4254. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4255. }
  4256. }
  4257. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4258. }
  4259. else
  4260. {
  4261. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4262. {
  4263. tempIndex = 2;
  4264. }
  4265. else
  4266. {
  4267. tempIndex = gun_index;
  4268. }
  4269. for (int index = 0; index < AC_QUANTITY; index++)
  4270. {
  4271. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4272. {
  4273. 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
  4274. }
  4275. } // END OF FOR AC_QUANTITY
  4276. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  4277. }
  4278. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4279. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  4280. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  4281. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  4282. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4283. }
  4284. //====================== End SoC ================================
  4285. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4286. {
  4287. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4288. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  4289. {
  4290. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4291. {
  4292. tempIndex = ((gun_index==2) ? 1: 0);
  4293. }
  4294. else
  4295. {
  4296. tempIndex = gun_index;
  4297. }
  4298. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4299. {
  4300. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4301. {
  4302. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4303. {
  4304. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  4305. }
  4306. }
  4307. }
  4308. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4309. {
  4310. for (int index = 0; index < CCS_QUANTITY; index++)
  4311. {
  4312. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4313. {
  4314. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  4315. }
  4316. }
  4317. }
  4318. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4319. {
  4320. for (int index = 0; index < GB_QUANTITY; index++)
  4321. {
  4322. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4323. {
  4324. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  4325. }
  4326. }
  4327. }
  4328. else if(gunType[gun_index] == GUN_TYPE_DO)
  4329. {
  4330. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4331. {
  4332. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4333. {
  4334. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  4335. }
  4336. }
  4337. }
  4338. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4339. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  4340. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4341. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  4342. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  4343. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4344. } // END FOR DC CASE
  4345. }
  4346. // ================================= Current.Import L2 ===============================================
  4347. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4348. {
  4349. // AC 3 phse L2 current
  4350. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4351. {
  4352. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4353. {
  4354. tempIndex = 2;
  4355. }
  4356. else
  4357. {
  4358. tempIndex = gun_index;
  4359. }
  4360. for (int index = 0; index < AC_QUANTITY; index++)
  4361. {
  4362. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4363. {
  4364. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  4365. }
  4366. }// End of for AC_QUANTITY
  4367. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  4368. }
  4369. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4370. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  4371. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  4372. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  4373. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4374. }
  4375. // ================================= Current.Import L3 ===============================================
  4376. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4377. {
  4378. // AC 3 phse L3 current
  4379. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4380. {
  4381. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4382. {
  4383. tempIndex = 2;
  4384. }
  4385. else
  4386. {
  4387. tempIndex = gun_index;
  4388. }
  4389. for (int index = 0; index < AC_QUANTITY; index++)
  4390. {
  4391. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4392. {
  4393. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  4394. }
  4395. }// End of for AC_QUANTITY
  4396. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  4397. }
  4398. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4399. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  4400. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  4401. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  4402. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4403. }
  4404. //============================ Voltage L2 ====================================
  4405. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4406. {
  4407. // AC 3 phse L2 voltage
  4408. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4409. {
  4410. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4411. {
  4412. tempIndex = 2;
  4413. }
  4414. else
  4415. {
  4416. tempIndex = gun_index;
  4417. }
  4418. for (int index = 0; index < AC_QUANTITY; index++)
  4419. {
  4420. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4421. {
  4422. 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
  4423. }
  4424. } // END OF FOR AC_QUANTITY
  4425. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  4426. }
  4427. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4428. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  4429. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  4430. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  4431. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4432. }
  4433. //============================ Voltage L3 ====================================
  4434. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4435. {
  4436. // AC 3 phse L3 voltage
  4437. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4438. {
  4439. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4440. {
  4441. tempIndex = 2;
  4442. }
  4443. else
  4444. {
  4445. tempIndex = gun_index;
  4446. }
  4447. for (int index = 0; index < AC_QUANTITY; index++)
  4448. {
  4449. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4450. {
  4451. 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
  4452. }
  4453. } // END OF FOR AC_QUANTITY
  4454. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  4455. }
  4456. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4457. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  4458. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  4459. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  4460. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4461. }
  4462. //====================== Start SoC ================================
  4463. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4464. {
  4465. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4466. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  4467. {
  4468. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4469. {
  4470. tempIndex = ((gun_index==2) ? 1: 0);
  4471. }
  4472. else
  4473. {
  4474. tempIndex = gun_index;
  4475. }
  4476. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4477. {
  4478. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4479. {
  4480. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4481. {
  4482. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  4483. }
  4484. }
  4485. }
  4486. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4487. {
  4488. for (int index = 0; index < CCS_QUANTITY; index++)
  4489. {
  4490. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4491. {
  4492. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  4493. }
  4494. }
  4495. }
  4496. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4497. {
  4498. for (int index = 0; index < GB_QUANTITY; index++)
  4499. {
  4500. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4501. {
  4502. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  4503. }
  4504. }
  4505. }
  4506. else if(gunType[gun_index] == GUN_TYPE_DO)
  4507. {
  4508. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4509. {
  4510. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4511. {
  4512. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  4513. }
  4514. }
  4515. }
  4516. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4517. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  4518. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4519. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  4520. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  4521. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4522. } // END FOR DC CASE
  4523. }
  4524. //================================================ Message create ====================================================
  4525. json_object *StopTransaction = json_object_new_object();
  4526. json_object *transactionDatas = json_object_new_array();
  4527. json_object *sampledValues = json_object_new_array();
  4528. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  4529. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  4530. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  4531. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  4532. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  4533. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  4534. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  4535. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  4536. {
  4537. json_object *transactionData = json_object_new_object();
  4538. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  4539. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  4540. {
  4541. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  4542. {
  4543. json_object *sampledValue = json_object_new_object();
  4544. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  4545. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  4546. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  4547. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  4548. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  4549. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  4550. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  4551. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  4552. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  4553. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  4554. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  4555. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  4556. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  4557. json_object_array_add(sampledValues, sampledValue);
  4558. }
  4559. }
  4560. json_object_object_add(transactionData, "sampledValue", sampledValues);
  4561. json_object_array_add(transactionDatas, transactionData);
  4562. }
  4563. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  4564. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  4565. ,MESSAGE_TYPE_CALL
  4566. ,guid
  4567. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  4568. json_object_put(StopTransaction);
  4569. #if 1 // for TempStopTransaction
  4570. //Delete TempStopTransaction
  4571. if((access(TempStopTransaction,F_OK))!=-1)
  4572. {
  4573. remove(TempStopTransaction); // remove file "TempStopTransaction"
  4574. }
  4575. #endif
  4576. #if 1
  4577. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4578. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4579. {
  4580. result = PASS;
  4581. //DEBUG_INFO("StopTransaction mapitem pass\n");
  4582. }
  4583. #endif
  4584. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4585. OCPP_insert_transaction_msg(NO, queuedata);
  4586. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4587. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4588. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  4589. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4590. {
  4591. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4592. }
  4593. //for test
  4594. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4595. return result;
  4596. }
  4597. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4598. {
  4599. mtrace();
  4600. int result = FAIL;
  4601. char guid[37]={0};
  4602. char tempdata[65]={0};
  4603. int tempIndex = 0;
  4604. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4605. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4606. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  4607. //set value
  4608. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4609. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (((strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging") != NULL) || (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "SuspendedEV") != NULL) || (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "SuspendedEVSE") != NULL) )?
  4610. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  4611. -1);
  4612. random_uuid(guid);
  4613. //UTC Date time
  4614. struct timeval tmnow;
  4615. struct tm *tm;
  4616. char buf[28];//, usec_buf[6];
  4617. gettimeofday(&tmnow, NULL);
  4618. time_t t;
  4619. t = time(NULL);
  4620. /*UTC time and date*/
  4621. tm = gmtime(&t);
  4622. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4623. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4624. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4625. //********************************(1)Current.Import L1************************************************/
  4626. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  4627. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  4628. (dataType == ReadingContext_Trigger))
  4629. {
  4630. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4631. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4632. {
  4633. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4634. {
  4635. tempIndex = ((gun_index==2) ? 1: 0);
  4636. }
  4637. else
  4638. {
  4639. tempIndex = gun_index;
  4640. }
  4641. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4642. {
  4643. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4644. {
  4645. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4646. }
  4647. }
  4648. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4649. }
  4650. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4651. {
  4652. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4653. {
  4654. tempIndex = ((gun_index==2) ? 1: 0);
  4655. }
  4656. else
  4657. {
  4658. tempIndex = gun_index;
  4659. }
  4660. for (int index = 0; index < CCS_QUANTITY; index++)
  4661. {
  4662. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4663. {
  4664. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4665. }
  4666. }
  4667. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4668. }
  4669. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4670. {
  4671. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4672. {
  4673. tempIndex = ((gun_index==2) ? 1: 0);
  4674. }
  4675. else
  4676. {
  4677. tempIndex = gun_index;
  4678. }
  4679. for (int index = 0; index < GB_QUANTITY; index++)
  4680. {
  4681. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4682. {
  4683. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4684. }
  4685. }
  4686. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4687. }
  4688. else if(gunType[gun_index] == GUN_TYPE_DO)
  4689. {
  4690. tempIndex = gun_index;
  4691. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4692. {
  4693. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4694. {
  4695. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  4696. }
  4697. }
  4698. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4699. }
  4700. else
  4701. {
  4702. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4703. {
  4704. tempIndex = 2;
  4705. }
  4706. else
  4707. {
  4708. tempIndex = gun_index;
  4709. }
  4710. for (int index = 0; index < AC_QUANTITY; index++)
  4711. {
  4712. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4713. {
  4714. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4715. }
  4716. }
  4717. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4718. }
  4719. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4720. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4721. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4722. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4723. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4724. }
  4725. //********************************(2)Energy.Active.Import.Register ************************************************/
  4726. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4727. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4728. (dataType == ReadingContext_Trigger))
  4729. {
  4730. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4731. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4732. {
  4733. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4734. {
  4735. tempIndex = ((gun_index==2) ? 1: 0);
  4736. }
  4737. else
  4738. {
  4739. tempIndex = gun_index;
  4740. }
  4741. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4742. {
  4743. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4744. {
  4745. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4746. }
  4747. }
  4748. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4749. }
  4750. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4751. {
  4752. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4753. {
  4754. tempIndex = ((gun_index==2) ? 1: 0);
  4755. }
  4756. else
  4757. {
  4758. tempIndex = gun_index;
  4759. }
  4760. for (int index = 0; index < CCS_QUANTITY; index++)
  4761. {
  4762. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4763. {
  4764. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4765. }
  4766. }
  4767. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4768. }
  4769. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4770. {
  4771. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4772. {
  4773. tempIndex = ((gun_index==2) ? 1: 0);
  4774. }
  4775. else
  4776. {
  4777. tempIndex = gun_index;
  4778. }
  4779. for (int index = 0; index < GB_QUANTITY; index++)
  4780. {
  4781. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4782. {
  4783. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4784. }
  4785. }
  4786. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4787. }
  4788. else if(gunType[gun_index] == GUN_TYPE_DO)
  4789. {
  4790. tempIndex = gun_index;
  4791. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4792. {
  4793. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4794. {
  4795. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  4796. }
  4797. }
  4798. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4799. }
  4800. else
  4801. {
  4802. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4803. {
  4804. tempIndex = 2;
  4805. }
  4806. else
  4807. {
  4808. tempIndex = gun_index;
  4809. }
  4810. for (int index = 0; index < AC_QUANTITY; index++)
  4811. {
  4812. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4813. {
  4814. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4815. }
  4816. }
  4817. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4818. }
  4819. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  4820. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4821. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4822. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4823. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4824. }
  4825. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  4826. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  4827. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  4828. (dataType == ReadingContext_Trigger))
  4829. {
  4830. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4831. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4832. {
  4833. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4834. {
  4835. tempIndex = ((gun_index==2) ? 1: 0);
  4836. }
  4837. else
  4838. {
  4839. tempIndex = gun_index;
  4840. }
  4841. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4842. {
  4843. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4844. {
  4845. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4846. }
  4847. } // END OF FOR CHAdeMO_QUANTITY
  4848. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4849. }
  4850. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4851. {
  4852. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4853. {
  4854. tempIndex = ((gun_index==2) ? 1: 0);
  4855. }
  4856. else
  4857. {
  4858. tempIndex = gun_index;
  4859. }
  4860. for (int index = 0; index < CCS_QUANTITY; index++)
  4861. {
  4862. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4863. {
  4864. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  4865. }
  4866. } // END OF CCS_QUANTITY
  4867. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4868. }
  4869. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4870. {
  4871. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4872. {
  4873. tempIndex = ((gun_index==2) ? 1: 0);
  4874. }
  4875. else
  4876. {
  4877. tempIndex = gun_index;
  4878. }
  4879. for (int index = 0; index < GB_QUANTITY; index++)
  4880. {
  4881. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4882. {
  4883. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  4884. }
  4885. } // END OF GB_QUANTITY
  4886. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4887. }
  4888. else if(gunType[gun_index] == GUN_TYPE_DO)
  4889. {
  4890. tempIndex = gun_index;
  4891. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4892. {
  4893. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4894. {
  4895. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  4896. }
  4897. }
  4898. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4899. }
  4900. else
  4901. {
  4902. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4903. {
  4904. tempIndex = 2;
  4905. }
  4906. else
  4907. {
  4908. tempIndex = gun_index;
  4909. }
  4910. for (int index = 0; index < AC_QUANTITY; index++)
  4911. {
  4912. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4913. {
  4914. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  4915. }
  4916. }
  4917. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  4918. }
  4919. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  4920. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  4921. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  4922. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  4923. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4924. }
  4925. //********************************(4)Power.Active.Import************************************************/
  4926. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Power.Active.Import") != NULL)) ||
  4927. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Power.Active.Import") != NULL)) ||
  4928. (dataType == ReadingContext_Trigger))
  4929. {
  4930. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4931. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4932. {
  4933. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4934. {
  4935. tempIndex = ((gun_index==2) ? 1: 0);
  4936. }
  4937. else
  4938. {
  4939. tempIndex = gun_index;
  4940. }
  4941. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4942. {
  4943. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4944. {
  4945. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  4946. }
  4947. } // END OF FOR
  4948. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4949. }
  4950. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4951. {
  4952. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4953. {
  4954. tempIndex = ((gun_index==2) ? 1: 0);
  4955. }
  4956. else
  4957. {
  4958. tempIndex = gun_index;
  4959. }
  4960. for (int index = 0; index < CCS_QUANTITY; index++)
  4961. {
  4962. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4963. {
  4964. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  4965. }
  4966. }
  4967. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4968. }
  4969. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4970. {
  4971. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4972. {
  4973. tempIndex = ((gun_index==2) ? 1: 0);
  4974. }
  4975. else
  4976. {
  4977. tempIndex = gun_index;
  4978. }
  4979. for (int index = 0; index < GB_QUANTITY; index++)
  4980. {
  4981. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4982. {
  4983. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4984. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  4985. }
  4986. }
  4987. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4988. }
  4989. else if(gunType[gun_index] == GUN_TYPE_DO)
  4990. {
  4991. tempIndex = gun_index;
  4992. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4993. {
  4994. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4995. {
  4996. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4997. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  4998. }
  4999. }
  5000. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5001. }
  5002. else
  5003. {
  5004. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5005. {
  5006. tempIndex = 2;
  5007. }
  5008. else
  5009. {
  5010. tempIndex = gun_index;
  5011. }
  5012. for (int index = 0; index < AC_QUANTITY; index++)
  5013. {
  5014. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5015. {
  5016. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  5017. }
  5018. }
  5019. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  5020. }
  5021. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  5022. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  5023. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  5024. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  5025. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  5026. }
  5027. //***********************************************(5)VOLTAGE L1******************************************************/
  5028. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5029. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5030. (dataType == ReadingContext_Trigger))
  5031. {
  5032. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5033. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5034. {
  5035. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5036. {
  5037. tempIndex = ((gun_index==2) ? 1: 0);
  5038. }
  5039. else
  5040. {
  5041. tempIndex = gun_index;
  5042. }
  5043. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5044. {
  5045. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5046. {
  5047. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  5048. }
  5049. }
  5050. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5051. }
  5052. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5053. {
  5054. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5055. {
  5056. tempIndex = ((gun_index==2) ? 1: 0);
  5057. }
  5058. else
  5059. {
  5060. tempIndex = gun_index;
  5061. }
  5062. for (int index = 0; index < CCS_QUANTITY; index++)
  5063. {
  5064. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5065. {
  5066. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  5067. }
  5068. }
  5069. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5070. }
  5071. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5072. {
  5073. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5074. {
  5075. tempIndex = ((gun_index==2) ? 1: 0);
  5076. }
  5077. else
  5078. {
  5079. tempIndex = gun_index;
  5080. }
  5081. for (int index = 0; index < GB_QUANTITY; index++)
  5082. {
  5083. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5084. {
  5085. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  5086. }
  5087. }
  5088. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5089. }
  5090. else if(gunType[gun_index] == GUN_TYPE_DO)
  5091. {
  5092. tempIndex = gun_index;
  5093. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5094. {
  5095. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5096. {
  5097. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  5098. }
  5099. }
  5100. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5101. }
  5102. else
  5103. {
  5104. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5105. {
  5106. tempIndex = 2;
  5107. }
  5108. else
  5109. {
  5110. tempIndex = gun_index;
  5111. }
  5112. for (int index = 0; index < AC_QUANTITY; index++)
  5113. {
  5114. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5115. {
  5116. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  5117. }
  5118. }
  5119. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  5120. }
  5121. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  5122. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  5123. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  5124. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  5125. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5126. }
  5127. //***********************************************(6)SOC******************************************************/
  5128. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "SOC") != NULL)) ||
  5129. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "SOC") != NULL)) ||
  5130. (dataType == ReadingContext_Trigger))
  5131. {
  5132. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  5133. {
  5134. //idx_sample=5;
  5135. //sampledValue = NULL;
  5136. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5137. {
  5138. tempIndex = ((gun_index==2) ? 1: 0);
  5139. }
  5140. else
  5141. {
  5142. tempIndex = gun_index;
  5143. }
  5144. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5145. {
  5146. //tempIndex = ((gun_index==2) ? 1: 0);
  5147. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5148. {
  5149. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5150. {
  5151. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  5152. }
  5153. }
  5154. }
  5155. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5156. {
  5157. //tempIndex = ((gun_index==2) ? 1: 0);
  5158. for (int index = 0; index < CCS_QUANTITY; index++)
  5159. {
  5160. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5161. {
  5162. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  5163. }
  5164. }
  5165. }
  5166. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5167. {
  5168. //tempIndex = ((gun_index==2) ? 1: 0);
  5169. for (int index = 0; index < GB_QUANTITY; index++)
  5170. {
  5171. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5172. {
  5173. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  5174. }
  5175. }
  5176. }
  5177. else if(gunType[gun_index] == GUN_TYPE_DO)
  5178. {
  5179. //tempIndex = ((gun_index==2) ? 1: 0);
  5180. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5181. {
  5182. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5183. {
  5184. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  5185. }
  5186. }
  5187. }
  5188. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  5189. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  5190. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  5191. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  5192. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  5193. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  5194. }
  5195. }
  5196. //********************************(7)Current.Import L2************************************************/
  5197. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5198. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5199. (dataType == ReadingContext_Trigger))
  5200. {
  5201. // Only for AC 3 phase
  5202. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5203. {
  5204. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5205. {
  5206. tempIndex = 2;
  5207. }
  5208. else
  5209. {
  5210. tempIndex = gun_index;
  5211. }
  5212. for (int index = 0; index < AC_QUANTITY; index++)
  5213. {
  5214. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5215. {
  5216. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  5217. }
  5218. }
  5219. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  5220. }
  5221. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  5222. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  5223. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  5224. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  5225. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5226. }
  5227. //********************************(8)Current.Import L3************************************************/
  5228. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5229. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5230. (dataType == ReadingContext_Trigger))
  5231. {
  5232. // Only for AC 3 phase
  5233. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5234. {
  5235. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5236. {
  5237. tempIndex = 2;
  5238. }
  5239. else
  5240. {
  5241. tempIndex = gun_index;
  5242. }
  5243. for (int index = 0; index < AC_QUANTITY; index++)
  5244. {
  5245. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5246. {
  5247. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  5248. }
  5249. }
  5250. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  5251. }
  5252. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  5253. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  5254. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  5255. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  5256. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5257. }
  5258. //***********************************************(9)VOLTAGE L2******************************************************/
  5259. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5260. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5261. (dataType == ReadingContext_Trigger))
  5262. {
  5263. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5264. {
  5265. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5266. {
  5267. tempIndex = 2;
  5268. }
  5269. else
  5270. {
  5271. tempIndex = gun_index;
  5272. }
  5273. for (int index = 0; index < AC_QUANTITY; index++)
  5274. {
  5275. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5276. {
  5277. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  5278. }
  5279. }
  5280. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  5281. }
  5282. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  5283. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  5284. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  5285. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  5286. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5287. }
  5288. //***********************************************(10)VOLTAGE L3******************************************************/
  5289. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5290. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5291. (dataType == ReadingContext_Trigger))
  5292. {
  5293. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5294. {
  5295. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5296. {
  5297. tempIndex = 2;
  5298. }
  5299. else
  5300. {
  5301. tempIndex = gun_index;
  5302. }
  5303. for (int index = 0; index < AC_QUANTITY; index++)
  5304. {
  5305. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5306. {
  5307. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  5308. }
  5309. }
  5310. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  5311. }
  5312. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  5313. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  5314. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  5315. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  5316. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5317. }
  5318. // Message create ====================================================================================================
  5319. if(TRUE)
  5320. {
  5321. json_object *MeterValueReq = json_object_new_object();
  5322. json_object *MeterValues = json_object_new_array();
  5323. json_object *sampledValues = json_object_new_array();
  5324. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  5325. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  5326. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  5327. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  5328. {
  5329. json_object *MeterValue = json_object_new_object();
  5330. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  5331. {
  5332. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  5333. {
  5334. json_object *sampledValue = json_object_new_object();
  5335. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  5336. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  5337. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  5338. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  5339. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  5340. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  5341. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  5342. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  5343. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  5344. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  5345. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  5346. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  5347. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  5348. json_object_array_add(sampledValues, sampledValue);
  5349. }
  5350. }
  5351. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  5352. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  5353. json_object_array_add(MeterValues, MeterValue);
  5354. }
  5355. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  5356. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  5357. ,gun_index + 1
  5358. ,MESSAGE_TYPE_CALL
  5359. ,guid
  5360. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  5361. json_object_put(MeterValueReq);
  5362. }
  5363. // Put request guid to hash map
  5364. sprintf(tempdata, "MeterValues,%d", (gun_index));
  5365. 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*/)
  5366. {
  5367. result = PASS;
  5368. //DEBUG_INFO("MeterValues mapitem pass\n");
  5369. }
  5370. if((dataType != ReadingContext_Trigger) &&
  5371. (dataType != ReadingContext_Sample_Clock) &&
  5372. (ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1))
  5373. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  5374. else
  5375. {
  5376. if(FirstHeartBeat)
  5377. LWS_Send(queuedata +2);
  5378. }
  5379. return result;
  5380. }
  5381. //==========================================
  5382. // send confirm routine
  5383. //==========================================
  5384. int sendCancelReservationConfirmation(char *uuid,char *payload)
  5385. {
  5386. mtrace();
  5387. int result = FAIL;
  5388. char message[100]={0};
  5389. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  5390. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5391. LWS_Send(message);
  5392. result = TRUE;
  5393. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  5394. return result;
  5395. }
  5396. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  5397. {
  5398. mtrace();
  5399. int result = FAIL;
  5400. char message[100]={0};
  5401. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  5402. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5403. LWS_Send(message);
  5404. result = TRUE;
  5405. return result;
  5406. }
  5407. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  5408. {
  5409. mtrace();
  5410. int result = FAIL;
  5411. char message[100]={0};
  5412. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  5413. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5414. LWS_Send(message);
  5415. result = TRUE;
  5416. return result;
  5417. }
  5418. int sendClearCacheConfirmation(char *uuid,char *payload)
  5419. {
  5420. mtrace();
  5421. int result = FAIL;
  5422. char message[500]={0};
  5423. DEBUG_INFO("sendClearCacheConfirmation...\n");
  5424. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5425. LWS_Send(message);
  5426. return result;
  5427. }
  5428. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  5429. {
  5430. mtrace();
  5431. int result = FAIL;
  5432. char message[500]={0};
  5433. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  5434. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5435. LWS_Send(message);
  5436. return result;
  5437. }
  5438. int sendDataTransferConfirmation(char *uuid,char *payload)
  5439. {
  5440. mtrace();
  5441. char statusStr[20]={0};
  5442. char dataStr[10]={0};
  5443. char sstr[20]={0};
  5444. int c = 0;
  5445. char *loc;
  5446. int result = FAIL;
  5447. DEBUG_INFO("sendDataTransferConfirmation...\n");
  5448. /**********************status**************************/
  5449. loc = strstr(payload, "status");
  5450. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5451. c = 0;
  5452. while (loc[3+strlen("status")+c] != '\"')
  5453. {
  5454. sstr[c] = loc[3+strlen("status")+c];
  5455. c++;
  5456. }
  5457. sstr[c] = '\0';
  5458. strcpy(statusStr, sstr);
  5459. /**********************data**************************/
  5460. loc = strstr(payload, "data");
  5461. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5462. c = 0;
  5463. while (loc[3+strlen("data")+c] != '\"')
  5464. {
  5465. sstr[c] = loc[3+strlen("data")+c];
  5466. c++;
  5467. }
  5468. sstr[c] = '\0';
  5469. strcpy(dataStr, sstr);
  5470. return result;
  5471. }
  5472. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  5473. {
  5474. mtrace();
  5475. int result = FAIL;
  5476. char message[1000]={0};
  5477. int CompositeScheduleIndex = 0;
  5478. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  5479. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  5480. if(nPeriod == 0)
  5481. {
  5482. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  5483. {
  5484. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  5485. ,MESSAGE_TYPE_CALLRESULT
  5486. ,uuid
  5487. ,payload
  5488. ,connectorIdInt);
  5489. }
  5490. else
  5491. {
  5492. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  5493. ,MESSAGE_TYPE_CALLRESULT
  5494. ,uuid
  5495. ,payload
  5496. ,connectorIdInt
  5497. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5498. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5499. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5500. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  5501. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  5502. }
  5503. }
  5504. else
  5505. {
  5506. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  5507. ,MESSAGE_TYPE_CALLRESULT
  5508. ,uuid
  5509. ,payload
  5510. ,connectorIdInt
  5511. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5512. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5513. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5514. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  5515. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  5516. {
  5517. if (idx_sample == 0)
  5518. {
  5519. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5520. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5521. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5522. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5523. }
  5524. else
  5525. {
  5526. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5527. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5528. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5529. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5530. }
  5531. }
  5532. sprintf(message + strlen(message), "]}}]");
  5533. }
  5534. LWS_Send(message);
  5535. result = TRUE;
  5536. return result;
  5537. }
  5538. int sendGetConfigurationConfirmation(char *uuid)
  5539. {
  5540. mtrace();
  5541. int result = FAIL;
  5542. int MaxKeySupported = 0;
  5543. int sentConfigurationNumber= 0;
  5544. int sentunConfigurationNumber= 0;
  5545. char message[4000]={0};
  5546. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5547. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5548. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5549. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5550. ,MESSAGE_TYPE_CALLRESULT
  5551. ,uuid );
  5552. //configuration key
  5553. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5554. {
  5555. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5556. {
  5557. if (sentConfigurationNumber == 0)
  5558. {
  5559. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5560. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5561. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5562. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5563. }
  5564. else
  5565. {
  5566. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5567. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5568. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5569. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5570. }
  5571. sentConfigurationNumber = sentConfigurationNumber + 1;
  5572. }
  5573. }
  5574. sprintf(message + strlen(message), "]");
  5575. if(UnknownKeynum != 0)
  5576. {
  5577. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5578. //unkown key
  5579. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5580. {
  5581. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5582. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5583. if(sentunConfigurationNumber == 0)
  5584. {
  5585. sprintf(message + strlen(message), "\"%s\""
  5586. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5587. }
  5588. else
  5589. {
  5590. sprintf(message + strlen(message), ",\"%s\""
  5591. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5592. }
  5593. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5594. }
  5595. sprintf(message + strlen(message), "]");
  5596. }
  5597. sprintf(message + strlen(message), "}]");
  5598. LWS_Send(message);
  5599. return result;
  5600. }
  5601. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5602. {
  5603. mtrace();
  5604. int result = FAIL;
  5605. char message[400]={0};
  5606. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5607. if(strcmp(payload,"")==0)
  5608. {
  5609. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5610. }
  5611. else
  5612. {
  5613. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5614. }
  5615. LWS_Send(message);
  5616. result = TRUE;
  5617. return result;
  5618. }
  5619. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5620. {
  5621. mtrace();
  5622. int result = FAIL;
  5623. char message[80]={0};
  5624. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5625. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  5626. LWS_Send(message);
  5627. result = TRUE;
  5628. return result;
  5629. }
  5630. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5631. {
  5632. mtrace();
  5633. int result = FAIL;
  5634. char message[80]={0};
  5635. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5636. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5637. LWS_Send(message);
  5638. result = TRUE;
  5639. return result;
  5640. }
  5641. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5642. {
  5643. mtrace();
  5644. int result = FAIL;
  5645. char message[80]={0};
  5646. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5647. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5648. LWS_Send(message);
  5649. result = TRUE;
  5650. return result;
  5651. }
  5652. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5653. {
  5654. mtrace();
  5655. int result = FAIL;
  5656. char message[80]={0};
  5657. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5658. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5659. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5660. LWS_Send(message);
  5661. result = TRUE;
  5662. return result;
  5663. }
  5664. int sendResetConfirmation(char *uuid,char *payload)
  5665. {
  5666. mtrace();
  5667. int result = FAIL;
  5668. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  5669. char message[80]={0};
  5670. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  5671. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5672. LWS_Send(message);
  5673. result = TRUE;
  5674. return result;
  5675. }
  5676. int sendSendLocalListConfirmation(char *uuid,char *payload)
  5677. {
  5678. mtrace();
  5679. int result = FAIL;
  5680. char message[500]={0};
  5681. // [ 3, "1571284266109", { "status": "Accepted" } ]
  5682. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5683. LWS_Send(message);
  5684. result = TRUE;
  5685. return result;
  5686. }
  5687. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  5688. {
  5689. mtrace();
  5690. int result = FAIL;
  5691. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  5692. char message[80]={0};
  5693. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  5694. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5695. LWS_Send(message);
  5696. result = TRUE;
  5697. return result;
  5698. }
  5699. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  5700. {
  5701. mtrace();
  5702. int result = FAIL;
  5703. char message[80]={0};
  5704. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  5705. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5706. LWS_Send(message);
  5707. result = TRUE;
  5708. return result;
  5709. }
  5710. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  5711. {
  5712. mtrace();
  5713. int result = FAIL;
  5714. char message[80]={0};
  5715. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5716. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  5717. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5718. LWS_Send(message);
  5719. result = TRUE;
  5720. return result;
  5721. }
  5722. int sendUpdateFirmwareConfirmation(char *uuid)
  5723. {
  5724. mtrace();
  5725. int result = FAIL;
  5726. char message[60]={0};
  5727. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5728. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  5729. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5730. LWS_Send(message);
  5731. result = TRUE;
  5732. return result;
  5733. }
  5734. //==========================================
  5735. // Handle server request routine Start
  5736. //==========================================
  5737. int handleCancelReservationRequest(char *uuid, char *payload)
  5738. {
  5739. mtrace();
  5740. int result = FAIL;
  5741. int gunNO = 0;
  5742. int reservationIdInt = -1;
  5743. char comfirmstr[20];
  5744. DEBUG_INFO("handleCancelReservationRequest...\n");
  5745. json_object *CancelReservation;
  5746. CancelReservation = json_tokener_parse(payload);
  5747. if(!is_error(CancelReservation))
  5748. {
  5749. // Required data
  5750. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  5751. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  5752. }
  5753. json_object_put(CancelReservation);
  5754. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  5755. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5756. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  5757. if(reservationIdInt != -1)
  5758. {
  5759. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  5760. //check Transaction active
  5761. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5762. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5763. {
  5764. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  5765. {
  5766. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5767. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5768. if(gunType[2] == GUN_TYPE_CHAdeMO)
  5769. {
  5770. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  5771. }
  5772. else
  5773. {
  5774. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  5775. }
  5776. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5777. goto end;
  5778. }
  5779. }
  5780. for (int index = 0; index < CCS_QUANTITY; index++)
  5781. {
  5782. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  5783. {
  5784. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5785. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5786. if(gunType[2] == GUN_TYPE_CCS)
  5787. {
  5788. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  5789. }
  5790. else
  5791. {
  5792. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  5793. }
  5794. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5795. goto end;
  5796. }
  5797. }
  5798. for (int index = 0; index < GB_QUANTITY; index++)
  5799. {
  5800. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  5801. {
  5802. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5803. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5804. if(gunType[2] == GUN_TYPE_GBT)
  5805. {
  5806. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  5807. }
  5808. else
  5809. {
  5810. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  5811. }
  5812. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5813. goto end;
  5814. }
  5815. }
  5816. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5817. {
  5818. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  5819. {
  5820. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5821. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5822. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  5823. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5824. goto end;
  5825. }
  5826. }
  5827. for (int index = 0; index < AC_QUANTITY; index++)
  5828. {
  5829. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  5830. {
  5831. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5832. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5833. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5834. {
  5835. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  5836. }
  5837. else
  5838. {
  5839. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  5840. }
  5841. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5842. goto end;
  5843. }
  5844. }
  5845. }
  5846. //The reservationId does NOT match the reservationId
  5847. sendCancelReservationConfirmation(uuid, comfirmstr);
  5848. end:
  5849. // Fill in ocpp packet uuid
  5850. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  5851. return result;
  5852. }
  5853. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  5854. {
  5855. mtrace();
  5856. int result = FAIL;
  5857. int gunIndex = 0;
  5858. char typeStr[16]={0};
  5859. char comfirmstr[20];
  5860. int specificId = FALSE;
  5861. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  5862. json_object *ChangeAvailability;
  5863. ChangeAvailability = json_tokener_parse(payload);
  5864. if(!is_error(ChangeAvailability))
  5865. {
  5866. // Required data
  5867. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  5868. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  5869. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  5870. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  5871. }
  5872. json_object_put(ChangeAvailability);
  5873. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5874. {
  5875. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  5876. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  5877. }
  5878. else if(gunIndex == 0)
  5879. {
  5880. for(int i=0; i < gunTotalNumber; i++)
  5881. {
  5882. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  5883. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  5884. }
  5885. }
  5886. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5887. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5888. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  5889. {
  5890. specificId = TRUE;
  5891. }
  5892. if(specificId == FALSE)
  5893. goto end;
  5894. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  5895. {
  5896. //----------------------gunIndex is 0 ------------------------------------------------//
  5897. if(gunIndex == 0)
  5898. {
  5899. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5900. {
  5901. for(int i=0; i < gunTotalNumber; i++)
  5902. {
  5903. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5904. {
  5905. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  5906. {
  5907. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5908. {
  5909. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5910. goto end;
  5911. }
  5912. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5913. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5914. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5915. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5916. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5917. {
  5918. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5919. goto end;
  5920. }
  5921. }
  5922. }//END FOR CHAdeMO_QUANTITY
  5923. for (int index = 0; index < CCS_QUANTITY; index++)
  5924. {
  5925. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  5926. {
  5927. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  5928. {
  5929. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5930. goto end;
  5931. }
  5932. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5933. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5934. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5935. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5936. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5937. {
  5938. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5939. goto end;
  5940. }
  5941. }
  5942. }//END FOR CCS_QUANTITY
  5943. for (int index = 0; index < GB_QUANTITY; index++)
  5944. {
  5945. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  5946. {
  5947. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5948. {
  5949. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5950. goto end;
  5951. }
  5952. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5953. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5954. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5955. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5956. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5957. {
  5958. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5959. goto end;
  5960. }
  5961. }
  5962. }// END FOR GB_QUANTITY
  5963. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5964. {
  5965. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  5966. {
  5967. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5968. {
  5969. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5970. goto end;
  5971. }
  5972. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  5973. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  5974. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  5975. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  5976. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5977. {
  5978. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5979. goto end;
  5980. }
  5981. }
  5982. }// END FOR GENERAL_GUN_QUANTITY
  5983. for (int index = 0; index < AC_QUANTITY; index++)
  5984. {
  5985. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  5986. {
  5987. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5988. {
  5989. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5990. goto end;
  5991. }
  5992. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5993. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5994. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5995. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5996. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5997. {
  5998. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5999. goto end;
  6000. }
  6001. }
  6002. }//END FOR AC_QUANTITY
  6003. }// END FOR gunTotalNumber
  6004. }
  6005. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6006. {
  6007. for(int i=0; i < gunTotalNumber; i++)
  6008. {
  6009. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6010. {
  6011. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6012. goto end;
  6013. }
  6014. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6015. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  6016. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  6017. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  6018. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6019. {
  6020. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6021. goto end;
  6022. }
  6023. }
  6024. }
  6025. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6026. goto end;
  6027. }
  6028. //----------------------gunIndex is not 0 ------------------------------------------------//
  6029. //check Transaction active
  6030. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6031. {
  6032. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  6033. {
  6034. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  6035. {
  6036. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6037. goto end;
  6038. }
  6039. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6040. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6041. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6042. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6043. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6044. {
  6045. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6046. goto end;
  6047. }
  6048. else
  6049. {
  6050. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  6051. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6052. goto end;
  6053. }
  6054. }
  6055. }//END FOR CHAdeMO_QUANTITY
  6056. for (int index = 0; index < CCS_QUANTITY; index++)
  6057. {
  6058. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  6059. {
  6060. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  6061. {
  6062. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6063. goto end;
  6064. }
  6065. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6066. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6067. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6068. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6069. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6070. {
  6071. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6072. goto end;
  6073. }
  6074. else
  6075. {
  6076. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  6077. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6078. goto end;
  6079. }
  6080. }
  6081. }//END FOR CCS_QUANTITY
  6082. for (int index = 0; index < GB_QUANTITY; index++)
  6083. {
  6084. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  6085. {
  6086. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6087. {
  6088. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6089. goto end;
  6090. }
  6091. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6092. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6093. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6094. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6095. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6096. {
  6097. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6098. goto end;
  6099. }
  6100. else
  6101. {
  6102. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  6103. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6104. goto end;
  6105. }
  6106. }
  6107. }// END FOR GB_QUANTITY
  6108. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6109. {
  6110. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  6111. {
  6112. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6113. {
  6114. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6115. goto end;
  6116. }
  6117. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6118. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6119. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6120. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6121. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6122. {
  6123. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6124. goto end;
  6125. }
  6126. else
  6127. {
  6128. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  6129. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6130. goto end;
  6131. }
  6132. }
  6133. }// END FOR GENERAL_GUN_QUANTITY
  6134. for (int index = 0; index < AC_QUANTITY; index++)
  6135. {
  6136. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  6137. {
  6138. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6139. {
  6140. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6141. goto end;
  6142. }
  6143. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6144. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6145. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6146. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6147. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6148. {
  6149. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6150. goto end;
  6151. }
  6152. else
  6153. {
  6154. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  6155. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6156. goto end;
  6157. }
  6158. }
  6159. }//END FOR AC_QUANTITY
  6160. }//END FOR AvailabilityTypeStr[Inoperative]
  6161. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  6162. {
  6163. //----------------------gunIndex is 0 ------------------------------------------------//
  6164. if(gunIndex == 0)
  6165. {
  6166. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6167. {
  6168. for(int i=0; i < gunTotalNumber; i++)
  6169. {
  6170. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6171. {
  6172. if ((gunType[i] == GUN_TYPE_CHAdeMO )&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO)) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6173. {
  6174. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6175. goto end;
  6176. }
  6177. }//END FOR CHAdeMO_QUANTITY
  6178. for (int index = 0; index < CCS_QUANTITY; index++)
  6179. {
  6180. if ((gunType[i] == GUN_TYPE_CCS)&&(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
  6181. {
  6182. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6183. goto end;
  6184. }
  6185. }//END FOR CCS_QUANTITY
  6186. for (int index = 0; index < GB_QUANTITY; index++)
  6187. {
  6188. if ((gunType[i] == GUN_TYPE_GBT)&&(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
  6189. {
  6190. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6191. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6192. goto end;
  6193. }
  6194. }// END FOR GB_QUANTITY
  6195. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6196. {
  6197. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'O')))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6198. {
  6199. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6200. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6201. goto end;
  6202. }
  6203. }// END FOR GENERAL_GUN_QUANTITY
  6204. for (int index = 0; index < AC_QUANTITY; index++)
  6205. {
  6206. if ((gunType[i] == GUN_TYPE_AC) &&(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
  6207. {
  6208. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6209. goto end;
  6210. }
  6211. }//END FOR CHAdeMO_QUANTITY
  6212. }// END FOR gunTotalNumber
  6213. }
  6214. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6215. {
  6216. for(int i=0; i < gunTotalNumber; i++)
  6217. {
  6218. for (int index = 0; index < AC_QUANTITY; index++)
  6219. {
  6220. if ((gunType[i] == GUN_TYPE_AC) &&(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
  6221. {
  6222. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6223. goto end;
  6224. }
  6225. }//END FOR CHAdeMO_QUANTITY
  6226. } // END FOR gunTotalNumber
  6227. }
  6228. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6229. goto end;
  6230. }
  6231. //----------------------gunIndex is not 0 ------------------------------------------------//
  6232. //check Transaction active
  6233. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6234. {
  6235. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6236. {
  6237. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6238. goto end;
  6239. }
  6240. }//END FOR CHAdeMO_QUANTITY
  6241. for (int index = 0; index < CCS_QUANTITY; index++)
  6242. {
  6243. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6244. {
  6245. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6246. goto end;
  6247. }
  6248. }//END FOR CCS_QUANTITY
  6249. for (int index = 0; index < GB_QUANTITY; index++)
  6250. {
  6251. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6252. {
  6253. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6254. goto end;
  6255. }
  6256. }// END FOR GB_QUANTITY
  6257. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6258. {
  6259. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6260. {
  6261. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6262. goto end;
  6263. }
  6264. }// END FOR GENERAL_GUN_QUANTITY
  6265. for (int index = 0; index < AC_QUANTITY; index++)
  6266. {
  6267. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6268. {
  6269. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6270. goto end;
  6271. }
  6272. }//END FOR AC_QUANTITY
  6273. }//END FOR AvailabilityTypeStr[Operative]
  6274. end:
  6275. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6276. {
  6277. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  6278. }
  6279. else
  6280. {
  6281. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  6282. }
  6283. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6284. {
  6285. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6286. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6287. }
  6288. else if(gunIndex == 0)
  6289. {
  6290. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6291. {
  6292. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  6293. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  6294. }
  6295. }
  6296. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  6297. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6298. return result;
  6299. }
  6300. int handleChangeConfigurationRequest(char *uuid, char *payload)
  6301. {
  6302. mtrace();
  6303. int result = FAIL;
  6304. char keystr[40]={0};
  6305. char valuestr[256]={0};
  6306. char comfirmstr[20]={0};
  6307. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  6308. json_object *ChangeConfiguration;
  6309. ChangeConfiguration = json_tokener_parse(payload);
  6310. if(!is_error(ChangeConfiguration))
  6311. {
  6312. // Required data
  6313. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  6314. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  6315. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  6316. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  6317. }
  6318. json_object_put(ChangeConfiguration);
  6319. if((uuid==NULL) || (payload ==NULL) )
  6320. {
  6321. DEBUG_ERROR("Payload is null\n");
  6322. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6323. }
  6324. else
  6325. {
  6326. int status = setKeyValue(keystr, valuestr);
  6327. switch(status)
  6328. {
  6329. case ConfigurationStatus_Accepted:
  6330. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  6331. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  6332. StoreConfigurationTable();
  6333. break;
  6334. case RebootRequired:
  6335. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  6336. StoreConfigurationTable();
  6337. break;
  6338. case NotSupported:
  6339. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  6340. break;
  6341. case ConfigurationStatus_Rejected:
  6342. default:
  6343. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6344. break;
  6345. }
  6346. }
  6347. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  6348. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  6349. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6350. {
  6351. ChageWebSocketPingInterval(atoi(valuestr));
  6352. }
  6353. if((strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6354. {
  6355. SetOcppConnStatus(FALSE);
  6356. }
  6357. return result;
  6358. }
  6359. int handleClearCacheRequest(char *uuid, char *payload)
  6360. {
  6361. mtrace();
  6362. int result = FAIL;
  6363. char comfirmstr[20];
  6364. char rmFileCmd[100]={0};
  6365. struct stat stats;
  6366. DEBUG_INFO("handleClearCacheRequest...\n");
  6367. stat("/Storage/OCPP", &stats);
  6368. // Check for directory existence
  6369. if (S_ISDIR(stats.st_mode) == 1)
  6370. {}
  6371. else
  6372. {
  6373. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  6374. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  6375. system(rmFileCmd);
  6376. }
  6377. if(OCPP_cleanLocalCache())
  6378. {
  6379. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  6380. }
  6381. else
  6382. {
  6383. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  6384. }
  6385. sendClearCacheConfirmation(uuid, comfirmstr);
  6386. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6387. return result;
  6388. }
  6389. int handleClearChargingProfileRequest(char *uuid, char *payload)
  6390. {
  6391. mtrace();
  6392. int result = FAIL;
  6393. int resultRename;
  6394. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  6395. char chargingProfilePurposeStr[26]={0};
  6396. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  6397. char tempchargingProfilePurposeStr[26]={0};
  6398. char str[100]={0};
  6399. char fname[200]={0};
  6400. char comfirmstr[20]={0};
  6401. char word[1600]={0};
  6402. int clearflag = FALSE;
  6403. int chargingProfileIdIsNULL = FALSE;
  6404. int connectorIsNULL = FALSE;
  6405. int chargingProfilePurposeIsNULL = FALSE;
  6406. int stackLevelIsNULL = FALSE;
  6407. //int GotoEnd = FALSE;
  6408. FILE *fptr1, *fptr2;
  6409. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  6410. int n_chargingProfile=0;
  6411. int isEmptyFile = FALSE;
  6412. char sLineWord[1600]={0};
  6413. char chargingProfiles[10][100]={0};
  6414. int ChargeProfileCount = 0;
  6415. int ch;
  6416. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  6417. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  6418. json_object *ClearChargingProfile;
  6419. ClearChargingProfile = json_tokener_parse(payload);
  6420. if(!is_error(ClearChargingProfile))
  6421. {
  6422. // Optional data
  6423. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  6424. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  6425. else
  6426. chargingProfileIdIsNULL = TRUE;
  6427. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  6428. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  6429. else
  6430. connectorIsNULL = TRUE;
  6431. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  6432. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  6433. else
  6434. chargingProfilePurposeIsNULL = TRUE;
  6435. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  6436. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  6437. else
  6438. stackLevelIsNULL = TRUE;
  6439. }
  6440. json_object_put(ClearChargingProfile);
  6441. if(connectorIsNULL == FALSE)
  6442. {
  6443. switch(connectorIdInt)
  6444. {
  6445. case 0:
  6446. if(chargingProfilePurposeIsNULL == TRUE)
  6447. {
  6448. int l = 0;
  6449. strcpy(fname, ChargePointMaxProfile_JSON);
  6450. if((access(fname,F_OK))!=-1)
  6451. {
  6452. strcpy(chargingProfiles[l], fname);
  6453. l = l + 1;
  6454. }
  6455. strcpy(fname, TxDefaultProfile_0_JSON);
  6456. if((access(fname,F_OK))!=-1)
  6457. {
  6458. strcpy(chargingProfiles[l], fname);
  6459. l = l + 1;
  6460. }
  6461. ChargeProfileCount = l;
  6462. }
  6463. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  6464. {
  6465. strcpy(fname, ChargePointMaxProfile_JSON);
  6466. if((access(fname,F_OK))!=-1)
  6467. {
  6468. strcpy(chargingProfiles[0], fname);
  6469. ChargeProfileCount = 1;
  6470. }
  6471. }
  6472. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6473. {
  6474. strcpy(fname, TxDefaultProfile_0_JSON);
  6475. if((access(fname,F_OK))!=-1)
  6476. {
  6477. strcpy(chargingProfiles[0], fname);
  6478. ChargeProfileCount = 1;
  6479. }
  6480. }
  6481. break;
  6482. default:
  6483. if(chargingProfilePurposeIsNULL == TRUE)
  6484. {
  6485. int m = 0;
  6486. memset(fname, 0, ARRAY_SIZE(fname));
  6487. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6488. if((access(fname,F_OK))!=-1)
  6489. {
  6490. strcpy(chargingProfiles[m], fname);
  6491. m = m + 1;
  6492. }
  6493. memset(fname, 0, ARRAY_SIZE(fname));
  6494. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6495. if((access(fname,F_OK))!=-1)
  6496. {
  6497. strcpy(chargingProfiles[m], fname);
  6498. m = m + 1;
  6499. }
  6500. ChargeProfileCount = m;
  6501. }
  6502. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6503. {
  6504. //strcpy(fname, TxDefaultProfile_1_JSON);
  6505. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6506. if((access(fname,F_OK))!=-1)
  6507. {
  6508. strcpy(chargingProfiles[0], fname);
  6509. ChargeProfileCount = 1;
  6510. }
  6511. }
  6512. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  6513. {
  6514. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6515. if((access(fname,F_OK))!=-1)
  6516. {
  6517. strcpy(chargingProfiles[0], fname);
  6518. ChargeProfileCount = 1;
  6519. }
  6520. //strcpy(fname, TxProfile_1_JSON);
  6521. }
  6522. //strcpy(fname, ChargePointMaxProfile_JSON );
  6523. break;
  6524. }
  6525. }
  6526. else // Check all Charging Profiles
  6527. {
  6528. int i = 0;
  6529. char fnametemp[200]={0};
  6530. ChargeProfileCount = 0;
  6531. //Check ChargePointMaxProfile.json exit
  6532. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  6533. {
  6534. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  6535. i = i + 1;
  6536. }
  6537. //Check TxDefaultProfile_0.json exit
  6538. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  6539. {
  6540. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  6541. i = i + 1;
  6542. }
  6543. //Check TxDefaultProfile_%d.json
  6544. for(int j=1; j <= gunTotalNumber; j++)
  6545. {
  6546. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6547. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  6548. if((access(fnametemp,F_OK))!=-1)
  6549. {
  6550. strcpy(chargingProfiles[i], fnametemp);
  6551. i = i + 1;
  6552. }
  6553. }
  6554. //Check TxProfile_%d.json
  6555. for(int j=1; j <= gunTotalNumber; j++)
  6556. {
  6557. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6558. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  6559. if((access(fnametemp,F_OK))!=-1)
  6560. {
  6561. strcpy(chargingProfiles[i], fnametemp);
  6562. i = i + 1;
  6563. }
  6564. }
  6565. ChargeProfileCount = i;
  6566. }// End connectorIsNULL is TRUE
  6567. if(ChargeProfileCount == 0)
  6568. {
  6569. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6570. goto end;
  6571. }
  6572. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  6573. {
  6574. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6575. goto end;
  6576. }
  6577. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  6578. {
  6579. memset(str, 0, ARRAY_SIZE(str));
  6580. // clear temp file
  6581. sprintf(str,"rm -f %s",temp);
  6582. system(str);
  6583. for(int k=0; k < ChargeProfileCount; k++)
  6584. {
  6585. memset(str, 0, ARRAY_SIZE(str));
  6586. //clear file in C
  6587. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6588. system(str);
  6589. }
  6590. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6591. goto end;
  6592. }
  6593. else if(connectorIsNULL == TRUE)
  6594. {
  6595. for(int k=0; k < ChargeProfileCount; k++)
  6596. {
  6597. fptr1 = fopen(chargingProfiles[k], "r");
  6598. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  6599. //Check Charging Profile Count
  6600. while(fscanf(fptr1, "%s", word) != EOF)
  6601. {
  6602. //DEBUG_INFO("word=%s\n",word);
  6603. if(strstr(word, "chargingProfileId")!= NULL)
  6604. {
  6605. //DEBUG_INFO("test chargingProfileId \n");
  6606. n_chargingProfile = n_chargingProfile + 1;
  6607. //DEBUG_INFO("chargingProfileId Found\n");
  6608. }
  6609. }
  6610. rewind(fptr1);
  6611. //search Charging Profile Element
  6612. //int i= 0;
  6613. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6614. {
  6615. json_object *tmpProfilee;
  6616. tmpProfilee = json_tokener_parse(sLineWord);
  6617. if(!is_error(tmpProfilee))
  6618. {
  6619. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  6620. {
  6621. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  6622. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  6623. }
  6624. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  6625. {
  6626. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  6627. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  6628. }
  6629. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  6630. {
  6631. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  6632. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  6633. }
  6634. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  6635. {
  6636. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  6637. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  6638. }
  6639. }
  6640. json_object_put(tmpProfilee);
  6641. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6642. {
  6643. //------- not write to fptr2-------//
  6644. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6645. //clearflag = TRUE;
  6646. }
  6647. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  6648. {
  6649. //------- not write to fptr2-------//
  6650. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6651. }
  6652. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6653. {
  6654. //------- not write to fptr2-------//
  6655. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6656. }
  6657. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  6658. {
  6659. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6660. }
  6661. else
  6662. {
  6663. fprintf(fptr2, sLineWord);//writing data into file
  6664. }
  6665. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6666. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6667. if(clearflag == TRUE)
  6668. {
  6669. fclose(fptr1);
  6670. fclose(fptr2);
  6671. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6672. system(str);
  6673. // clear temp file
  6674. sprintf(str,"rm -f %s",temp);
  6675. system(str);
  6676. }
  6677. else
  6678. {
  6679. fclose(fptr1);
  6680. fclose(fptr2);
  6681. memset(str, 0, ARRAY_SIZE(str));
  6682. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6683. system(str);
  6684. resultRename = rename(temp, chargingProfiles[k]);
  6685. if(resultRename == 0)
  6686. {
  6687. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  6688. }
  6689. else
  6690. {
  6691. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  6692. }
  6693. if(comfirmstr[0]== 0)
  6694. {
  6695. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6696. }
  6697. //Check chargingProfile is empty file
  6698. /*------ Read the file ----------------*/
  6699. fptr1=fopen(chargingProfiles[k],"r");
  6700. ch=fgetc(fptr1);
  6701. rewind(fptr1);
  6702. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6703. if(ch!=EOF)
  6704. {
  6705. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6706. {
  6707. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6708. if(sLineWord[0]=='\0')
  6709. {
  6710. isEmptyFile = TRUE;
  6711. break;
  6712. }
  6713. else
  6714. {
  6715. isEmptyFile = FALSE;
  6716. break;
  6717. }
  6718. }
  6719. }
  6720. else
  6721. isEmptyFile = TRUE;
  6722. fclose(fptr1);
  6723. if(isEmptyFile == TRUE)
  6724. {
  6725. memset(str, 0, ARRAY_SIZE(str));
  6726. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6727. system(str);
  6728. }
  6729. }
  6730. }// End of while(int k=0; k < ChargePointCount; k++)
  6731. }
  6732. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  6733. {
  6734. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  6735. for(int k=0; k < ChargeProfileCount; k++)
  6736. {
  6737. fptr1 = fopen(chargingProfiles[k], "r");
  6738. fptr2 = fopen(temp, "w+");
  6739. //Check Charging Profile Count
  6740. while(fscanf(fptr1, "%s", word) != EOF)
  6741. {
  6742. //DEBUG_INFO("word=%s\n",word);
  6743. if(strstr(word, "chargingProfileId")!= NULL)
  6744. {
  6745. n_chargingProfile = n_chargingProfile + 1;
  6746. }
  6747. }
  6748. rewind(fptr1);
  6749. //search Charging Profile Element
  6750. //int i= 0;
  6751. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6752. {
  6753. json_object *tmpProfilee;
  6754. tmpProfilee = json_tokener_parse(sLineWord);
  6755. if(!is_error(tmpProfilee))
  6756. {
  6757. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  6758. {
  6759. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  6760. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  6761. }
  6762. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  6763. {
  6764. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  6765. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  6766. }
  6767. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  6768. {
  6769. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  6770. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  6771. }
  6772. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  6773. {
  6774. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  6775. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  6776. }
  6777. }
  6778. json_object_put(tmpProfilee);
  6779. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6780. {
  6781. //------- not write to fptr2-------//
  6782. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6783. //clearflag = TRUE;
  6784. }
  6785. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6786. {
  6787. //------- not write to fptr2-------//
  6788. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6789. }
  6790. else if(stackLevelIsNULL == TRUE)
  6791. {
  6792. //Clear Whole File
  6793. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6794. clearflag = TRUE;
  6795. break;
  6796. }
  6797. else
  6798. {
  6799. fprintf(fptr2, sLineWord);//writing data into file
  6800. }
  6801. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6802. }
  6803. if(clearflag == TRUE)
  6804. {
  6805. fclose(fptr1);
  6806. fclose(fptr2);
  6807. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6808. system(str);
  6809. // clear temp file
  6810. sprintf(str,"rm -f %s",temp);
  6811. system(str);
  6812. }
  6813. else
  6814. {
  6815. fclose(fptr1);
  6816. fclose(fptr2);
  6817. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6818. system(str);
  6819. resultRename = rename(temp, chargingProfiles[k]);
  6820. if(resultRename == 0)
  6821. {
  6822. DEBUG_INFO("File ChargingProfile renamed successfully");
  6823. }
  6824. else
  6825. {
  6826. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6827. }
  6828. if(comfirmstr[0]== 0)
  6829. {
  6830. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6831. }
  6832. //Check chargingProfile is empty file
  6833. /*------ Read the file ----------------*/
  6834. fptr1=fopen(chargingProfiles[k],"r");
  6835. ch=fgetc(fptr1);
  6836. rewind(fptr1);
  6837. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6838. if(ch!=EOF)
  6839. {
  6840. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6841. {
  6842. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6843. if(sLineWord[0]=='\0')
  6844. {
  6845. isEmptyFile = TRUE;
  6846. break;
  6847. }
  6848. else
  6849. {
  6850. isEmptyFile = FALSE;
  6851. break;
  6852. }
  6853. }
  6854. }
  6855. else
  6856. isEmptyFile = TRUE;
  6857. fclose(fptr1);
  6858. if(isEmptyFile == TRUE)
  6859. {
  6860. memset(str, 0, ARRAY_SIZE(str));
  6861. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6862. system(str);
  6863. }
  6864. /*------- End of reading ---------------*/
  6865. }
  6866. } // while(int k=0; k < ChargeProfileCount; k++)
  6867. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  6868. end:
  6869. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  6870. {
  6871. if(connectorIdInt == 0)
  6872. {
  6873. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  6874. {
  6875. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  6876. }
  6877. }
  6878. else
  6879. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  6880. }
  6881. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  6882. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6883. return result;
  6884. }
  6885. void createFirmwareVersionByDataTransfer(void)
  6886. {
  6887. json_object *FirmwareDataTransfer = json_object_new_object();
  6888. // AC & DC model
  6889. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  6890. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  6891. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  6892. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  6893. // DC model
  6894. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O')
  6895. {
  6896. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  6897. {
  6898. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6899. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6900. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  6901. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  6902. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6903. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6904. }
  6905. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  6906. ((gunType[1] != GUN_TYPE_UNKNOWN) || (gunType[2] != GUN_TYPE_UNKNOWN) || (gunType[3] != GUN_TYPE_UNKNOWN)))
  6907. {
  6908. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  6909. }
  6910. }
  6911. else
  6912. {
  6913. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6914. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6915. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6916. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6917. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  6918. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  6919. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  6920. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  6921. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  6922. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  6923. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  6924. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  6925. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  6926. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  6927. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  6928. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  6929. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  6930. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  6931. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  6932. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  6933. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  6934. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  6935. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  6936. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  6937. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  6938. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  6939. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  6940. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  6941. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  6942. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  6943. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  6944. }
  6945. // 4G model
  6946. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  6947. {
  6948. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  6949. }
  6950. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  6951. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  6952. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  6953. json_object_put(FirmwareDataTransfer);
  6954. }
  6955. int handleDataTransferRequest(char *uuid, char *payload)
  6956. {
  6957. mtrace();
  6958. json_object *response = json_object_new_object();
  6959. int result = FAIL;
  6960. char tempvendorId[255]={0};
  6961. char tempmessageId[50]={0};
  6962. char tempdata[512]={0};
  6963. char message[2048]={0};
  6964. DEBUG_INFO("handleDataTransferRequest...\n");
  6965. if((uuid != NULL) && (payload != NULL))
  6966. {
  6967. json_object *DataTransfer;
  6968. DataTransfer = json_tokener_parse(payload);
  6969. if(!is_error(DataTransfer))
  6970. {
  6971. // Required data
  6972. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  6973. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  6974. // Optional data
  6975. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  6976. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  6977. if(json_object_object_get(DataTransfer, "data") != NULL)
  6978. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  6979. result = PASS;
  6980. }
  6981. json_object_put(DataTransfer);
  6982. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  6983. {
  6984. // Send all moudle firmware version on EVSE
  6985. createFirmwareVersionByDataTransfer();
  6986. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6987. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  6988. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6989. json_object_put(response);
  6990. }
  6991. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  6992. {
  6993. system("/usr/bin/run_tmate_restart.sh &");
  6994. }
  6995. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  6996. {
  6997. json_object *data;
  6998. data = json_tokener_parse(tempdata);
  6999. if(!is_error(data))
  7000. {
  7001. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  7002. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  7003. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  7004. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  7005. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  7006. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  7007. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  7008. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  7009. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  7010. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  7011. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7012. }
  7013. else
  7014. {
  7015. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7016. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7017. }
  7018. json_object_put(data);
  7019. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7020. json_object_put(response);
  7021. }
  7022. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  7023. {
  7024. json_object *data;
  7025. data = json_tokener_parse(tempdata);
  7026. if(!is_error(data))
  7027. {
  7028. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  7029. if(json_object_object_get(data, "idToken") != NULL)
  7030. {
  7031. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  7032. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  7033. }
  7034. if(json_object_object_get(data, "price") != NULL)
  7035. {
  7036. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  7037. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  7038. }
  7039. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7040. }
  7041. else
  7042. {
  7043. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7044. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7045. }
  7046. json_object_put(data);
  7047. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7048. json_object_put(response);
  7049. }
  7050. else if(strstr(tempmessageId, "RunningCost") != NULL)
  7051. {
  7052. json_object *data;
  7053. data = json_tokener_parse(tempdata);
  7054. if(!is_error(data))
  7055. {
  7056. if(json_object_object_get(data, "txId") != NULL)
  7057. {
  7058. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7059. for(int idx = 0;idx<gunTotalNumber;idx++)
  7060. {
  7061. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7062. {
  7063. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  7064. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7065. if(json_object_object_get(data, "description") != NULL)
  7066. {
  7067. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7068. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7069. }
  7070. }
  7071. }
  7072. }
  7073. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7074. }
  7075. else
  7076. {
  7077. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7078. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7079. }
  7080. json_object_put(data);
  7081. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7082. json_object_put(response);
  7083. }
  7084. else if(strstr(tempmessageId, "FinalCost") != NULL)
  7085. {
  7086. json_object *data;
  7087. data = json_tokener_parse(tempdata);
  7088. if(!is_error(data))
  7089. {
  7090. if(json_object_object_get(data, "txId") != NULL)
  7091. {
  7092. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7093. for(int idx = 0;idx<gunTotalNumber;idx++)
  7094. {
  7095. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7096. {
  7097. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  7098. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7099. if(json_object_object_get(data, "description") != NULL)
  7100. {
  7101. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7102. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7103. }
  7104. }
  7105. }
  7106. }
  7107. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7108. }
  7109. else
  7110. {
  7111. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7112. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7113. }
  7114. json_object_put(data);
  7115. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7116. json_object_put(response);
  7117. }
  7118. else
  7119. {
  7120. // Can not find valid message id
  7121. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  7122. }
  7123. }
  7124. else
  7125. {
  7126. // Payload is null
  7127. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  7128. }
  7129. LWS_Send(message);
  7130. return result;
  7131. }
  7132. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  7133. {
  7134. mtrace();
  7135. int result = FAIL;
  7136. int connectorIdInt, durationInt;
  7137. char chargingRateUnitStr[4]={0};
  7138. char comfirmstr[20];
  7139. int confirmPeriods = 0;
  7140. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  7141. json_object *GetCompositeSchedule;
  7142. GetCompositeSchedule = json_tokener_parse(payload);
  7143. if(!is_error(GetCompositeSchedule))
  7144. {
  7145. // Required data
  7146. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  7147. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  7148. else
  7149. connectorIdInt = -1;
  7150. if(json_object_object_get(GetCompositeSchedule, "duration"))
  7151. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  7152. else
  7153. durationInt = 86400;
  7154. // Optional data
  7155. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  7156. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  7157. }
  7158. json_object_put(GetCompositeSchedule);
  7159. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  7160. if((connectorIdInt == 0) ||
  7161. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  7162. {
  7163. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  7164. struct StructChargingProfile tmpProfile[1];
  7165. if(strstr(chargingRateUnitStr, "W") != NULL)
  7166. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  7167. else
  7168. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  7169. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7170. {
  7171. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7172. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7173. }
  7174. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  7175. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  7176. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  7177. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7178. {
  7179. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7180. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7181. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  7182. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  7183. {
  7184. confirmPeriods = idx;
  7185. break;
  7186. }
  7187. }
  7188. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  7189. }
  7190. else
  7191. {
  7192. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  7193. }
  7194. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  7195. return result;
  7196. }
  7197. int handleGetConfigurationRequest(char *uuid, char *payload)
  7198. {
  7199. mtrace();
  7200. int result = FAIL;
  7201. int MaxKeySupported = 0;
  7202. int n_keys = 0;
  7203. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  7204. DEBUG_INFO("handleGetConfigurationRequest...\n");
  7205. json_object *GetConfiguration;
  7206. GetConfiguration = json_tokener_parse(payload);
  7207. if(!is_error(GetConfiguration))
  7208. {
  7209. // Optional data
  7210. if(json_object_object_get(GetConfiguration, "key") != NULL)
  7211. {
  7212. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  7213. {
  7214. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  7215. n_keys = idx + 1;
  7216. }
  7217. }
  7218. }
  7219. json_object_put(GetConfiguration);
  7220. UnknownKeynum = 0;
  7221. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  7222. MaxKeySupported = GetConfigurationMaxKeysNUM;
  7223. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  7224. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  7225. if(n_keys != 0)
  7226. {
  7227. for(int i=0;i<n_keys;i++)
  7228. {
  7229. getKeyValue(requestKey[i]);
  7230. }
  7231. }
  7232. else
  7233. {
  7234. DEBUG_INFO("There is no key in Message, get all configuration\n");
  7235. getKeyValue("");
  7236. }
  7237. processUnkownKey();
  7238. sendGetConfigurationConfirmation(uuid);
  7239. return result;
  7240. }
  7241. static char fnamePlusPath[100]={0};
  7242. static char fnamePWithNoPath[60]={0};
  7243. void checkUploadLog(void)
  7244. {
  7245. FILE *fp;
  7246. /* Open the command for reading. */
  7247. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  7248. if (fp == NULL) {
  7249. printf("Failed to run command\n" );
  7250. exit(1);
  7251. }
  7252. int ftppathlen = 0;
  7253. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  7254. int i = 0;
  7255. /* Read the output a line at a time - output it. */
  7256. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  7257. if(i==0)
  7258. {
  7259. ftppathlen = strlen(fnamePlusPath);
  7260. printf("%s\n", fnamePlusPath);
  7261. fnamePlusPath[ftppathlen]='\0';
  7262. break;
  7263. }
  7264. i= i+1;
  7265. }
  7266. /* close */
  7267. pclose(fp);
  7268. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  7269. {
  7270. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  7271. {
  7272. fnamePlusPath[k]='\0';
  7273. }
  7274. }
  7275. i=1;
  7276. //char fname[60]={0};
  7277. while(i < ftppathlen)
  7278. {
  7279. int len=ftppathlen-i;
  7280. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  7281. {
  7282. printf("compare '/' all right\n");
  7283. break;
  7284. }
  7285. i=i+1;
  7286. }
  7287. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  7288. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  7289. fnamePWithNoPath[i+1] = '\0';
  7290. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  7291. {
  7292. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  7293. {
  7294. fnamePWithNoPath[j]='\0';
  7295. }
  7296. }
  7297. FILE* fp1 = fopen(fnamePlusPath, "r");
  7298. if (fp1)
  7299. {
  7300. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  7301. // file exists
  7302. fclose(fp1);
  7303. }
  7304. else
  7305. {
  7306. // file doesn't exist
  7307. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  7308. }
  7309. }
  7310. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  7311. {
  7312. mtrace();
  7313. int result = FAIL;
  7314. time_t CurrentTime;
  7315. struct tm *tm;
  7316. pthread_t th_Status;
  7317. CurrentTime = time(NULL);
  7318. tm = localtime(&CurrentTime);
  7319. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  7320. sprintf((char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName, "%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);
  7321. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  7322. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  7323. return result;
  7324. }
  7325. void* GetDiagnosticsProcess(void* data)
  7326. {
  7327. pthread_detach(pthread_self());
  7328. mtrace();
  7329. int retriesInt=0, retryIntervalInt=0;
  7330. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  7331. 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};
  7332. int port=0;
  7333. int isSuccess = FALSE;
  7334. char ftpbuf[200]={0};
  7335. char cmdBuf[2048];
  7336. struct tm *tmNow;
  7337. time_t CurrentTime;
  7338. struct tm tmStart;
  7339. struct tm tmStop;
  7340. CurrentTime = time(NULL);
  7341. tmNow=localtime(&CurrentTime);
  7342. uint16_t targetYear, targetMonth;
  7343. json_object *GetDiagnostics;
  7344. DEBUG_INFO("GetDiagnosticsProcess...\n");
  7345. GetDiagnostics = json_tokener_parse(data);
  7346. if(!is_error(GetDiagnostics))
  7347. {
  7348. // Required data
  7349. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  7350. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  7351. // Optional data
  7352. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  7353. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  7354. else
  7355. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  7356. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  7357. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  7358. else
  7359. retryIntervalInt = 30;
  7360. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  7361. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  7362. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  7363. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  7364. }
  7365. json_object_put(GetDiagnostics);
  7366. // Pack log to compress file
  7367. if((sscanf((char*)startTimestr, "%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) &&
  7368. (sscanf((char*)stopTimestr, "%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))
  7369. {
  7370. // Pack system log
  7371. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  7372. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  7373. targetYear = tmStart.tm_year;
  7374. targetMonth = tmStart.tm_mon;
  7375. do
  7376. {
  7377. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7378. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7379. if(targetMonth+1>=13)
  7380. {
  7381. targetYear += 1;
  7382. targetMonth = 1;
  7383. }
  7384. else
  7385. {
  7386. targetMonth += 1;
  7387. }
  7388. }while((targetYear < (tmNow->tm_year+1900)) ||
  7389. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  7390. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  7391. system(cmdBuf);
  7392. // Pack charging & event log
  7393. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  7394. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  7395. targetYear = tmStart.tm_year;
  7396. targetMonth = tmStart.tm_mon;
  7397. do
  7398. {
  7399. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7400. if(targetMonth+1>=13)
  7401. {
  7402. targetYear += 1;
  7403. targetMonth = 1;
  7404. }
  7405. else
  7406. {
  7407. targetMonth += 1;
  7408. }
  7409. }while((targetYear < (tmNow->tm_year+1900)) ||
  7410. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  7411. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  7412. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  7413. system(cmdBuf);
  7414. // Combine log file
  7415. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  7416. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  7417. }
  7418. else
  7419. {
  7420. system("exec /root/logPackTools 'log' 6");
  7421. }
  7422. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  7423. system(cmdBuf);
  7424. checkUploadLog();
  7425. //****************location*******************/
  7426. if(strcmp(locationstr,"")==0)
  7427. {
  7428. DEBUG_INFO("location is <Empty>!\n");
  7429. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7430. goto end;
  7431. }
  7432. memset(protocol, 0, ARRAY_SIZE(protocol));
  7433. memset(user, 0, ARRAY_SIZE(user) );
  7434. memset(password, 0, ARRAY_SIZE(password));
  7435. memset(host, 0, ARRAY_SIZE(host));
  7436. memset(path, 0, ARRAY_SIZE(path));
  7437. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  7438. memset(host1, 0, ARRAY_SIZE(host1));
  7439. memset(path1, 0, ARRAY_SIZE(path1));
  7440. /*location: ftp://user:password@host:port/path*/
  7441. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  7442. if((access(fnamePlusPath,F_OK))!=-1)
  7443. {
  7444. DEBUG_INFO("fnamePlusPath exist.\n");
  7445. }
  7446. else
  7447. {
  7448. DEBUG_INFO("fnamePlusPath not exist!\n");
  7449. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7450. goto end;
  7451. }
  7452. if(strchr(locationstr,'@')==NULL)
  7453. {
  7454. sscanf(locationstr,
  7455. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  7456. protocol, host, &port, path);
  7457. strcpy(user,"anonymous");
  7458. strcpy(password,"");
  7459. }
  7460. else
  7461. {
  7462. //DEBUG_INFO("pch=%s\n", pch);
  7463. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  7464. protocol, user, password, host, &port, path);
  7465. }
  7466. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  7467. {
  7468. DEBUG_INFO("protocol is not ftp/http ! \n");
  7469. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7470. goto end;
  7471. }
  7472. if(strncmp(locationstr,"http", 4) == 0)
  7473. {
  7474. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  7475. sprintf(ftppath,"/%s", path);
  7476. do
  7477. {
  7478. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7479. sleep(3);
  7480. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  7481. if(!isSuccess)
  7482. {
  7483. DEBUG_INFO("Diagnostics fail.\n");
  7484. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7485. sleep(retryIntervalInt);
  7486. }
  7487. else
  7488. {
  7489. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7490. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7491. }
  7492. retriesInt--;
  7493. }while((isSuccess == 0)&&(retriesInt >= 0));
  7494. }
  7495. else
  7496. {
  7497. sscanf(host,"%[^/]%s",host1, path1);
  7498. if(strlen(path) > 0)
  7499. sprintf(ftppath,"/%s", path);
  7500. else
  7501. sprintf(ftppath,"/%s", path1);
  7502. int ftppathlen=strlen(ftppath);
  7503. int i=1;
  7504. char filenametemp[50];
  7505. while(i < ftppathlen)
  7506. {
  7507. int len=ftppathlen-i;
  7508. if(ftppath[len]== 47) // '/' ascll code: 47
  7509. {
  7510. DEBUG_INFO("find '/' all right\n");
  7511. break;
  7512. }
  7513. i=i+1;
  7514. }
  7515. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  7516. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  7517. filenametemp[i+1] = 0;
  7518. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  7519. if(port == 0)
  7520. port = 21;
  7521. do
  7522. {
  7523. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7524. sleep(3);
  7525. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  7526. if(!isSuccess)
  7527. {
  7528. DEBUG_INFO("Diagnostics fail.\n");
  7529. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7530. sleep(retryIntervalInt);
  7531. }
  7532. else
  7533. {
  7534. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7535. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7536. }
  7537. retriesInt--;
  7538. }while((!isSuccess)&&(retriesInt >= 0));
  7539. }
  7540. end:
  7541. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  7542. system("rm -f /mnt/*");
  7543. pthread_exit(NULL);
  7544. }
  7545. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  7546. {
  7547. mtrace();
  7548. int result = FAIL;
  7549. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  7550. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  7551. {
  7552. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  7553. localversion = -1;
  7554. }
  7555. else
  7556. {
  7557. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  7558. OCPP_getListVerion();
  7559. }
  7560. //from db.OCPP_getListVerion
  7561. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  7562. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  7563. sendGetLocalListVersionConfirmation(uuid,"");
  7564. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  7565. return result;
  7566. }
  7567. int handleRemoteStartRequest(char *uuid, char *payload)
  7568. {
  7569. mtrace();
  7570. int result = FAIL;
  7571. int connectorIdInt=0;
  7572. int tempIndex = 0;
  7573. int connectorIdIsNULL, chargingProfileIsNULL;
  7574. char comfirmstr[20]={0};
  7575. char cmdBuf[512];
  7576. json_object *RemoteStartTransaction;
  7577. FILE *fp;
  7578. DEBUG_INFO("handleRemoteStartRequest ...\n");
  7579. if(server_pending == TRUE)
  7580. {
  7581. return 0;
  7582. }
  7583. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  7584. RemoteStartTransaction = json_tokener_parse(payload);
  7585. if(!is_error(RemoteStartTransaction))
  7586. {
  7587. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  7588. {
  7589. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  7590. if(connectorIdInt <= gunTotalNumber)
  7591. {
  7592. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  7593. // Required data
  7594. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  7595. // Optional data
  7596. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  7597. {
  7598. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  7599. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  7600. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  7601. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  7602. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  7603. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  7604. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  7605. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  7606. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  7607. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  7608. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  7609. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  7610. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  7611. {
  7612. 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")));
  7613. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  7614. 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"));
  7615. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  7616. 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"));
  7617. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  7618. 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")));
  7619. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  7620. {
  7621. 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++)
  7622. {
  7623. 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"));
  7624. 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"));
  7625. 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)
  7626. 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"));
  7627. }
  7628. }
  7629. }
  7630. }
  7631. else
  7632. chargingProfileIsNULL = TRUE;
  7633. }
  7634. }
  7635. else
  7636. connectorIdIsNULL = TRUE;
  7637. }
  7638. else
  7639. connectorIdIsNULL = TRUE;
  7640. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  7641. {
  7642. DEBUG_WARN("Connector id is NULL\n.");
  7643. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7644. goto end;
  7645. }
  7646. /*
  7647. enum _SYSTEM_STATUS
  7648. {
  7649. S_BOOTING = 0,
  7650. S_IDLE, = 1
  7651. S_AUTHORIZING, = 2
  7652. S_REASSIGN_CHECK, = 3
  7653. S_REASSIGN, = 4
  7654. S_PRECHARGE, = 5
  7655. S_PREPARING_FOR_EV, = 6
  7656. S_PREPARING_FOR_EVSE, = 7
  7657. S_CHARGING, = 8
  7658. S_TERMINATING, = 9
  7659. S_COMPLETE, = 10
  7660. S_ALARM, = 11
  7661. S_FAULT = 12
  7662. }
  7663. */
  7664. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  7665. {
  7666. //check Transaction active
  7667. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  7668. {
  7669. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7670. {
  7671. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7672. }
  7673. else
  7674. {
  7675. tempIndex = connectorIdInt -1;
  7676. }
  7677. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7678. {
  7679. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  7680. {
  7681. 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))
  7682. {
  7683. //Reserved
  7684. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7685. }
  7686. 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))
  7687. {
  7688. //Reserved
  7689. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7690. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7691. goto end;
  7692. }
  7693. else
  7694. {
  7695. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7696. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  7697. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  7698. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  7699. {
  7700. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  7701. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7702. goto end;
  7703. }
  7704. }//END FOR ELSE
  7705. }
  7706. }// END FOR CHAdeMO_QUANTITY
  7707. }
  7708. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  7709. {
  7710. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7711. {
  7712. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7713. }
  7714. else
  7715. {
  7716. tempIndex = connectorIdInt -1;
  7717. }
  7718. for (int index = 0; index < CCS_QUANTITY; index++)
  7719. {
  7720. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7721. {
  7722. 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))
  7723. {
  7724. //Reserved
  7725. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7726. }
  7727. 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))
  7728. {
  7729. //Reserved
  7730. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7731. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7732. goto end;
  7733. }
  7734. else
  7735. {
  7736. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7737. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7738. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7739. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7740. {
  7741. DEBUG_WARN("CCS connector not allow start\n.");
  7742. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7743. goto end;
  7744. }
  7745. }// END FOR ELSE
  7746. }
  7747. }// END FOR CCS_QUANTITY
  7748. }
  7749. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  7750. {
  7751. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7752. {
  7753. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7754. }
  7755. else
  7756. {
  7757. tempIndex = connectorIdInt -1;
  7758. }
  7759. for (int index = 0; index < GB_QUANTITY; index++)
  7760. {
  7761. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7762. {
  7763. 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))
  7764. {
  7765. //Reserved
  7766. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7767. }
  7768. 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))
  7769. {
  7770. //Reserved
  7771. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7772. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7773. goto end;
  7774. }
  7775. else
  7776. {
  7777. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7778. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7779. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7780. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7781. {
  7782. DEBUG_WARN("GB connector not allow start\n.");
  7783. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7784. goto end;
  7785. }
  7786. }// END FOR ELSE
  7787. }
  7788. } // END FOR GB_QUANTITY
  7789. }
  7790. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  7791. {
  7792. tempIndex = connectorIdInt -1;
  7793. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7794. {
  7795. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  7796. {
  7797. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  7798. {
  7799. //Reserved
  7800. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7801. }
  7802. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  7803. {
  7804. //Reserved
  7805. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7806. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7807. goto end;
  7808. }
  7809. else
  7810. {
  7811. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7812. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7813. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7814. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7815. {
  7816. DEBUG_WARN("GB connector not allow start\n.");
  7817. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7818. goto end;
  7819. }
  7820. }// END FOR ELSE
  7821. }
  7822. } // END FOR GB_QUANTITY
  7823. }
  7824. else
  7825. {
  7826. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7827. {
  7828. tempIndex = 2;
  7829. }
  7830. else
  7831. {
  7832. tempIndex = connectorIdInt -1;
  7833. }
  7834. for (int index = 0; index < AC_QUANTITY; index++)
  7835. {
  7836. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7837. {
  7838. 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))
  7839. {
  7840. //Reserved
  7841. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7842. }
  7843. 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))
  7844. {
  7845. //Reserved
  7846. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7847. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7848. goto end;
  7849. }
  7850. else
  7851. {
  7852. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7853. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7854. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7855. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7856. {
  7857. DEBUG_WARN("AC connector not allow start\n.");
  7858. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7859. goto end;
  7860. }
  7861. }//END FOR ELSE
  7862. }
  7863. }// END FOR AC_QUANTITY
  7864. }
  7865. if(chargingProfileIsNULL == FALSE)
  7866. {
  7867. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7868. {
  7869. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7870. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7871. //memset idTag
  7872. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7873. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7874. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7875. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7876. // Save profile to file
  7877. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7878. system(cmdBuf);
  7879. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7880. fp = fopen(cmdBuf, "w");
  7881. fprintf(fp, "{\"connectorId\":%d,\"csChargingProfiles\":%s}\n", connectorIdInt, json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  7882. fclose(fp);
  7883. }
  7884. else
  7885. {
  7886. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  7887. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7888. }
  7889. }
  7890. else
  7891. {
  7892. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7893. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7894. //memset idTag
  7895. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7896. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7897. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7898. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7899. }
  7900. }
  7901. else
  7902. {
  7903. DEBUG_WARN("Connector id over\n.");
  7904. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7905. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7906. }
  7907. end:
  7908. json_object_put(RemoteStartTransaction);
  7909. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  7910. {
  7911. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7912. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7913. }
  7914. //OCPP send RemoteStartConfirmation by first.
  7915. sendRemoteStartConfirmation(uuid, comfirmstr);
  7916. return result;
  7917. }
  7918. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7919. {
  7920. mtrace();
  7921. int result = FAIL;
  7922. int match = FALSE;
  7923. int GunNO = 0;
  7924. int tempIndex = 0;
  7925. int transactionIdInt=0;
  7926. int transactionIdIsNULL= TRUE;
  7927. char comfirmstr[20];
  7928. json_object *RemoteStopTransaction;
  7929. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7930. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7931. if(server_pending == TRUE)
  7932. {
  7933. return 0;
  7934. }
  7935. RemoteStopTransaction = json_tokener_parse(payload);
  7936. if(!is_error(RemoteStopTransaction))
  7937. {
  7938. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  7939. {
  7940. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  7941. transactionIdIsNULL = FALSE;
  7942. }
  7943. }
  7944. json_object_put(RemoteStopTransaction);
  7945. if(transactionIdIsNULL == FALSE)
  7946. {
  7947. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7948. {
  7949. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7950. {
  7951. //check Transaction active
  7952. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7953. {
  7954. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7955. {
  7956. tempIndex = ((gun_index==2) ? 1: 0);
  7957. }
  7958. else
  7959. {
  7960. tempIndex = gun_index;
  7961. }
  7962. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7963. {
  7964. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7965. {
  7966. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7967. {
  7968. match = TRUE;
  7969. GunNO = gun_index;
  7970. }
  7971. }
  7972. }// END FOR CHAdeMO_QUANTITY
  7973. }
  7974. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7975. {
  7976. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7977. {
  7978. tempIndex = ((gun_index==2) ? 1: 0);
  7979. }
  7980. else
  7981. {
  7982. tempIndex = gun_index;
  7983. }
  7984. for (int index = 0; index < CCS_QUANTITY; index++)
  7985. {
  7986. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7987. {
  7988. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7989. {
  7990. match = TRUE;
  7991. GunNO = gun_index;
  7992. }
  7993. }
  7994. }// END FOR CCS_QUANTITY
  7995. }
  7996. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7997. {
  7998. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7999. {
  8000. tempIndex = ((gun_index==2) ? 1: 0);
  8001. }
  8002. else
  8003. {
  8004. tempIndex = gun_index;
  8005. }
  8006. for (int index = 0; index < GB_QUANTITY; index++)
  8007. {
  8008. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8009. {
  8010. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8011. {
  8012. match = TRUE;
  8013. GunNO = gun_index;
  8014. }
  8015. }
  8016. }// END FOR GB_QUANTITY
  8017. }
  8018. else if(gunType[gun_index] == GUN_TYPE_DO)
  8019. {
  8020. tempIndex = gun_index;
  8021. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8022. {
  8023. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8024. {
  8025. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8026. {
  8027. match = TRUE;
  8028. GunNO = gun_index;
  8029. }
  8030. }
  8031. }// END FOR GB_QUANTITY
  8032. }
  8033. else
  8034. {
  8035. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8036. {
  8037. tempIndex = 2;
  8038. }
  8039. else
  8040. {
  8041. tempIndex = gun_index;
  8042. }
  8043. for (int index = 0; index < AC_QUANTITY; index++)
  8044. {
  8045. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8046. {
  8047. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8048. {
  8049. match = TRUE;
  8050. GunNO = gun_index;
  8051. }
  8052. }
  8053. }// END FOR CHAdeMO_QUANTITY
  8054. } // END FOR AC ELSE
  8055. }// CHECK IF ResponseTransactionId == transactionIdInt
  8056. }//END FOR
  8057. if( match == TRUE)
  8058. {
  8059. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  8060. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8061. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  8062. }
  8063. else
  8064. {
  8065. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8066. }
  8067. }
  8068. else
  8069. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8070. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  8071. return result;
  8072. }
  8073. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  8074. {
  8075. mtrace();
  8076. int result = FAIL;
  8077. int connectorIdInt=0, reservationIdInt=0;
  8078. int tempIndex = 0;
  8079. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  8080. char comfirmstr[20]={0};
  8081. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  8082. int c = 0;
  8083. char *loc;
  8084. //char *ptr;
  8085. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  8086. strcpy(sstrtemp, stringtrimspace(payload));
  8087. //***(1)connectorId ****/
  8088. c=0;
  8089. loc = strstr(sstrtemp, "connectorId");
  8090. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8091. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  8092. {
  8093. sstr[c] = loc[strlen("connectorId")+2+c];
  8094. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8095. c++;
  8096. }
  8097. sstr[c] = '\0';
  8098. connectorIdInt = atoi(sstr);
  8099. //***(2)expiryDate ****/
  8100. loc = strstr(sstrtemp, "expiryDate");
  8101. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8102. c = 0;
  8103. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  8104. {
  8105. sstr[c] = loc[3+strlen("expiryDate")+c];
  8106. c++;
  8107. }
  8108. sstr[c] = '\0';
  8109. strcpy(expiryDatestr, sstr);
  8110. //***(3)idTag ****/
  8111. loc = strstr(sstrtemp, "idTag");
  8112. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8113. c = 0;
  8114. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  8115. {
  8116. sstr[c] = loc[3+strlen("idTag")+c];
  8117. c++;
  8118. }
  8119. sstr[c] = '\0';
  8120. strcpy(idTagstr, sstr);
  8121. //***(4)parentIdTag ****/
  8122. loc = strstr(sstrtemp, "parentIdTag");
  8123. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8124. c = 0;
  8125. if(loc == NULL)
  8126. {
  8127. strcpy(parentIdTagstr, "");
  8128. }
  8129. else
  8130. {
  8131. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8132. {
  8133. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8134. c++;
  8135. }
  8136. sstr[c] = '\0';
  8137. strcpy(parentIdTagstr, sstr);
  8138. }
  8139. //***(5)reservationId ****/
  8140. c=0;
  8141. loc = strstr(sstrtemp, "reservationId");
  8142. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8143. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  8144. {
  8145. sstr[c] = loc[strlen("reservationId")+2+c];
  8146. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8147. c++;
  8148. }
  8149. sstr[c] = '\0';
  8150. reservationIdInt = atoi(sstr);
  8151. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8152. /*
  8153. enum SYSTEM_STATUS
  8154. {
  8155. SYS_MODE_BOOTING = 0,
  8156. SYS_MODE_IDLE = 1,
  8157. SYS_MODE_AUTHORIZING = 2,
  8158. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  8159. SYS_MODE_REASSIGN = 4,
  8160. SYS_MODE_PREPARING = 5,
  8161. SYS_MODE_PREPARE_FOR_EV = 6,
  8162. SYS_MODE_PREPARE_FOR_EVSE = 7,
  8163. SYS_MODE_CHARGING = 8,
  8164. SYS_MODE_TERMINATING = 9,
  8165. SYS_MODE_COMPLETE = 10,
  8166. SYS_MODE_ALARM = 11,
  8167. SYS_MODE_FAULT = 12,
  8168. SYS_MODE_RESERVATION = 13,
  8169. SYS_MODE_BOOKING = 14,
  8170. SYS_MODE_MAINTAIN = 15,
  8171. SYS_MODE_DEBUG = 16,
  8172. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  8173. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  8174. SYS_MODE_UPDATE = 19
  8175. };
  8176. */
  8177. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  8178. {
  8179. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8180. goto end;
  8181. }
  8182. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  8183. {
  8184. //check Transaction active
  8185. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8186. {
  8187. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8188. {
  8189. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8190. }
  8191. else
  8192. {
  8193. tempIndex = connectorIdInt -1;
  8194. }
  8195. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8196. {
  8197. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8198. {
  8199. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8200. {
  8201. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8202. {
  8203. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8204. {
  8205. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8206. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8207. }
  8208. 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'))
  8209. {
  8210. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8211. }
  8212. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8213. {
  8214. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8215. }
  8216. else
  8217. {
  8218. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8219. }
  8220. }
  8221. 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
  8222. {
  8223. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8224. }
  8225. }
  8226. else
  8227. {
  8228. //replace reservation
  8229. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8230. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8231. }
  8232. }
  8233. } // END FOR CHAdeMO_QUANTITY
  8234. }
  8235. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8236. {
  8237. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8238. {
  8239. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8240. }
  8241. else
  8242. {
  8243. tempIndex = connectorIdInt -1;
  8244. }
  8245. for (int index = 0; index < CCS_QUANTITY; index++)
  8246. {
  8247. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8248. {
  8249. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8250. {
  8251. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8252. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8253. {
  8254. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8255. {
  8256. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8257. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8258. }
  8259. 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'))
  8260. {
  8261. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8262. }
  8263. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  8264. {
  8265. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8266. }
  8267. else
  8268. {
  8269. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8270. }
  8271. }
  8272. 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
  8273. {
  8274. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8275. }
  8276. }
  8277. else
  8278. {
  8279. //replace reservation
  8280. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8281. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8282. }
  8283. }
  8284. } // END FOR CCS_QUANTITY
  8285. }
  8286. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8287. {
  8288. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8289. {
  8290. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8291. }
  8292. else
  8293. {
  8294. tempIndex = connectorIdInt -1;
  8295. }
  8296. for (int index = 0; index < GB_QUANTITY; index++)
  8297. {
  8298. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8299. {
  8300. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8301. {
  8302. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8303. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8304. {
  8305. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8306. {
  8307. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8308. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8309. }
  8310. 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'))
  8311. {
  8312. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8313. }
  8314. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8315. {
  8316. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8317. }
  8318. else
  8319. {
  8320. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8321. }
  8322. }
  8323. 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
  8324. {
  8325. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8326. }
  8327. }
  8328. else
  8329. {
  8330. //replace reservation
  8331. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8332. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8333. }
  8334. }
  8335. }// END FOR GB_QUANTITY
  8336. }
  8337. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8338. {
  8339. tempIndex = connectorIdInt -1;
  8340. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8341. {
  8342. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8343. {
  8344. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  8345. {
  8346. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8347. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8348. {
  8349. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8350. {
  8351. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8352. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8353. }
  8354. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  8355. {
  8356. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8357. }
  8358. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8359. {
  8360. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8361. }
  8362. else
  8363. {
  8364. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8365. }
  8366. }
  8367. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus ==SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus ==SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_ALARM ,SYS_MODE_TERMINATING ---> SuspendedEV
  8368. {
  8369. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8370. }
  8371. }
  8372. else
  8373. {
  8374. //replace reservation
  8375. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8376. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8377. }
  8378. }
  8379. }// END FOR GB_QUANTITY
  8380. }
  8381. else
  8382. {
  8383. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8384. {
  8385. tempIndex = 2;
  8386. }
  8387. else
  8388. {
  8389. tempIndex = (connectorIdInt -1);
  8390. }
  8391. for (int index = 0; index < AC_QUANTITY; index++)
  8392. {
  8393. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8394. {
  8395. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8396. {
  8397. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8398. {
  8399. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8400. {
  8401. 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))
  8402. {
  8403. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8404. }
  8405. else
  8406. {
  8407. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8408. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8409. }
  8410. }
  8411. 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'))
  8412. {
  8413. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8414. }
  8415. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8416. {
  8417. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8418. }
  8419. else
  8420. {
  8421. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8422. }
  8423. }
  8424. 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
  8425. {
  8426. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8427. }
  8428. }
  8429. else
  8430. {
  8431. //replace reservation
  8432. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8433. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8434. }
  8435. }
  8436. } // END FOR AC_QUANTITY
  8437. }
  8438. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8439. }
  8440. else if(connectorIdInt == 0)
  8441. {
  8442. //check Transaction active
  8443. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8444. {
  8445. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8446. {
  8447. 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'))
  8448. {
  8449. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8450. goto end;
  8451. }
  8452. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8453. {
  8454. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8455. goto end;
  8456. }
  8457. 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
  8458. {
  8459. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8460. goto end;
  8461. }
  8462. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8463. {
  8464. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8465. goto end;
  8466. }
  8467. }
  8468. }// END FOR CHAdeMO_QUANTITY
  8469. for (int index = 0; index < CCS_QUANTITY; index++)
  8470. {
  8471. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8472. {
  8473. 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'))
  8474. {
  8475. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8476. goto end;
  8477. }
  8478. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  8479. {
  8480. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8481. goto end;
  8482. }
  8483. 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
  8484. {
  8485. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8486. goto end;
  8487. }
  8488. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8489. {
  8490. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8491. goto end;
  8492. }
  8493. }
  8494. } // END FOR CCS_QUANTITY
  8495. for (int index = 0; index < GB_QUANTITY; index++)
  8496. {
  8497. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8498. {
  8499. 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'))
  8500. {
  8501. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8502. goto end;
  8503. }
  8504. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8505. {
  8506. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8507. goto end;
  8508. }
  8509. 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
  8510. {
  8511. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8512. goto end;
  8513. }
  8514. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8515. {
  8516. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8517. goto end;
  8518. }
  8519. }
  8520. } // END FOR GB_QUANTITY
  8521. for (int index = 0; index < AC_QUANTITY; index++)
  8522. {
  8523. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8524. {
  8525. 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'))
  8526. {
  8527. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8528. goto end;
  8529. }
  8530. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8531. {
  8532. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8533. goto end;
  8534. }
  8535. 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
  8536. {
  8537. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8538. goto end;
  8539. }
  8540. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8541. {
  8542. 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))
  8543. {
  8544. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8545. goto end;
  8546. }
  8547. }
  8548. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8549. {
  8550. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8551. goto end;
  8552. }
  8553. }
  8554. }// END FOR AC_QUANTITY
  8555. //The connectorId is 0
  8556. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  8557. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8558. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  8559. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  8560. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  8561. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  8562. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  8563. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  8564. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  8565. result = TRUE;
  8566. return result;
  8567. }
  8568. else
  8569. {
  8570. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8571. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8572. }
  8573. if(strcmp(comfirmstr,"Accepted") == 0)
  8574. {
  8575. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  8576. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  8577. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  8578. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  8579. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  8580. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  8581. result = TRUE;
  8582. return result;
  8583. }
  8584. end:
  8585. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  8586. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  8587. return result;
  8588. }
  8589. int handleResetRequest(char *uuid, char *payload)
  8590. {
  8591. mtrace();
  8592. int result = FAIL;
  8593. char sstr[10]={0},sstrtemp[30]={ 0 };
  8594. char typestr[10]={0};
  8595. char comfirmstr[20]={0};
  8596. int c = 0;
  8597. char *loc;
  8598. DEBUG_INFO("handleResetRequest...\n");
  8599. strcpy(sstrtemp, stringtrimspace(payload));
  8600. loc = strstr(sstrtemp, "type");
  8601. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8602. c = 0;
  8603. while (loc[3+strlen("type")+c] != '\"')
  8604. {
  8605. sstr[c] = loc[3+strlen("type")+c];
  8606. c++;
  8607. }
  8608. sstr[c] = '\0';
  8609. strcpy(typestr,sstr);
  8610. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  8611. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  8612. {
  8613. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  8614. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  8615. result = TRUE;
  8616. return result;
  8617. }
  8618. else
  8619. {
  8620. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  8621. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  8622. goto errorend;
  8623. }
  8624. errorend:
  8625. sendResetConfirmation(uuid, comfirmstr);
  8626. return result;
  8627. }
  8628. int handleSendLocalListRequest(char *uuid, char *payload)
  8629. {
  8630. mtrace();
  8631. int result = FAIL;
  8632. int listVersionInt;
  8633. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  8634. char listsearch[]="listVersion";
  8635. char updateTypesearch[]="updateType";
  8636. char localAuthorizationListsearch[]="localAuthorizationList";
  8637. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  8638. char CardList[500][160]={0};
  8639. char updateTypestr[15]={0};
  8640. char idTagstr[20]={0};
  8641. char parentIdTag[20]={0};
  8642. char expiryDate[30]={0};
  8643. char idTagstatus[16]={0};
  8644. int c = 0;
  8645. int i = 0;
  8646. char *delim1 = "}";
  8647. char * pch;
  8648. char *loc;
  8649. //char *ptr;
  8650. char comfirmstr[20];
  8651. //int n_localAuthorizations = 0;
  8652. int checkState_Faulted = FALSE;
  8653. DEBUG_INFO("handleSendLocalListRequest...\n");
  8654. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  8655. {
  8656. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8657. goto end;
  8658. }
  8659. //check Charge Point state
  8660. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8661. {
  8662. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8663. {
  8664. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8665. }
  8666. }
  8667. for (int index = 0; index < CCS_QUANTITY; index++)
  8668. {
  8669. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8670. {
  8671. checkState_Faulted = TRUE; //OCPP Status
  8672. }
  8673. }
  8674. for (int index = 0; index < GB_QUANTITY; index++)
  8675. {
  8676. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8677. {
  8678. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8679. }
  8680. }
  8681. //check Charge Point state
  8682. for (int index = 0; index < AC_QUANTITY; index++)
  8683. {
  8684. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8685. {
  8686. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8687. }
  8688. }
  8689. if(checkState_Faulted == TRUE)
  8690. {
  8691. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8692. goto end;
  8693. }
  8694. //Filter payload space
  8695. strcpy(sstrtemp, stringtrimspace(payload));
  8696. //listVersion
  8697. c = 0;
  8698. loc = strstr(sstrtemp, listsearch);
  8699. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  8700. {
  8701. sstr[c] = loc[strlen("listVersion")+2+c];
  8702. c++;
  8703. }
  8704. sstr[c] = '\0';
  8705. listVersionInt = atoi(sstr);
  8706. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8707. //updateType
  8708. loc = strstr(sstrtemp, updateTypesearch);
  8709. c = 0;
  8710. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  8711. {
  8712. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  8713. c++;
  8714. }
  8715. sstr[c] = '\0';
  8716. strcpy(updateTypestr, sstr);
  8717. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  8718. //localAuthorizationList
  8719. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8720. loc = strstr(sstrtemp, localAuthorizationListsearch);
  8721. if(loc != NULL) // localAuthorizationList is not NULL
  8722. {
  8723. //Check UpdateType
  8724. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8725. {
  8726. //Local list full update
  8727. printf("Local list full update.\n");
  8728. OCPP_getListVerion();
  8729. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8730. {
  8731. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8732. goto end;
  8733. }
  8734. OCPP_cleanLocalList();
  8735. }
  8736. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8737. {
  8738. //Local list different update
  8739. printf("Local list different update.\n");
  8740. OCPP_getListVerion();
  8741. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8742. {
  8743. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  8744. goto end;
  8745. }
  8746. }
  8747. else
  8748. {
  8749. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8750. goto end;
  8751. }
  8752. c = 0;
  8753. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  8754. {
  8755. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  8756. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8757. c++;
  8758. }
  8759. sstr[c] = '\0';
  8760. //DEBUG_INFO("sstr=%s\n", sstr);
  8761. //parsing strings to words
  8762. i = 0;
  8763. pch = strtok(sstr,delim1);
  8764. while (pch != NULL)
  8765. {
  8766. strcpy(CardList[i], pch);
  8767. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  8768. pch = strtok (NULL, delim1);
  8769. i = i + 1;
  8770. }
  8771. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  8772. //local Authorizations List Numbers
  8773. //n_localAuthorizations = i;
  8774. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8775. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  8776. c= 0;
  8777. while(c < i) // i is CardList Number
  8778. {
  8779. //Search "IdToken"
  8780. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8781. loc = strstr(CardList[c], "idTag");
  8782. int j = 0;
  8783. while (loc[3+strlen("idTag")+j] != '\"')
  8784. {
  8785. sstr[j] = loc[3+strlen("idTag")+j];
  8786. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8787. j++;
  8788. }
  8789. sstr[j] = '\0';
  8790. strcpy(idTagstr, sstr);
  8791. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  8792. //Search "expiryDate"
  8793. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8794. loc = strstr(CardList[c], "expiryDate");
  8795. j = 0;
  8796. if(loc != NULL)
  8797. {
  8798. while (loc[3+strlen("expiryDate")+j] != '\"')
  8799. {
  8800. sstr[j] = loc[3+strlen("expiryDate")+j];
  8801. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8802. j++;
  8803. }
  8804. sstr[j] = '\0';
  8805. strcpy(expiryDate, sstr);
  8806. }
  8807. else
  8808. {
  8809. strcpy(expiryDate, "");
  8810. }
  8811. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  8812. //Search "parentIdTag"
  8813. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8814. loc = strstr(CardList[c], "parentIdTag");
  8815. j = 0;
  8816. if(loc != NULL)
  8817. {
  8818. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8819. {
  8820. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8821. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8822. j++;
  8823. }
  8824. sstr[j] = '\0';
  8825. strcpy(parentIdTag, sstr);
  8826. }
  8827. else
  8828. {
  8829. strcpy(parentIdTag, "");
  8830. }
  8831. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8832. //Search "status"
  8833. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8834. loc = strstr(CardList[c], "status");
  8835. j = 0;
  8836. while (loc[3+strlen("status")+j] != '\"')
  8837. {
  8838. sstr[j] = loc[3+strlen("status")+j];
  8839. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8840. j++;
  8841. }
  8842. sstr[j] = '\0';
  8843. strcpy(idTagstatus, sstr);
  8844. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8845. OCPP_getIdTagFromLocalList(idTagstr);
  8846. //OCPP_getIdTagFromLocalList("test"); For Test
  8847. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8848. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8849. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8850. {
  8851. //Local list full update
  8852. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8853. // update list
  8854. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8855. //DEBUG_INFO("Local list full update. 1\n");
  8856. //OCPP_get_TableAuthlocalAllData();
  8857. //DEBUG_INFO("Local list full update. 2\n");
  8858. }
  8859. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8860. {
  8861. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8862. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8863. }
  8864. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8865. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8866. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8867. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8868. c++;
  8869. }
  8870. }
  8871. else
  8872. {
  8873. //Check UpdateType
  8874. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8875. {
  8876. //Local list full update
  8877. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8878. OCPP_cleanLocalList();
  8879. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8880. goto end;
  8881. }
  8882. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8883. {
  8884. //Local list different update
  8885. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8886. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8887. goto end;
  8888. }
  8889. }
  8890. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8891. end:
  8892. sendSendLocalListConfirmation(uuid, comfirmstr);
  8893. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8894. return result;
  8895. }
  8896. #define MAX 200
  8897. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8898. {
  8899. mtrace();
  8900. int result = FAIL;
  8901. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8902. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8903. char chargingProfilePurposeStr[30]={0};
  8904. char chargingProfileKindStr[16]={0};
  8905. char recurrencyKindStr[10]={0};
  8906. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8907. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8908. int chargingSchedulePeriodCount = 0;
  8909. char comfirmstr[20]={0};
  8910. int meet= FALSE;
  8911. FILE *fptr1;
  8912. char filename[MAX]={0};
  8913. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8914. char rmFileCmd[50]={0};
  8915. char tempchargingProfilePurposeStr[30]={0};
  8916. char word[1600]={0};
  8917. int n_chargingProfile = 0;
  8918. json_object *SetChargingProfile;
  8919. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8920. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8921. SetChargingProfile = json_tokener_parse(payload);
  8922. if(!is_error(SetChargingProfile))
  8923. {
  8924. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  8925. {
  8926. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  8927. if(connectorIdInt == 0)
  8928. {
  8929. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  8930. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8931. }
  8932. else
  8933. {
  8934. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  8935. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  8936. }
  8937. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  8938. }
  8939. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  8940. {
  8941. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  8942. {
  8943. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  8944. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8945. {
  8946. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8947. }
  8948. else
  8949. {
  8950. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8951. }
  8952. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  8953. }
  8954. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  8955. {
  8956. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  8957. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8958. {
  8959. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8960. }
  8961. else
  8962. {
  8963. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8964. }
  8965. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  8966. }
  8967. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8968. {
  8969. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  8970. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8971. {
  8972. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8973. }
  8974. else
  8975. {
  8976. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8977. }
  8978. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  8979. }
  8980. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  8981. {
  8982. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  8983. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8984. {
  8985. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8986. }
  8987. else
  8988. {
  8989. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8990. }
  8991. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  8992. }
  8993. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  8994. {
  8995. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  8996. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8997. {
  8998. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  8999. }
  9000. else
  9001. {
  9002. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  9003. }
  9004. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  9005. }
  9006. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  9007. {
  9008. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  9009. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9010. {
  9011. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9012. }
  9013. else
  9014. {
  9015. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9016. }
  9017. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  9018. }
  9019. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  9020. {
  9021. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  9022. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9023. {
  9024. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  9025. }
  9026. else
  9027. {
  9028. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  9029. }
  9030. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  9031. }
  9032. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  9033. {
  9034. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  9035. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9036. {
  9037. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  9038. }
  9039. else
  9040. {
  9041. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  9042. }
  9043. //DEBUG_INFO("validToStr: %s\n", validToStr);
  9044. }
  9045. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  9046. {
  9047. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  9048. {
  9049. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  9050. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9051. {
  9052. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9053. }
  9054. else
  9055. {
  9056. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9057. }
  9058. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  9059. }
  9060. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  9061. {
  9062. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  9063. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9064. {
  9065. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9066. }
  9067. else
  9068. {
  9069. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9070. }
  9071. //DEBUG_INFO("durationInt: %d\n", durationInt);
  9072. }
  9073. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  9074. {
  9075. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  9076. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9077. {
  9078. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9079. }
  9080. else
  9081. {
  9082. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9083. }
  9084. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  9085. }
  9086. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  9087. {
  9088. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  9089. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9090. {
  9091. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9092. }
  9093. else
  9094. {
  9095. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9096. }
  9097. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  9098. }
  9099. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9100. {
  9101. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  9102. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  9103. if(chargingSchedulePeriodCount <= 10)
  9104. {
  9105. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  9106. {
  9107. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod") != NULL)
  9108. {
  9109. startPeriodInt[idxPeriod] = 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(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  9110. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9111. {
  9112. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9113. }
  9114. else
  9115. {
  9116. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9117. }
  9118. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  9119. }
  9120. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit") != NULL)
  9121. {
  9122. limitflaot[idxPeriod] = 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(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  9123. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9124. {
  9125. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9126. }
  9127. else
  9128. {
  9129. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9130. }
  9131. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  9132. }
  9133. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases") != NULL)
  9134. {
  9135. numberPhasesInt[idxPeriod] = 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(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  9136. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9137. {
  9138. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9139. }
  9140. else
  9141. {
  9142. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9143. }
  9144. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  9145. }
  9146. }
  9147. }
  9148. }
  9149. }
  9150. }
  9151. }
  9152. json_object_put(SetChargingProfile);
  9153. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  9154. {
  9155. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9156. goto end;
  9157. }
  9158. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  9159. {
  9160. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  9161. if(connectorIdInt != 0)
  9162. {
  9163. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9164. goto end;
  9165. }
  9166. strcpy(filename, ChargePointMaxProfile_JSON );
  9167. fptr1 = fopen(filename, "r");
  9168. if (!fptr1)
  9169. {
  9170. //file not exist
  9171. DEBUG_INFO("Unable to open the input file!!\n");
  9172. fptr1 = fopen(filename, "w+");
  9173. }
  9174. else
  9175. {
  9176. //Check Charging Profile Count
  9177. while(fscanf(fptr1, "%s", word) != EOF)
  9178. {
  9179. //DEBUG_INFO("word=%s\n",word);
  9180. if(strstr(word, "chargingProfileId")!= NULL)
  9181. {
  9182. //DEBUG_INFO("test chargingProfileId \n");
  9183. n_chargingProfile = n_chargingProfile + 1;
  9184. //DEBUG_INFO("chargingProfileId Found\n");
  9185. }
  9186. }
  9187. }
  9188. fclose(fptr1);
  9189. }
  9190. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  9191. {
  9192. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  9193. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9194. {
  9195. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9196. goto end;
  9197. }
  9198. memset(filename, 0, ARRAY_SIZE(filename));
  9199. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9200. fptr1 = fopen(filename, "r");
  9201. if (!fptr1)
  9202. {
  9203. //file not exist
  9204. //DEBUG_INFO("Unable to open the input file!!\n");
  9205. fptr1 = fopen(filename, "w+");
  9206. }
  9207. else
  9208. {
  9209. //Check Charging Profile Count
  9210. while(fscanf(fptr1, "%s", word) != EOF)
  9211. {
  9212. //DEBUG_INFO("word=%s\n",word);
  9213. if(strstr(word, "chargingProfileId")!= NULL)
  9214. {
  9215. //DEBUG_INFO("test chargingProfileId \n");
  9216. n_chargingProfile = n_chargingProfile + 1;
  9217. //DEBUG_INFO("chargingProfileId Found\n");
  9218. }
  9219. }
  9220. }
  9221. fclose(fptr1);
  9222. }
  9223. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9224. {
  9225. //printf("set chargingProfile 1-4\n");
  9226. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  9227. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  9228. if(connectorIdInt == 0)
  9229. {
  9230. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9231. goto end;
  9232. }
  9233. int tempIndex = 0;
  9234. //check Transaction active
  9235. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9236. {
  9237. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9238. {
  9239. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9240. }
  9241. else
  9242. {
  9243. tempIndex = connectorIdInt -1;
  9244. }
  9245. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9246. {
  9247. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9248. {
  9249. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9250. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9251. {
  9252. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9253. {
  9254. meet = TRUE;
  9255. break;
  9256. }
  9257. }
  9258. }
  9259. }
  9260. }
  9261. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9262. {
  9263. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9264. {
  9265. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9266. }
  9267. else
  9268. {
  9269. tempIndex = connectorIdInt -1;
  9270. }
  9271. for (int index = 0; index < CCS_QUANTITY; index++)
  9272. {
  9273. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9274. {
  9275. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9276. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9277. {
  9278. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9279. {
  9280. meet = TRUE;
  9281. break;
  9282. }
  9283. }
  9284. }
  9285. }
  9286. }
  9287. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9288. {
  9289. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9290. {
  9291. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9292. }
  9293. else
  9294. {
  9295. tempIndex = connectorIdInt -1;
  9296. }
  9297. for (int index = 0; index < GB_QUANTITY; index++)
  9298. {
  9299. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9300. {
  9301. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9302. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9303. {
  9304. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9305. {
  9306. meet = TRUE;
  9307. break;
  9308. }
  9309. }
  9310. }
  9311. }
  9312. }
  9313. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9314. {
  9315. tempIndex = connectorIdInt -1;
  9316. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9317. {
  9318. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9319. {
  9320. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  9321. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9322. {
  9323. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9324. {
  9325. meet = TRUE;
  9326. break;
  9327. }
  9328. }
  9329. }
  9330. }
  9331. }
  9332. else
  9333. {
  9334. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9335. {
  9336. tempIndex = 2;
  9337. }
  9338. else
  9339. {
  9340. tempIndex = (connectorIdInt -1);
  9341. }
  9342. for (int index = 0; index < AC_QUANTITY; index++)
  9343. {
  9344. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9345. {
  9346. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9347. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9348. {
  9349. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9350. {
  9351. meet = TRUE;
  9352. break;
  9353. }
  9354. }
  9355. }
  9356. }
  9357. }
  9358. //check Transaction active
  9359. if(meet == FALSE)
  9360. {
  9361. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9362. goto end;
  9363. }
  9364. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9365. {
  9366. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9367. goto end;
  9368. }
  9369. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9370. fptr1 = fopen(filename, "r");
  9371. if (!fptr1)
  9372. {
  9373. //file not exist
  9374. DEBUG_INFO("Unable to open the input file!!\n");
  9375. fptr1 = fopen(filename, "w+");
  9376. }
  9377. else
  9378. {
  9379. //Check Charging Profile Count
  9380. while(fscanf(fptr1, "%s", word) != EOF)
  9381. {
  9382. //DEBUG_INFO("word=%s\n",word);
  9383. if(strstr(word, "chargingProfileId")!= NULL)
  9384. {
  9385. //DEBUG_INFO("test chargingProfileId \n");
  9386. n_chargingProfile = n_chargingProfile + 1;
  9387. //DEBUG_INFO("chargingProfileId Found\n");
  9388. }
  9389. }
  9390. }
  9391. fclose(fptr1);
  9392. }
  9393. // Check ChargeProfileMaxStackLevel
  9394. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  9395. {
  9396. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9397. goto end;
  9398. }
  9399. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9400. {
  9401. int i = 0;
  9402. char fnametemp[200]={0};
  9403. n_chargingProfile = 0;
  9404. //Check ChargePointMaxProfile.json exit
  9405. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9406. {
  9407. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  9408. //Check Charging Profile Count
  9409. while(fscanf(fptr1, "%s", word) != EOF)
  9410. {
  9411. //DEBUG_INFO("word=%s\n",word);
  9412. if(strstr(word, "chargingProfileId")!= NULL)
  9413. {
  9414. //DEBUG_INFO("test chargingProfileId \n");
  9415. n_chargingProfile = n_chargingProfile + 1;
  9416. i = i + 1;
  9417. //DEBUG_INFO("chargingProfileId Found\n");
  9418. }
  9419. memset(word, 0, ARRAY_SIZE(word));
  9420. }
  9421. fclose(fptr1);
  9422. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  9423. }
  9424. //Check TxDefaultProfile_0.json exit
  9425. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9426. {
  9427. i = 0;
  9428. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  9429. //Check Charging Profile Count
  9430. while(fscanf(fptr1, "%s", word) != EOF)
  9431. {
  9432. //DEBUG_INFO("word=%s\n",word);
  9433. if(strstr(word, "chargingProfileId")!= NULL)
  9434. {
  9435. //DEBUG_INFO("test chargingProfileId \n");
  9436. n_chargingProfile = n_chargingProfile + 1;
  9437. i = i + 1;
  9438. //DEBUG_INFO("chargingProfileId Found\n");
  9439. }
  9440. memset(word, 0, ARRAY_SIZE(word));
  9441. }
  9442. fclose(fptr1);
  9443. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  9444. }
  9445. //Check TxDefaultProfile_%d.json
  9446. for(int j=1; j <= gunTotalNumber; j++)
  9447. {
  9448. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9449. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9450. if((access(fnametemp,F_OK))!=-1)
  9451. {
  9452. i = 0;
  9453. fptr1 = fopen(fnametemp, "r");
  9454. //Check Charging Profile Count
  9455. while(fscanf(fptr1, "%s", word) != EOF)
  9456. {
  9457. //DEBUG_INFO("word=%s\n",word);
  9458. if(strstr(word, "chargingProfileId")!= NULL)
  9459. {
  9460. //DEBUG_INFO("test chargingProfileId \n");
  9461. n_chargingProfile = n_chargingProfile + 1;
  9462. i = i + 1;
  9463. //DEBUG_INFO("chargingProfileId Found\n");
  9464. }
  9465. memset(word, 0, ARRAY_SIZE(word));
  9466. }
  9467. fclose(fptr1);
  9468. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9469. }
  9470. }
  9471. //Check TxProfile_%d.json
  9472. for(int j=1; j <= gunTotalNumber; j++)
  9473. {
  9474. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9475. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9476. if((access(fnametemp,F_OK))!=-1)
  9477. {
  9478. i = 0;
  9479. fptr1 = fopen(fnametemp, "r");
  9480. //Check Charging Profile Count
  9481. while(fscanf(fptr1, "%s", word) != EOF)
  9482. {
  9483. //DEBUG_INFO("word=%s\n",word);
  9484. if(strstr(word, "chargingProfileId")!= NULL)
  9485. {
  9486. //DEBUG_INFO("test chargingProfileId \n");
  9487. n_chargingProfile = n_chargingProfile + 1;
  9488. i = i + 1;
  9489. //DEBUG_INFO("chargingProfileId Found\n");
  9490. }
  9491. memset(word, 0, ARRAY_SIZE(word));
  9492. }
  9493. fclose(fptr1);
  9494. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9495. }
  9496. }
  9497. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  9498. {
  9499. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9500. goto end;
  9501. }
  9502. }
  9503. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9504. //**********************************Write to File********************************************************/
  9505. FILE *infile;
  9506. FILE *outfile;
  9507. infile = fopen (filename, "r");
  9508. outfile = fopen (tempfile, "w");
  9509. int d =0;
  9510. d = fgetc(infile);
  9511. rewind(infile);
  9512. if(d == EOF)
  9513. {
  9514. // Profile is empty
  9515. fprintf(outfile,"%s\n",payload);
  9516. fclose(infile);
  9517. fclose(outfile);
  9518. sprintf(rmFileCmd,"rm -f %s",filename);
  9519. system(rmFileCmd);
  9520. rename(tempfile, filename);
  9521. }
  9522. else
  9523. {
  9524. // Profile is not empty
  9525. char buf[2048]={0};
  9526. int ChargingProfileAdded = FALSE;
  9527. while (fgets(buf, sizeof(buf), infile) != NULL)
  9528. {
  9529. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9530. json_object *tmpChargingProfile;
  9531. tmpChargingProfile = json_tokener_parse(buf);
  9532. if(!is_error(SetChargingProfile))
  9533. {
  9534. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  9535. {
  9536. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  9537. }
  9538. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  9539. {
  9540. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9541. {
  9542. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9543. }
  9544. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9545. {
  9546. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  9547. }
  9548. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9549. {
  9550. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9551. }
  9552. }
  9553. }
  9554. json_object_put(tmpChargingProfile);
  9555. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  9556. {
  9557. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9558. {
  9559. //DEBUG_INFO("update set chargingProfile to file -0\n");
  9560. if(ChargingProfileAdded == FALSE)
  9561. {
  9562. fprintf(outfile,"%s\n",payload);
  9563. ChargingProfileAdded = TRUE;
  9564. }
  9565. }
  9566. else
  9567. {
  9568. if(tempstackLevelInt < stackLevelInt)
  9569. {
  9570. if(ChargingProfileAdded == FALSE)
  9571. {
  9572. fprintf(outfile,"%s\n",buf);
  9573. fprintf(outfile,"%s\n",payload);
  9574. ChargingProfileAdded = TRUE;
  9575. }
  9576. else
  9577. {
  9578. fprintf(outfile,"%s\n",buf);
  9579. }
  9580. }
  9581. else
  9582. {
  9583. if(ChargingProfileAdded == FALSE)
  9584. {
  9585. fprintf(outfile,"%s\n",buf);
  9586. fprintf(outfile,"%s\n",payload);
  9587. ChargingProfileAdded = TRUE;
  9588. }
  9589. else
  9590. {
  9591. fprintf(outfile,"%s\n",buf);
  9592. }
  9593. }
  9594. }
  9595. }
  9596. else
  9597. {
  9598. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9599. {
  9600. if(ChargingProfileAdded == FALSE)
  9601. {
  9602. fprintf(outfile,"%s\n",buf);
  9603. fprintf(outfile,"%s\n",payload);
  9604. ChargingProfileAdded = TRUE;
  9605. }
  9606. else
  9607. {
  9608. fprintf(outfile,"%s\n",buf);
  9609. }
  9610. }
  9611. else if(tempstackLevelInt < stackLevelInt)
  9612. {
  9613. if(ChargingProfileAdded == FALSE)
  9614. {
  9615. fprintf(outfile,"%s\n",buf);
  9616. fprintf(outfile,"%s\n",payload);
  9617. ChargingProfileAdded = TRUE;
  9618. }
  9619. else
  9620. {
  9621. fprintf(outfile,"%s\n",buf);
  9622. }
  9623. }
  9624. else
  9625. {
  9626. if(ChargingProfileAdded == FALSE)
  9627. {
  9628. fprintf(outfile,"%s\n",buf);
  9629. fprintf(outfile,"%s\n",payload);
  9630. ChargingProfileAdded = TRUE;
  9631. }
  9632. else
  9633. {
  9634. fprintf(outfile,"%s\n",buf);
  9635. }
  9636. }
  9637. }
  9638. } // end of while loop
  9639. fclose(infile);
  9640. fclose(outfile);
  9641. sprintf(rmFileCmd,"rm -f %s",filename);
  9642. system(rmFileCmd);
  9643. rename(tempfile, filename);
  9644. }
  9645. sleep(1);
  9646. result = TRUE;
  9647. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9648. end:
  9649. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  9650. {
  9651. if(connectorIdInt == 0)
  9652. {
  9653. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9654. {
  9655. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9656. }
  9657. }
  9658. else
  9659. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9660. }
  9661. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  9662. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9663. return result;
  9664. }
  9665. int handleTriggerMessageRequest(char *uuid, char *payload)
  9666. {
  9667. mtrace();
  9668. int result = FAIL;
  9669. int connectorIdIsNULL = FALSE;
  9670. int connectorIdInt =0;
  9671. char sstr[40]={0},sstrtemp[100]={ 0 };
  9672. char requestedMessagestr[40]={0};
  9673. char comfirmstr[20]={0};
  9674. int c = 0;
  9675. char *loc;
  9676. DEBUG_INFO("handleTriggerMessageRequest\n");
  9677. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  9678. strcpy(sstrtemp, stringtrimspace(payload));
  9679. c = 0;
  9680. loc = strstr(sstrtemp, "requestedMessage");
  9681. while (loc[3+strlen("requestedMessage")+c] != '\"')
  9682. {
  9683. sstr[c] = loc[3+strlen("requestedMessage")+c];
  9684. c++;
  9685. }
  9686. sstr[c] = '\0';
  9687. strcpy(requestedMessagestr, sstr);
  9688. c = 0;
  9689. loc = strstr(sstrtemp, "connectorId");
  9690. if(loc == NULL)
  9691. {
  9692. connectorIdIsNULL = TRUE;
  9693. }
  9694. else
  9695. {
  9696. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9697. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  9698. {
  9699. sstr[c] = loc[strlen("connectorId")+2+c];
  9700. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9701. c++;
  9702. }
  9703. sstr[c] = '\0';
  9704. connectorIdInt = atoi(sstr);
  9705. }
  9706. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  9707. {
  9708. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  9709. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  9710. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  9711. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  9712. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  9713. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  9714. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  9715. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  9716. {
  9717. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  9718. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9719. return TRUE;
  9720. }
  9721. else
  9722. {
  9723. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9724. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9725. }
  9726. }
  9727. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  9728. {
  9729. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  9730. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9731. return TRUE;
  9732. }
  9733. //==========================
  9734. // Trigger message
  9735. //==========================
  9736. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  9737. {
  9738. if((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) &&
  9739. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) &&
  9740. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) &&
  9741. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING) )
  9742. {
  9743. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  9744. }
  9745. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  9746. }
  9747. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  9748. {
  9749. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  9750. }
  9751. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  9752. {
  9753. //sendBootNotificationRequest();
  9754. server_sign = FALSE;
  9755. }
  9756. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  9757. {
  9758. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  9759. }
  9760. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  9761. {
  9762. if(connectorIdIsNULL == FALSE)
  9763. {
  9764. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9765. {
  9766. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  9767. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  9768. }
  9769. }
  9770. else
  9771. {
  9772. for(int idx=0;idx< gunTotalNumber;idx++)
  9773. {
  9774. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  9775. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  9776. }
  9777. }
  9778. }
  9779. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  9780. {
  9781. if(connectorIdIsNULL == FALSE)
  9782. {
  9783. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9784. {
  9785. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  9786. }
  9787. }
  9788. else
  9789. {
  9790. for(int idx=0;idx< gunTotalNumber;idx++)
  9791. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  9792. }
  9793. }
  9794. return result;
  9795. }
  9796. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9797. {
  9798. mtrace();
  9799. int result = FAIL;
  9800. int connectorIdInt =0;
  9801. char comfirmstr[20]={0};
  9802. int tempIndex = 0;
  9803. json_object *UnlockConnector;
  9804. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9805. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9806. UnlockConnector = json_tokener_parse(payload);
  9807. if(!is_error(UnlockConnector))
  9808. {
  9809. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  9810. {
  9811. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  9812. }
  9813. }
  9814. json_object_put(UnlockConnector);
  9815. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  9816. if(gunTotalNumber == 0)
  9817. {
  9818. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9819. goto end;
  9820. }
  9821. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9822. {
  9823. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9824. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9825. goto end;
  9826. }
  9827. else
  9828. {
  9829. //check Transaction active
  9830. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  9831. {
  9832. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9833. {
  9834. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9835. }
  9836. else
  9837. {
  9838. tempIndex = connectorIdInt -1;
  9839. }
  9840. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9841. {
  9842. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9843. {
  9844. //stop Transaction
  9845. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9846. }
  9847. }
  9848. }
  9849. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  9850. {
  9851. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9852. {
  9853. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9854. }
  9855. else
  9856. {
  9857. tempIndex = connectorIdInt -1;
  9858. }
  9859. for (int index = 0; index < CCS_QUANTITY; index++)
  9860. {
  9861. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9862. {
  9863. //stop Transaction
  9864. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9865. }
  9866. }
  9867. }
  9868. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  9869. {
  9870. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9871. {
  9872. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9873. }
  9874. else
  9875. {
  9876. tempIndex = connectorIdInt -1;
  9877. }
  9878. for (int index = 0; index < GB_QUANTITY; index++)
  9879. {
  9880. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9881. {
  9882. //stop Transaction
  9883. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9884. }
  9885. }
  9886. }
  9887. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  9888. {
  9889. tempIndex = connectorIdInt -1;
  9890. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9891. {
  9892. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)))
  9893. {
  9894. //stop Transaction
  9895. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9896. }
  9897. }
  9898. }
  9899. else
  9900. {
  9901. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9902. {
  9903. tempIndex = 2;
  9904. }
  9905. else
  9906. {
  9907. tempIndex = connectorIdInt-1;
  9908. }
  9909. for (int index = 0; index < AC_QUANTITY; index++)
  9910. {
  9911. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9912. {
  9913. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9914. }
  9915. }
  9916. }
  9917. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9918. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9919. result = TRUE;
  9920. return result;
  9921. }
  9922. end:
  9923. //json_object_put(obj); --- remove temporally
  9924. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9925. return result;
  9926. }
  9927. static char UpdateFirmwarepayloadData[300]={0};
  9928. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9929. {
  9930. mtrace();
  9931. int result = FAIL;
  9932. pthread_t t;
  9933. sendUpdateFirmwareConfirmation(uuid);
  9934. memset(UpdateFirmwarepayloadData, 0, 300);
  9935. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9936. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9937. ////pthread_join(t, NULL); //
  9938. //pthread_detach(t);
  9939. //sendUpdateFirmwareConfirmation(uuid);
  9940. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9941. return result;
  9942. }
  9943. void *UpdateFirmwareProcess(void *data)
  9944. {
  9945. pthread_detach(pthread_self());
  9946. mtrace();
  9947. int retriesInt =0, retryIntervalInt=0;
  9948. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9949. int port=0;
  9950. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9951. int isSuccess = 0;
  9952. char ftpbuf[200];
  9953. char temp[100];
  9954. char * pch;
  9955. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9956. json_object *UpdateFirmware;
  9957. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  9958. if(!is_error(UpdateFirmware))
  9959. {
  9960. // Required data
  9961. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  9962. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  9963. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  9964. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  9965. // Optional data
  9966. if(json_object_object_get(UpdateFirmware, "retries"))
  9967. {
  9968. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  9969. }
  9970. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  9971. {
  9972. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  9973. }
  9974. }
  9975. json_object_put(UpdateFirmware);
  9976. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9977. memset(path, 0, ARRAY_SIZE(path));
  9978. system("rm -f /mnt/*");
  9979. if(strncmp(locationstr,"http", 4) == 0)
  9980. {
  9981. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9982. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9983. // protocol, user, password, host, path);
  9984. sprintf(ftppath,"/%s", path);
  9985. DEBUG_INFO("locationstr: %s\n", locationstr);
  9986. DEBUG_INFO("protocol: %s\n",protocol);
  9987. DEBUG_INFO("host: %s\n",host);
  9988. DEBUG_INFO("path: %s\n",path);
  9989. DEBUG_INFO("ftppath: %s\n",ftppath);
  9990. int ftppathlen=strlen(ftppath);
  9991. int i=1;
  9992. char filenametemp[50];
  9993. while(i < ftppathlen)
  9994. {
  9995. int len=ftppathlen-i;
  9996. if(ftppath[len]== 47) // '/' ascll code: 47
  9997. {
  9998. DEBUG_INFO("compare '/' all right\n");
  9999. break;
  10000. }
  10001. i=i+1;
  10002. }
  10003. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10004. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10005. filenametemp[i+1] = 0;
  10006. do
  10007. {
  10008. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  10009. sleep(3);
  10010. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  10011. if(!isSuccess)
  10012. {
  10013. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10014. sleep(retryIntervalInt);
  10015. }
  10016. else
  10017. {
  10018. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10019. }
  10020. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  10021. }
  10022. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  10023. {
  10024. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  10025. memset(temp, 0, ARRAY_SIZE(temp));
  10026. //DEBUG_INFO("locationstr=%s\n",locationstr);
  10027. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  10028. int ftppathlen=strlen(ftpbuf);
  10029. int i=1;
  10030. char filenametemp[50];
  10031. while(i < ftppathlen)
  10032. {
  10033. int len=ftppathlen-i;
  10034. if(ftpbuf[len]== 47) // '/' ascll code: 47
  10035. {
  10036. DEBUG_INFO(" compare '/' all right\n");
  10037. break;
  10038. }
  10039. i=i+1;
  10040. }
  10041. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10042. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  10043. filenametemp[i+1] = 0;
  10044. strncpy(temp, ftpbuf, ftppathlen-i+1);
  10045. pch=strchr(temp,'@');
  10046. if(pch==NULL)
  10047. {
  10048. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10049. protocol, host, &port, path);
  10050. strcpy(user,"anonymous");
  10051. strcpy(password,"");
  10052. }
  10053. else
  10054. {
  10055. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10056. protocol, user, password, host, &port, path);
  10057. }
  10058. sscanf(host,"%[^/]%s",host1, path1);
  10059. sprintf(ftppath,"%s", path1);
  10060. //DEBUG_INFO("protocol =%s\n",protocol);
  10061. //DEBUG_INFO("user =%s\n",user);
  10062. //DEBUG_INFO("password =%s\n",password);
  10063. //DEBUG_INFO("host1 =%s\n",host1);
  10064. //DEBUG_INFO("port =%d\n",port);
  10065. //DEBUG_INFO("path1 =%s\n",path1);
  10066. //DEBUG_INFO("ftppath=%s\n",ftppath);
  10067. //ftpFile(host, user, password, port, ftppath, fname);
  10068. //download firmware pthred
  10069. if(port == 0)
  10070. {
  10071. port = 21;
  10072. }
  10073. do
  10074. {
  10075. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  10076. sleep(3);
  10077. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  10078. if(!isSuccess)
  10079. {
  10080. //BulldogUtil.sleepMs(interval*1000);
  10081. DEBUG_INFO("Update firmware request and download file fail.\n");
  10082. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10083. sleep(retryIntervalInt);
  10084. }
  10085. else
  10086. {
  10087. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10088. }
  10089. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  10090. }
  10091. else
  10092. {
  10093. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10094. }
  10095. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  10096. pthread_exit(NULL);
  10097. }
  10098. //==========================================
  10099. // Handle server response routine
  10100. //==========================================
  10101. void handleAuthorizeResponse(char *payload, int gun_index)
  10102. {
  10103. mtrace();
  10104. char expiryDatestr[30]={0};
  10105. char parentIdTagstr[20]={0};
  10106. char statusstr[20]={0};
  10107. int expiryDateISNULL=FALSE;
  10108. int parentIdTagISNULL=FALSE;
  10109. DEBUG_INFO("handleAuthorizeResponse...\n");
  10110. json_object *Authorize;
  10111. Authorize = json_tokener_parse(payload);
  10112. if(!is_error(Authorize))
  10113. {
  10114. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  10115. {
  10116. // Required data
  10117. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  10118. // Optional data
  10119. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  10120. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  10121. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  10122. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  10123. }
  10124. }
  10125. json_object_put(Authorize);
  10126. if(expiryDateISNULL == FALSE)
  10127. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  10128. if(parentIdTagISNULL == FALSE)
  10129. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  10130. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  10131. //Update idTag information to authorization cache if supproted
  10132. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  10133. {
  10134. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  10135. }
  10136. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  10137. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  10138. authorizeRetryTimes = 0;
  10139. }
  10140. void handleBootNotificationResponse(char *payload, int gun_index)
  10141. {
  10142. mtrace();
  10143. char statusStr[12]={0};
  10144. char currentTimeStr[30]={0};
  10145. int intervalInt = 0;
  10146. struct tm tp;
  10147. char buf[28]={0};
  10148. char timebuf[50]={0};
  10149. DEBUG_INFO("handleBootNotificationResponse...\n");
  10150. json_object *BootNotification;
  10151. BootNotification = json_tokener_parse(payload);
  10152. if(!is_error(BootNotification))
  10153. {
  10154. // Required data
  10155. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  10156. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  10157. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  10158. }
  10159. json_object_put(BootNotification);
  10160. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10161. BootNotificationInterval = intervalInt;
  10162. HeartBeatWaitTime = intervalInt;
  10163. //write back to ShmOCPP16Data->BootNotification
  10164. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  10165. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10166. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  10167. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  10168. {
  10169. server_sign = TRUE;
  10170. server_pending =FALSE;
  10171. }
  10172. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  10173. {
  10174. server_pending = TRUE;
  10175. }
  10176. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10177. tp.tm_isdst = -1;
  10178. //time_t utc = mktime(&tp);
  10179. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  10180. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  10181. sprintf(timebuf,"date -s '%s'",buf);
  10182. system(timebuf);
  10183. srand(time(NULL));
  10184. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  10185. //==============================================
  10186. // RTC sync
  10187. //==============================================
  10188. system("/sbin/hwclock -w --systohc");
  10189. SetOcppConnStatus(TRUE);
  10190. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  10191. }
  10192. void handleDataTransferResponse(char *payload, int gun_index)
  10193. {
  10194. char sstr[160]={0};//sstr[200]={ 0 };
  10195. int c = 0;
  10196. char *loc;
  10197. DEBUG_INFO("handleDataTransferResponse ...\n");
  10198. loc = strstr(payload, "status");
  10199. printf("loc=%s\n",loc);
  10200. c = 0;
  10201. while (loc[3+strlen("status")+c] != '\"')
  10202. {
  10203. sstr[c] = loc[3+strlen("status")+c];
  10204. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10205. c++;
  10206. }
  10207. sstr[c] = '\0';
  10208. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  10209. }
  10210. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  10211. {
  10212. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  10213. //struct json_object *obj;
  10214. // obj = json_tokener_parse(payload);
  10215. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  10216. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  10217. //No fields are defined.
  10218. }
  10219. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  10220. {
  10221. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  10222. //struct json_object *obj;
  10223. // obj = json_tokener_parse(payload);
  10224. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  10225. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  10226. //No fields are defined.
  10227. }
  10228. void handleHeartbeatResponse(char *payload, int gun_index)
  10229. {
  10230. mtrace();
  10231. struct tm tp;
  10232. char buf[28]={0};
  10233. char timebuf[50]={0};
  10234. DEBUG_INFO("handleHeartbeatResponse...\n");
  10235. json_object *Heartbeat;
  10236. Heartbeat = json_tokener_parse(payload);
  10237. if(!is_error(Heartbeat))
  10238. {
  10239. // Required data
  10240. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  10241. }
  10242. json_object_put(Heartbeat);
  10243. if(FirstHeartBeat == 0)
  10244. {
  10245. FirstHeartBeat = 1;
  10246. DEBUG_INFO("FirstHeartBeat \n");
  10247. }
  10248. HeartBeatWithNOResponse = 0;
  10249. clientTime.Heartbeat=time((time_t*)NULL);
  10250. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10251. tp.tm_isdst = -1;
  10252. //time_t utc = mktime(&tp);
  10253. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  10254. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  10255. sprintf(timebuf,"date -s '%s'",buf);
  10256. system(timebuf);
  10257. //==============================================
  10258. // RTC sync
  10259. //==============================================
  10260. system("/sbin/hwclock -w --systohc");
  10261. }
  10262. void handleMeterValuesResponse(char *payload, int gun_index)
  10263. {
  10264. mtrace();
  10265. DEBUG_INFO("handleMeterValuesResponse...\n");
  10266. }
  10267. void handleStartTransactionResponse(char *payload, int gun_index)
  10268. {
  10269. mtrace();
  10270. //int transactionIdInt = 0;
  10271. FILE *outfile;
  10272. char data[100]={0};
  10273. DEBUG_INFO("handleStartTransactionResponse...\n");
  10274. json_object *StartTransaction;
  10275. StartTransaction = json_tokener_parse(payload);
  10276. if(!is_error(StartTransaction))
  10277. {
  10278. // Required data
  10279. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  10280. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  10281. // Optional data
  10282. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  10283. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  10284. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10285. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  10286. }
  10287. json_object_put(StartTransaction);
  10288. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  10289. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  10290. //-----------Start : write to the Queue TransactionId file -----------------//
  10291. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  10292. {}
  10293. else
  10294. {
  10295. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  10296. if(log == NULL)
  10297. {
  10298. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  10299. return ;
  10300. }
  10301. else
  10302. {
  10303. fclose(log);
  10304. }
  10305. }
  10306. // open file for writing
  10307. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  10308. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  10309. {
  10310. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  10311. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  10312. fputs(data, outfile);
  10313. fclose (outfile);
  10314. }
  10315. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10316. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10317. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  10318. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  10319. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10320. }
  10321. void handleStatusNotificationResponse(char *payload, int gun_index)
  10322. {
  10323. mtrace();
  10324. DEBUG_INFO("handleStatusNotificationResponse...\n");
  10325. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  10326. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  10327. }
  10328. void handleStopTransactionnResponse(char *payload, int gun_index)
  10329. {
  10330. mtrace();
  10331. DEBUG_INFO("handleStopTransactionnResponse...\n");
  10332. json_object *StopTransaction;
  10333. StopTransaction = json_tokener_parse(payload);
  10334. if(!is_error(StopTransaction))
  10335. {
  10336. // Optional data
  10337. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  10338. {
  10339. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  10340. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  10341. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  10342. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10343. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  10344. }
  10345. }
  10346. json_object_put(StopTransaction);
  10347. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  10348. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  10349. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10350. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10351. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  10352. }
  10353. //==========================================
  10354. // Handle Error routine
  10355. //==========================================
  10356. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  10357. {
  10358. mtrace();
  10359. #ifdef SystemLogMessage
  10360. DEBUG_INFO("errorCode: %s\n", errorCode);
  10361. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  10362. DEBUG_INFO("errorDetails: %s\n", payload);
  10363. #endif
  10364. }
  10365. //===============================================
  10366. // Common routine
  10367. //===============================================
  10368. int initialConfigurationTable(void)
  10369. {
  10370. //clock_t start_t, end_t, total_t;
  10371. FILE *fp;
  10372. FILE *outfile;
  10373. char str[512]={0};
  10374. char sstr[256]={0};
  10375. int c = 0;
  10376. char *loc;
  10377. int confVersion = 1;
  10378. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  10379. //start_t = clock();
  10380. //printf("Starting of the program, start_t = %ld\n", start_t);
  10381. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  10382. // Check configuration file size is correct
  10383. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  10384. {
  10385. struct stat st;
  10386. stat("/Storage/OCPP/OCPPConfiguration", &st);
  10387. if(st.st_size < 3100)
  10388. {
  10389. system("rm -f /Storage/OCPP/OCPPConfiguration");
  10390. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  10391. }
  10392. }
  10393. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  10394. {
  10395. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10396. if(outfile == NULL)
  10397. {
  10398. DEBUG_INFO("Error opening file\n");
  10399. return FALSE;
  10400. }
  10401. /*Core Profile*/
  10402. //AllowOfflineTxForUnknownId
  10403. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10404. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10405. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  10406. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10407. //AuthorizationCacheEnabled
  10408. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10409. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10410. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10411. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10412. //AuthorizeRemoteTxRequests
  10413. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10414. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10415. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  10416. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10417. //BlinkRepeat
  10418. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10419. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10420. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10421. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10422. //ClockAlignedDataInterval
  10423. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10424. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10425. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10426. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10427. //ConnectionTimeOut
  10428. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10429. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10430. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10431. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10432. //GetConfigurationMaxKeys
  10433. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10434. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10435. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  10436. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10437. // HeartbeatInterval
  10438. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10439. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10440. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  10441. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10442. // LightIntensity
  10443. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10444. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10445. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10446. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10447. // LocalAuthorizeOffline
  10448. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  10449. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10450. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10451. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10452. // LocalPreAuthorize
  10453. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10454. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10455. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10456. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10457. // MaxEnergyOnInvalidId
  10458. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10459. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10460. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10461. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10462. // MeterValuesAlignedData
  10463. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10464. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10465. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10466. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10467. else
  10468. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10469. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10470. // MeterValuesAlignedDataMaxLength
  10471. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10472. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10473. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10474. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  10475. else
  10476. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "9" );
  10477. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10478. // MeterValuesSampledData
  10479. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10480. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10481. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10482. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10483. else
  10484. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10485. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10486. // MeterValuesSampledDataMaxLength
  10487. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10488. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10489. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10490. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  10491. else
  10492. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "9" );
  10493. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10494. // MeterValueSampleInterval
  10495. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10496. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10497. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  10498. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10499. // MinimumStatusDuration
  10500. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10501. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10502. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  10503. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  10504. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10505. // NumberOfConnectors
  10506. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10507. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10508. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10509. {
  10510. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10511. }
  10512. else
  10513. {
  10514. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10515. }
  10516. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10517. // ResetRetries
  10518. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10519. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10520. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10521. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10522. // ConnectorPhaseRotation
  10523. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10524. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10525. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10526. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10527. // ConnectorPhaseRotationMaxLength
  10528. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10529. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10530. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10531. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10532. // StopTransactionOnEVSideDisconnect
  10533. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10534. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10535. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10536. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10537. // StopTransactionOnInvalidId
  10538. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  10539. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10540. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10541. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10542. // StopTxnAlignedData
  10543. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10544. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10545. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10546. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10547. // StopTxnAlignedDataMaxLength
  10548. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10549. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10550. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10551. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10552. // StopTxnSampledData
  10553. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10554. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10555. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10556. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10557. else
  10558. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10559. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10560. // StopTxnSampledDataMaxLength
  10561. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10562. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10563. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10564. {
  10565. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  10566. }
  10567. else
  10568. {
  10569. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  10570. }
  10571. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10572. // SupportedFeatureProfiles
  10573. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10574. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10575. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10576. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10577. // SupportedFeatureProfilesMaxLength
  10578. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10579. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10580. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10581. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10582. // TransactionMessageAttempts
  10583. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10584. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10585. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10586. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10587. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10588. // TransactionMessageRetryInterval
  10589. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10590. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10591. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10592. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10593. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10594. // UnlockConnectorOnEVSideDisconnect
  10595. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10596. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10597. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10598. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10599. // WebSocketPingInterval
  10600. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10601. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10602. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10603. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10604. // QueueOffLineStartTransactionMessage
  10605. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  10606. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10607. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10608. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10609. // AuthorizationKey
  10610. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  10611. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  10612. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "" );
  10613. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  10614. // SecurityProfile
  10615. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  10616. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  10617. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "0" );
  10618. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  10619. // DefaultPrice
  10620. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  10621. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  10622. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  10623. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  10624. // CustomDisplayCostAndPrice
  10625. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  10626. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  10627. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  10628. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  10629. // CustomIdleFeeAfterStop
  10630. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  10631. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  10632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  10633. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  10634. // Configuration Version
  10635. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  10636. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  10637. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  10638. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  10639. //* Local Auth List Management Profile*/
  10640. #if 0
  10641. //For OCTT Test Case
  10642. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10643. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10644. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10645. #endif
  10646. #if 1
  10647. //LocalAuthListEnabled
  10648. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10649. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10650. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10651. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10652. #endif
  10653. //LocalAuthListMaxLength
  10654. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10655. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10656. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10657. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10658. //SendLocalListMaxLength
  10659. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10660. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10661. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  10662. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10663. //ReserveConnectorZeroSupported
  10664. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10665. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10666. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10667. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10668. //* Smart Charging Profile */
  10669. //ChargeProfileMaxStackLevel
  10670. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10671. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10672. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10673. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10674. // ChargingScheduleAllowedChargingRateUnit
  10675. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10676. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10677. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10678. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10679. // ChargingScheduleMaxPeriods
  10680. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10681. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10682. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10683. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10684. // ConnectorSwitch3to1PhaseSupported
  10685. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10686. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10687. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10688. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10689. // MaxChargingProfilesInstalled
  10690. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10691. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10692. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  10693. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10694. fclose(outfile);
  10695. }
  10696. else
  10697. {
  10698. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10699. char keystr[60]={0};
  10700. char readonlystr[10]={0};
  10701. char valuestr[256]={0};
  10702. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10703. if(fp == NULL) {
  10704. DEBUG_INFO("Error opening file");
  10705. return FALSE;
  10706. }
  10707. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  10708. {
  10709. //DEBUG_INFO("Get Configuration \n");
  10710. if(strlen(str) > 0)
  10711. {
  10712. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10713. //*************************key*********************************/
  10714. if(strstr(str, "key") != NULL)
  10715. {
  10716. loc = strstr(str, "key");
  10717. c = 0;
  10718. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10719. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  10720. {
  10721. sstr[c] = loc[strlen("key")+3+c];
  10722. c++;
  10723. }
  10724. sstr[c] = '\0';
  10725. strcpy(keystr,sstr);
  10726. }
  10727. //*************************readonly*********************************/
  10728. if(strstr(str, "readonly") != NULL)
  10729. {
  10730. loc = strstr(str, "readonly");
  10731. c = 0;
  10732. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10733. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  10734. {
  10735. sstr[c] = loc[strlen("readonly")+2+c];
  10736. c++;
  10737. }
  10738. sstr[c] = '\0';
  10739. strcpy(readonlystr,sstr);
  10740. }
  10741. //*************************value*********************************/
  10742. if(strstr(str, "value") != NULL)
  10743. {
  10744. loc = strstr(str, "value");
  10745. c = 0;
  10746. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10747. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  10748. {
  10749. sstr[c] = loc[strlen("value")+3+c];
  10750. c++;
  10751. }
  10752. sstr[c] = '\0';
  10753. strcpy(valuestr,sstr);
  10754. }
  10755. // DEBUG_INFO("keystr=%s\n",keystr);
  10756. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10757. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10758. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10759. {
  10760. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10761. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10762. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10763. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10764. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10765. }
  10766. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10767. {
  10768. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10769. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10770. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10771. }
  10772. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10773. {
  10774. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10775. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10776. }
  10777. if(strcmp(keystr, "BlinkRepeat") == 0)
  10778. {
  10779. //Charger.BlinkRepeat = Integer.parseInt(value);
  10780. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10781. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10782. }
  10783. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10784. {
  10785. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10786. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10787. }
  10788. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10789. {
  10790. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10791. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10792. }
  10793. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10794. {
  10795. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10796. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  10797. }
  10798. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10799. {
  10800. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10801. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10802. HeartBeatWaitTime = atoi(valuestr);
  10803. }
  10804. if(strcmp(keystr, "LightIntensity") == 0)
  10805. {
  10806. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10807. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10808. }
  10809. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10810. {
  10811. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10812. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10813. }
  10814. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10815. {
  10816. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10817. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10818. }
  10819. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10820. {
  10821. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10822. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10823. }
  10824. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10825. {
  10826. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10827. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10828. }
  10829. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10830. {
  10831. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10832. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10833. }
  10834. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10835. {
  10836. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10837. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10838. }
  10839. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10840. {
  10841. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10842. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10843. }
  10844. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10845. {
  10846. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10847. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10848. }
  10849. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10850. {
  10851. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10852. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10853. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10854. }
  10855. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10856. {
  10857. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10858. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10859. }
  10860. if(strcmp(keystr, "ResetRetries") == 0)
  10861. {
  10862. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10863. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10864. }
  10865. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10866. {
  10867. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10868. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10869. }
  10870. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10871. {
  10872. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10873. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10874. }
  10875. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10876. {
  10877. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10878. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10879. }
  10880. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10881. {
  10882. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10883. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10884. }
  10885. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10886. {
  10887. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10888. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10889. }
  10890. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10891. {
  10892. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10893. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10894. }
  10895. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10896. {
  10897. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10898. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10899. }
  10900. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10901. {
  10902. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10903. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10904. }
  10905. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10906. {
  10907. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10908. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10909. }
  10910. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10911. {
  10912. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10913. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10914. }
  10915. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10916. {
  10917. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10918. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10919. TransactionMessageAttemptsValue = atoi(valuestr);
  10920. }
  10921. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10922. {
  10923. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10924. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10925. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10926. }
  10927. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10928. {
  10929. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10930. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10931. }
  10932. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10933. {
  10934. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10935. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10936. }
  10937. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  10938. {
  10939. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10940. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  10941. }
  10942. if(strcmp(keystr, "AuthorizationKey") == 0)
  10943. {
  10944. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10945. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  10946. }
  10947. if(strcmp(keystr, "SecurityProfile") == 0)
  10948. {
  10949. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10950. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  10951. }
  10952. if(strcmp(keystr, "DefaultPrice") == 0)
  10953. {
  10954. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10955. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  10956. }
  10957. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  10958. {
  10959. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10960. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  10961. }
  10962. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  10963. {
  10964. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10965. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  10966. }
  10967. if(strcmp(keystr, "ConfigurationVersion") == 0)
  10968. {
  10969. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10970. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  10971. }
  10972. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10973. {
  10974. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10975. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10976. }
  10977. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10978. {
  10979. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10980. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10981. }
  10982. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10983. {
  10984. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10985. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10986. }
  10987. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10988. {
  10989. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10990. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10991. }
  10992. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10993. {
  10994. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10995. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10996. }
  10997. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10998. {
  10999. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11000. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  11001. }
  11002. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  11003. {
  11004. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11005. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  11006. }
  11007. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  11008. {
  11009. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11010. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  11011. }
  11012. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  11013. {
  11014. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11015. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  11016. }
  11017. }
  11018. }
  11019. fclose(fp);
  11020. }
  11021. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  11022. {
  11023. return PASS;
  11024. }
  11025. else
  11026. {
  11027. return FAIL;
  11028. }
  11029. }
  11030. void StoreConfigurationTable(void)
  11031. {
  11032. FILE *outfile;
  11033. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  11034. if(outfile == NULL)
  11035. {
  11036. DEBUG_INFO("Error opening file");
  11037. return ;
  11038. }
  11039. /*Core Profile*/
  11040. //AllowOfflineTxForUnknownId
  11041. /*
  11042. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11043. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  11044. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11045. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  11046. */
  11047. //DEBUG_INFO("data=%s\n",data);
  11048. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11049. //AuthorizationCacheEnabled
  11050. /*
  11051. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11052. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11053. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11054. */
  11055. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11056. //AuthorizeRemoteTxRequests
  11057. /*
  11058. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11059. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11060. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  11061. */
  11062. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11063. //BlinkRepeat
  11064. /*
  11065. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11066. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11067. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11068. */
  11069. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11070. //ClockAlignedDataInterval
  11071. /*
  11072. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11073. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11074. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11075. */
  11076. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11077. //ConnectionTimeOut
  11078. /*
  11079. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11080. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11081. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11082. */
  11083. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11084. //GetConfigurationMaxKeys
  11085. /*
  11086. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11087. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11088. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  11089. */
  11090. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11091. // HeartbeatInterval
  11092. /*
  11093. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11094. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11095. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  11096. */
  11097. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11098. // LightIntensity
  11099. /*
  11100. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11101. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11102. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11103. */
  11104. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11105. // LocalAuthorizeOffline
  11106. /*
  11107. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  11108. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11109. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11110. */
  11111. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11112. // LocalPreAuthorize
  11113. /*
  11114. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  11115. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11116. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11117. */
  11118. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11119. // MaxEnergyOnInvalidId
  11120. /*
  11121. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11122. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  11123. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  11124. */
  11125. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  11126. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  11127. // MeterValuesAlignedData
  11128. /*
  11129. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  11130. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  11131. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  11132. */
  11133. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  11134. // MeterValuesAlignedDataMaxLength
  11135. /*
  11136. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  11137. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  11138. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  11139. */
  11140. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  11141. // MeterValuesSampledData
  11142. /*
  11143. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  11144. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  11145. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  11146. */
  11147. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  11148. // MeterValuesSampledDataMaxLength
  11149. /*
  11150. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  11151. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  11152. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  11153. */
  11154. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  11155. // MeterValueSampleInterval
  11156. /*
  11157. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  11158. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  11159. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  11160. */
  11161. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  11162. // MinimumStatusDuration
  11163. /*
  11164. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  11165. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  11166. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  11167. */
  11168. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  11169. // NumberOfConnectors
  11170. /*
  11171. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  11172. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  11173. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11174. {
  11175. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  11176. }
  11177. else
  11178. {
  11179. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  11180. }
  11181. */
  11182. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  11183. // ResetRetries
  11184. /*
  11185. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  11186. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  11187. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  11188. */
  11189. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  11190. // ConnectorPhaseRotation
  11191. /*
  11192. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  11193. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  11194. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  11195. */
  11196. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  11197. // ConnectorPhaseRotationMaxLength
  11198. /*
  11199. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  11200. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  11201. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  11202. */
  11203. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  11204. // StopTransactionOnEVSideDisconnect
  11205. /*
  11206. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  11207. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  11208. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  11209. */
  11210. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  11211. // StopTransactionOnInvalidId
  11212. /*
  11213. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  11214. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  11215. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  11216. */
  11217. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  11218. // StopTxnAlignedData
  11219. /*
  11220. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  11221. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  11222. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  11223. */
  11224. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  11225. // StopTxnAlignedDataMaxLength
  11226. /*
  11227. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  11228. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  11229. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11230. */
  11231. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11232. // StopTxnSampledData
  11233. /*
  11234. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11235. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11236. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  11237. */
  11238. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11239. // StopTxnSampledDataMaxLength
  11240. /*
  11241. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11242. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11243. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  11244. */
  11245. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11246. // SupportedFeatureProfiles
  11247. /*
  11248. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11249. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11250. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11251. */
  11252. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  11253. // SupportedFeatureProfilesMaxLength
  11254. /*
  11255. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  11256. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  11257. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  11258. */
  11259. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  11260. // TransactionMessageAttempts
  11261. /*
  11262. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11263. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11264. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11265. */
  11266. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11267. // TransactionMessageRetryInterval
  11268. /*
  11269. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11270. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11271. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11272. */
  11273. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11274. // UnlockConnectorOnEVSideDisconnect
  11275. /*
  11276. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11277. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11278. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11279. */
  11280. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11281. // WebSocketPingInterval
  11282. /*
  11283. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11284. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11285. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11286. */
  11287. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11288. // QueueOffLineStartTransactionMessage
  11289. /*
  11290. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  11291. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  11292. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  11293. */
  11294. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  11295. // AuthorizationKey
  11296. /*
  11297. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  11298. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  11299. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  11300. */
  11301. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  11302. // SecurityProfile
  11303. /*
  11304. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  11305. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  11306. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  11307. */
  11308. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  11309. // DefaultPrice
  11310. /*
  11311. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  11312. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  11313. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  11314. */
  11315. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  11316. // CustomDisplayCostAndPrice
  11317. /*
  11318. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  11319. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  11320. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  11321. */
  11322. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  11323. // CustomIdleFeeAfterStop
  11324. /*
  11325. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  11326. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  11327. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  11328. */
  11329. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  11330. // ConfigurationVersion
  11331. /*
  11332. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  11333. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  11334. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  11335. */
  11336. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  11337. //* Local Auth List Management Profile*/
  11338. //LocalAuthListEnabled
  11339. /*
  11340. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11341. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  11342. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11343. */
  11344. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11345. //LocalAuthListMaxLength
  11346. /*
  11347. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  11348. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  11349. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  11350. */
  11351. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  11352. //SendLocalListMaxLength
  11353. /*
  11354. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  11355. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11356. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  11357. */
  11358. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11359. //ReserveConnectorZeroSupported
  11360. /*
  11361. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11362. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11363. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11364. */
  11365. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11366. //* Smart Charging Profile */
  11367. //ChargeProfileMaxStackLevel
  11368. /*
  11369. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11370. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11371. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11372. */
  11373. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11374. // ChargingScheduleAllowedChargingRateUnit
  11375. /*
  11376. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11377. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11378. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  11379. */
  11380. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11381. // ChargingScheduleMaxPeriods
  11382. /*
  11383. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11384. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11385. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11386. */
  11387. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11388. // ConnectorSwitch3to1PhaseSupported
  11389. /*
  11390. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11391. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11392. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  11393. */
  11394. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11395. // MaxChargingProfilesInstalled
  11396. /*
  11397. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11398. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11399. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  11400. */
  11401. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11402. fclose(outfile);
  11403. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11404. }
  11405. void getKeyValue(char *keyReq)
  11406. {
  11407. int isEmpty = FALSE;
  11408. int isKnowKey = FALSE;
  11409. DEBUG_INFO("keyReq = %s\n", keyReq);
  11410. if((keyReq == NULL) || (strlen(keyReq) == 0))
  11411. isEmpty = TRUE;
  11412. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  11413. {
  11414. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  11415. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  11416. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11417. {
  11418. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  11419. }
  11420. else
  11421. {
  11422. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  11423. }
  11424. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  11425. isKnowKey = TRUE;
  11426. }
  11427. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  11428. {
  11429. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  11430. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  11431. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11432. {
  11433. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  11434. }
  11435. else
  11436. {
  11437. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  11438. }
  11439. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  11440. isKnowKey = TRUE;
  11441. }
  11442. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  11443. {
  11444. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  11445. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  11446. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11447. {
  11448. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  11449. }
  11450. else
  11451. {
  11452. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  11453. }
  11454. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  11455. isKnowKey = TRUE;
  11456. }
  11457. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  11458. {
  11459. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  11460. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  11461. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11462. {
  11463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  11464. }
  11465. else
  11466. {
  11467. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  11468. }
  11469. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  11470. isKnowKey = TRUE;
  11471. }
  11472. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  11473. {
  11474. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  11475. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  11476. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11477. {
  11478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  11479. }
  11480. else
  11481. {
  11482. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  11483. }
  11484. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  11485. isKnowKey = TRUE;
  11486. }
  11487. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  11488. {
  11489. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  11490. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  11491. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11492. {
  11493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  11494. }
  11495. else
  11496. {
  11497. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  11498. }
  11499. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  11500. isKnowKey = TRUE;
  11501. }
  11502. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  11503. {
  11504. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  11505. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  11506. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11507. {
  11508. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  11509. }
  11510. else
  11511. {
  11512. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  11513. }
  11514. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  11515. isKnowKey = TRUE;
  11516. }
  11517. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  11518. {
  11519. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  11520. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  11521. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11522. {
  11523. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  11524. }
  11525. else
  11526. {
  11527. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  11528. }
  11529. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  11530. isKnowKey = TRUE;
  11531. }
  11532. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  11533. {
  11534. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  11535. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  11536. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11537. {
  11538. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  11539. }
  11540. else
  11541. {
  11542. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  11543. }
  11544. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  11545. isKnowKey = TRUE;
  11546. }
  11547. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  11548. {
  11549. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  11550. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  11551. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11552. {
  11553. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  11554. }
  11555. else
  11556. {
  11557. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  11558. }
  11559. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  11560. isKnowKey = TRUE;
  11561. }
  11562. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  11563. {
  11564. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  11565. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  11566. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11567. {
  11568. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  11569. }
  11570. else
  11571. {
  11572. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  11573. }
  11574. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  11575. isKnowKey = TRUE;
  11576. }
  11577. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  11578. {
  11579. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  11580. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  11581. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11582. {
  11583. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11584. }
  11585. else
  11586. {
  11587. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11588. }
  11589. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  11590. isKnowKey = TRUE;
  11591. }
  11592. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  11593. {
  11594. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  11595. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11596. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11597. {
  11598. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11599. }
  11600. else
  11601. {
  11602. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11603. }
  11604. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11605. isKnowKey = TRUE;
  11606. }
  11607. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11608. {
  11609. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11611. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11612. {
  11613. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11614. }
  11615. else
  11616. {
  11617. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11618. }
  11619. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11620. isKnowKey = TRUE;
  11621. }
  11622. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11623. {
  11624. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11625. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11626. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11627. {
  11628. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11629. }
  11630. else
  11631. {
  11632. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11633. }
  11634. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11635. isKnowKey = TRUE;
  11636. }
  11637. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11638. {
  11639. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11640. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11641. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11642. {
  11643. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11644. }
  11645. else
  11646. {
  11647. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11648. }
  11649. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11650. isKnowKey = TRUE;
  11651. }
  11652. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11653. {
  11654. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11655. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11656. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11657. {
  11658. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11659. }
  11660. else
  11661. {
  11662. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11663. }
  11664. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11665. isKnowKey = TRUE;
  11666. }
  11667. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11668. {
  11669. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11670. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11671. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11672. {
  11673. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11674. }
  11675. else
  11676. {
  11677. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11678. }
  11679. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11680. isKnowKey = TRUE;
  11681. }
  11682. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11683. {
  11684. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11685. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11686. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11687. {
  11688. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11689. }
  11690. else
  11691. {
  11692. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11693. }
  11694. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  11695. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11696. isKnowKey = TRUE;
  11697. }
  11698. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11699. {
  11700. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11701. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11702. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11703. {
  11704. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11705. }
  11706. else
  11707. {
  11708. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11709. }
  11710. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11711. isKnowKey = TRUE;
  11712. }
  11713. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11714. {
  11715. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11716. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11717. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11718. {
  11719. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11720. }
  11721. else
  11722. {
  11723. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11724. }
  11725. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11726. isKnowKey = TRUE;
  11727. }
  11728. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11729. {
  11730. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11731. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11732. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11733. {
  11734. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11735. }
  11736. else
  11737. {
  11738. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11739. }
  11740. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11741. isKnowKey = TRUE;
  11742. }
  11743. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11744. {
  11745. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11746. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11747. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11748. {
  11749. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11750. }
  11751. else
  11752. {
  11753. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11754. }
  11755. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11756. isKnowKey = TRUE;
  11757. }
  11758. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11759. {
  11760. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11761. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11762. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11763. {
  11764. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11765. }
  11766. else
  11767. {
  11768. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11769. }
  11770. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11771. isKnowKey = TRUE;
  11772. }
  11773. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11774. {
  11775. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11776. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11777. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11778. {
  11779. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11780. }
  11781. else
  11782. {
  11783. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11784. }
  11785. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11786. isKnowKey = TRUE;
  11787. }
  11788. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11789. {
  11790. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11791. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11792. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11793. {
  11794. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11795. }
  11796. else
  11797. {
  11798. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11799. }
  11800. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11801. isKnowKey = TRUE;
  11802. }
  11803. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11804. {
  11805. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11806. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11807. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11808. {
  11809. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11810. }
  11811. else
  11812. {
  11813. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11814. }
  11815. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11816. isKnowKey = TRUE;
  11817. }
  11818. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11819. {
  11820. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11821. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11822. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11823. {
  11824. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11825. }
  11826. else
  11827. {
  11828. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11829. }
  11830. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11831. isKnowKey = TRUE;
  11832. }
  11833. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11834. {
  11835. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11836. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11837. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11838. {
  11839. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11840. }
  11841. else
  11842. {
  11843. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11844. }
  11845. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11846. isKnowKey = TRUE;
  11847. }
  11848. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11849. {
  11850. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11851. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11852. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11853. {
  11854. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11855. }
  11856. else
  11857. {
  11858. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11859. }
  11860. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11861. isKnowKey = TRUE;
  11862. }
  11863. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11864. {
  11865. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11866. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11867. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11868. {
  11869. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11870. }
  11871. else
  11872. {
  11873. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11874. }
  11875. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11876. isKnowKey = TRUE;
  11877. }
  11878. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11879. {
  11880. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11881. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11882. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11883. {
  11884. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11885. }
  11886. else
  11887. {
  11888. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11889. }
  11890. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11891. isKnowKey = TRUE;
  11892. }
  11893. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11894. {
  11895. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11896. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11897. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11898. {
  11899. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11900. }
  11901. else
  11902. {
  11903. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11904. }
  11905. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11906. isKnowKey = TRUE;
  11907. }
  11908. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11909. {
  11910. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11911. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11912. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11913. {
  11914. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11915. }
  11916. else
  11917. {
  11918. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11919. }
  11920. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11921. isKnowKey = TRUE;
  11922. }
  11923. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  11924. {
  11925. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  11926. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  11927. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  11928. {
  11929. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  11930. }
  11931. else
  11932. {
  11933. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  11934. }
  11935. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  11936. isKnowKey = TRUE;
  11937. }
  11938. /*
  11939. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  11940. {
  11941. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  11942. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  11943. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  11944. {
  11945. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  11946. }
  11947. else
  11948. {
  11949. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  11950. }
  11951. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  11952. isKnowKey = TRUE;
  11953. }*/
  11954. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  11955. {
  11956. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  11957. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  11958. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  11959. {
  11960. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  11961. }
  11962. else
  11963. {
  11964. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  11965. }
  11966. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  11967. isKnowKey = TRUE;
  11968. }
  11969. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  11970. {
  11971. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  11972. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  11973. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  11974. {
  11975. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  11976. }
  11977. else
  11978. {
  11979. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  11980. }
  11981. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  11982. isKnowKey = TRUE;
  11983. }
  11984. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  11985. {
  11986. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  11987. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  11988. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  11989. {
  11990. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  11991. }
  11992. else
  11993. {
  11994. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  11995. }
  11996. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  11997. isKnowKey = TRUE;
  11998. }
  11999. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  12000. {
  12001. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  12002. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  12003. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  12004. {
  12005. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  12006. }
  12007. else
  12008. {
  12009. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  12010. }
  12011. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  12012. isKnowKey = TRUE;
  12013. }
  12014. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  12015. {
  12016. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  12017. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  12018. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  12019. {
  12020. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  12021. }
  12022. else
  12023. {
  12024. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  12025. }
  12026. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  12027. isKnowKey = TRUE;
  12028. }
  12029. #if 1
  12030. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  12031. {
  12032. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  12033. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  12034. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12035. {
  12036. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  12037. }
  12038. else
  12039. {
  12040. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  12041. }
  12042. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  12043. isKnowKey = TRUE;
  12044. }
  12045. #endif
  12046. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  12047. {
  12048. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  12049. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  12050. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12051. {
  12052. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12053. }
  12054. else
  12055. {
  12056. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12057. }
  12058. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  12059. isKnowKey = TRUE;
  12060. }
  12061. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  12062. {
  12063. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  12064. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  12065. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12066. {
  12067. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12068. }
  12069. else
  12070. {
  12071. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12072. }
  12073. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  12074. isKnowKey = TRUE;
  12075. }
  12076. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  12077. {
  12078. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  12079. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  12080. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12081. {
  12082. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  12083. }
  12084. else
  12085. {
  12086. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  12087. }
  12088. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12089. isKnowKey = TRUE;
  12090. }
  12091. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  12092. {
  12093. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  12094. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  12095. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12096. {
  12097. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  12098. }
  12099. else
  12100. {
  12101. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  12102. }
  12103. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12104. isKnowKey = TRUE;
  12105. }
  12106. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  12107. {
  12108. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  12109. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  12110. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12111. {
  12112. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  12113. }
  12114. else
  12115. {
  12116. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  12117. }
  12118. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12119. isKnowKey = TRUE;
  12120. }
  12121. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  12122. {
  12123. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  12124. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  12125. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12126. {
  12127. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  12128. }
  12129. else
  12130. {
  12131. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  12132. }
  12133. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12134. isKnowKey = TRUE;
  12135. }
  12136. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  12137. {
  12138. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  12139. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  12140. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12141. {
  12142. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  12143. }
  12144. else
  12145. {
  12146. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  12147. }
  12148. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12149. isKnowKey = TRUE;
  12150. }
  12151. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  12152. {
  12153. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  12154. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  12155. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12156. {
  12157. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  12158. }
  12159. else
  12160. {
  12161. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  12162. }
  12163. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12164. isKnowKey = TRUE;
  12165. }
  12166. //=========================================================
  12167. if(!isEmpty && !isKnowKey)
  12168. {
  12169. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  12170. strcpy(unknownkey[UnknownKeynum], keyReq);
  12171. UnknownKeynum = UnknownKeynum + 1;
  12172. }
  12173. }
  12174. void processUnkownKey(void)
  12175. {
  12176. DEBUG_INFO("processUnkownKey...\n");
  12177. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  12178. for(int index=0; index < UnknownKeynum; index++)
  12179. {
  12180. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  12181. {
  12182. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  12183. }
  12184. }
  12185. }
  12186. int setKeyValue(char *key, char *value)
  12187. {
  12188. int isSuccess = NotSupported;
  12189. int check_ascii=0;
  12190. char str[256]={0};
  12191. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  12192. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  12193. {
  12194. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  12195. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  12196. {
  12197. strcpy(str, (const char*)value);
  12198. for(int i = 0; str[i]; i++){
  12199. str[i] = tolower(str[i]);
  12200. }
  12201. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12202. isSuccess = ConfigurationStatus_Accepted;
  12203. }
  12204. else
  12205. {
  12206. isSuccess = ConfigurationStatus_Rejected;
  12207. }
  12208. }
  12209. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  12210. {
  12211. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  12212. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  12213. {
  12214. strcpy(str, (const char*)value);
  12215. for(int i = 0; str[i]; i++){
  12216. str[i] = tolower(str[i]);
  12217. }
  12218. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12219. isSuccess = ConfigurationStatus_Accepted;
  12220. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  12221. }
  12222. else
  12223. {
  12224. isSuccess = ConfigurationStatus_Rejected;
  12225. }
  12226. }
  12227. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  12228. {
  12229. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  12230. {
  12231. strcpy(str, (const char*)value);
  12232. for(int i = 0; str[i]; i++)
  12233. {
  12234. str[i] = tolower(str[i]);
  12235. }
  12236. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  12237. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12238. isSuccess = ConfigurationStatus_Accepted;
  12239. }
  12240. else
  12241. {
  12242. isSuccess = ConfigurationStatus_Rejected;
  12243. }
  12244. }
  12245. if(strcmp(key, "BlinkRepeat") == 0)
  12246. {
  12247. //Charger.BlinkRepeat = Integer.parseInt(value);
  12248. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  12249. {
  12250. check_ascii = value[0];
  12251. if( (check_ascii < 48) || (check_ascii > 57) )
  12252. {
  12253. isSuccess = ConfigurationStatus_Rejected;
  12254. }
  12255. else
  12256. {
  12257. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  12258. isSuccess = ConfigurationStatus_Accepted;
  12259. }
  12260. }
  12261. else
  12262. {
  12263. isSuccess = ConfigurationStatus_Rejected;
  12264. }
  12265. }
  12266. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  12267. {
  12268. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  12269. {
  12270. check_ascii = value[0];
  12271. if( (check_ascii < 48) || (check_ascii > 57) )
  12272. {
  12273. isSuccess = ConfigurationStatus_Rejected;
  12274. }
  12275. else
  12276. {
  12277. if((atoi(value) == 0) || (atoi(value) >= 10))
  12278. {
  12279. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  12280. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  12281. isSuccess = ConfigurationStatus_Accepted;
  12282. }
  12283. else
  12284. isSuccess = ConfigurationStatus_Rejected;
  12285. }
  12286. }
  12287. else
  12288. {
  12289. isSuccess = ConfigurationStatus_Rejected;
  12290. }
  12291. }
  12292. if(strcmp(key, "ConnectionTimeOut") == 0 )
  12293. {
  12294. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  12295. {
  12296. check_ascii = value[0];
  12297. if( (check_ascii < 48) || (check_ascii > 57) )
  12298. {
  12299. isSuccess = ConfigurationStatus_Rejected;
  12300. }
  12301. else
  12302. {
  12303. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  12304. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  12305. isSuccess = ConfigurationStatus_Accepted;
  12306. }
  12307. }
  12308. else
  12309. {
  12310. isSuccess = ConfigurationStatus_Rejected;
  12311. }
  12312. }
  12313. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  12314. {
  12315. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  12316. {
  12317. check_ascii = value[0];
  12318. if( (check_ascii < 48) || (check_ascii > 57) )
  12319. {
  12320. isSuccess = ConfigurationStatus_Rejected;
  12321. }
  12322. else
  12323. {
  12324. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  12325. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  12326. isSuccess = ConfigurationStatus_Accepted;
  12327. }
  12328. }
  12329. else
  12330. {
  12331. isSuccess = ConfigurationStatus_Rejected;
  12332. }
  12333. }
  12334. if(strcmp(key, "HeartbeatInterval") == 0)
  12335. {
  12336. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  12337. {
  12338. check_ascii = value[0];
  12339. if( (check_ascii < 48) || (check_ascii > 57) )
  12340. {
  12341. isSuccess = ConfigurationStatus_Rejected;
  12342. }
  12343. else
  12344. {
  12345. if((atoi(value) == 0) || (atoi(value) >= 10))
  12346. {
  12347. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  12348. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  12349. HeartBeatWaitTime = atoi(value);
  12350. isSuccess = ConfigurationStatus_Accepted;
  12351. }
  12352. else
  12353. {
  12354. isSuccess = ConfigurationStatus_Rejected;
  12355. }
  12356. }
  12357. }
  12358. else
  12359. {
  12360. isSuccess = ConfigurationStatus_Rejected;
  12361. }
  12362. }
  12363. if(strcmp(key, "LightIntensity") == 0)
  12364. {
  12365. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  12366. {
  12367. check_ascii = value[0];
  12368. if( (check_ascii < 48) || (check_ascii > 57) )
  12369. {
  12370. isSuccess = ConfigurationStatus_Rejected;
  12371. }
  12372. else
  12373. {
  12374. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  12375. isSuccess = ConfigurationStatus_Accepted;
  12376. }
  12377. }
  12378. else
  12379. {
  12380. isSuccess = ConfigurationStatus_Rejected;
  12381. }
  12382. }
  12383. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  12384. {
  12385. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  12386. {
  12387. strcpy(str, (const char*)value);
  12388. for(int i = 0; str[i]; i++)
  12389. {
  12390. str[i] = tolower(str[i]);
  12391. }
  12392. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12393. isSuccess = ConfigurationStatus_Accepted;
  12394. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12395. }
  12396. else
  12397. {
  12398. isSuccess = ConfigurationStatus_Rejected;
  12399. }
  12400. }
  12401. if(strcmp(key, "LocalPreAuthorize") == 0)
  12402. {
  12403. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12404. {
  12405. strcpy(str, (const char*)value);
  12406. for(int i = 0; str[i]; i++)
  12407. {
  12408. str[i] = tolower(str[i]);
  12409. }
  12410. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12411. isSuccess = ConfigurationStatus_Accepted;
  12412. }
  12413. else
  12414. {
  12415. isSuccess = ConfigurationStatus_Rejected;
  12416. }
  12417. }
  12418. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  12419. {
  12420. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  12421. {
  12422. check_ascii = value[0];
  12423. if( (check_ascii < 48) || (check_ascii > 57) )
  12424. {
  12425. isSuccess = ConfigurationStatus_Rejected;
  12426. }
  12427. else
  12428. {
  12429. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  12430. isSuccess = ConfigurationStatus_Accepted;
  12431. }
  12432. }
  12433. else
  12434. {
  12435. isSuccess = ConfigurationStatus_Rejected;
  12436. }
  12437. }
  12438. if(strcmp(key, "MeterValuesAlignedData") == 0)
  12439. {
  12440. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12441. {
  12442. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  12443. isSuccess = ConfigurationStatus_Accepted;
  12444. }
  12445. else
  12446. {
  12447. isSuccess = ConfigurationStatus_Rejected;
  12448. }
  12449. }
  12450. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  12451. {
  12452. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12453. {
  12454. check_ascii = value[0];
  12455. if( (check_ascii < 48) || (check_ascii > 57) )
  12456. {
  12457. isSuccess = ConfigurationStatus_Rejected;
  12458. }
  12459. else
  12460. {
  12461. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12462. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  12463. isSuccess = ConfigurationStatus_Accepted;
  12464. }
  12465. }
  12466. else
  12467. {
  12468. isSuccess = ConfigurationStatus_Rejected;
  12469. }
  12470. }
  12471. if(strcmp(key, "MeterValuesSampledData") == 0 )
  12472. {
  12473. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12474. {
  12475. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  12476. isSuccess = ConfigurationStatus_Accepted;
  12477. }
  12478. else
  12479. {
  12480. isSuccess = ConfigurationStatus_Rejected;
  12481. }
  12482. }
  12483. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  12484. {
  12485. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12486. {
  12487. check_ascii = value[0];
  12488. if( (check_ascii < 48) || (check_ascii > 57) )
  12489. {
  12490. isSuccess = ConfigurationStatus_Rejected;
  12491. }
  12492. else
  12493. {
  12494. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12495. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  12496. isSuccess = ConfigurationStatus_Accepted;
  12497. }
  12498. }
  12499. else
  12500. {
  12501. isSuccess = ConfigurationStatus_Rejected;
  12502. }
  12503. }
  12504. if(strcmp(key, "MeterValueSampleInterval") == 0)
  12505. {
  12506. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12507. {
  12508. check_ascii = value[0];
  12509. if( (check_ascii < 48) || (check_ascii > 57) )
  12510. {
  12511. isSuccess = ConfigurationStatus_Rejected;
  12512. }
  12513. else
  12514. {
  12515. if((atoi(value) == 0) || (atoi(value) >= 10))
  12516. {
  12517. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12518. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  12519. isSuccess = ConfigurationStatus_Accepted;
  12520. }
  12521. else
  12522. {
  12523. isSuccess = ConfigurationStatus_Rejected;
  12524. }
  12525. }
  12526. }
  12527. else
  12528. {
  12529. isSuccess = ConfigurationStatus_Rejected;
  12530. }
  12531. }
  12532. if(strcmp(key, "MinimumStatusDuration") == 0)
  12533. {
  12534. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12535. {
  12536. check_ascii = value[0];
  12537. if( (check_ascii < 48) || (check_ascii > 57) )
  12538. {
  12539. isSuccess = ConfigurationStatus_Rejected;
  12540. }
  12541. else
  12542. {
  12543. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  12544. {
  12545. isSuccess = ConfigurationStatus_Rejected;
  12546. }
  12547. else
  12548. {
  12549. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  12550. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  12551. server_cycle_Status = atoi(value); //StatusNotification Cycle
  12552. isSuccess = ConfigurationStatus_Accepted;
  12553. }
  12554. }
  12555. }
  12556. else
  12557. {
  12558. isSuccess = ConfigurationStatus_Rejected;
  12559. }
  12560. }
  12561. if(strcmp(key, "NumberOfConnectors") == 0)
  12562. {
  12563. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12564. {
  12565. check_ascii = value[0];
  12566. if( (check_ascii < 48) || (check_ascii > 57) )
  12567. {
  12568. isSuccess = ConfigurationStatus_Rejected;
  12569. }
  12570. else
  12571. {
  12572. //Charger.ResetRetries = Integer.parseInt(value);
  12573. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  12574. isSuccess = ConfigurationStatus_Accepted;
  12575. }
  12576. }
  12577. else
  12578. {
  12579. isSuccess = ConfigurationStatus_Rejected;
  12580. }
  12581. }
  12582. if(strcmp(key, "ResetRetries") == 0)
  12583. {
  12584. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12585. {
  12586. check_ascii = value[0];
  12587. if( (check_ascii < 48) || (check_ascii > 57) )
  12588. {
  12589. isSuccess = ConfigurationStatus_Rejected;
  12590. }
  12591. else
  12592. {
  12593. //Charger.ResetRetries = Integer.parseInt(value);
  12594. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  12595. isSuccess = ConfigurationStatus_Accepted;
  12596. }
  12597. }
  12598. else
  12599. {
  12600. isSuccess = ConfigurationStatus_Rejected;
  12601. }
  12602. }
  12603. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  12604. {
  12605. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12606. {
  12607. strcpy(str, (const char*)value);
  12608. for(int i = 0; str[i]; i++)
  12609. {
  12610. str[i] = tolower(str[i]);
  12611. }
  12612. if(strcmp(str, "notapplicable")== 0)
  12613. {
  12614. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12615. isSuccess = ConfigurationStatus_Accepted;
  12616. }
  12617. else if(strcmp(str, "unknown")== 0)
  12618. {
  12619. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12620. isSuccess = ConfigurationStatus_Accepted;
  12621. }
  12622. else if(strcmp(str, "rst")== 0)
  12623. {
  12624. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12625. isSuccess = ConfigurationStatus_Accepted;
  12626. }
  12627. else if(strcmp(str, "rts")== 0)
  12628. {
  12629. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12630. isSuccess = ConfigurationStatus_Accepted;
  12631. }
  12632. else if(strcmp(str, "srt")== 0)
  12633. {
  12634. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12635. isSuccess = ConfigurationStatus_Accepted;
  12636. }
  12637. else if(strcmp(str, "str")== 0)
  12638. {
  12639. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12640. isSuccess = ConfigurationStatus_Accepted;
  12641. }
  12642. else if(strcmp(str, "trs")== 0)
  12643. {
  12644. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12645. isSuccess = ConfigurationStatus_Accepted;
  12646. }
  12647. else if(strcmp(str, "tsr")== 0)
  12648. {
  12649. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12650. isSuccess = ConfigurationStatus_Accepted;
  12651. }
  12652. else
  12653. {
  12654. isSuccess = ConfigurationStatus_Rejected;
  12655. }
  12656. }
  12657. else
  12658. {
  12659. isSuccess = ConfigurationStatus_Rejected;
  12660. }
  12661. }
  12662. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12663. {
  12664. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12665. {
  12666. check_ascii = value[0];
  12667. if( (check_ascii < 48) || (check_ascii > 57) )
  12668. {
  12669. isSuccess = ConfigurationStatus_Rejected;
  12670. }
  12671. else
  12672. {
  12673. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12674. isSuccess = ConfigurationStatus_Accepted;
  12675. }
  12676. }
  12677. else
  12678. {
  12679. isSuccess = ConfigurationStatus_Rejected;
  12680. }
  12681. }
  12682. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12683. {
  12684. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12685. {
  12686. strcpy(str, (const char*)value);
  12687. for(int i = 0; str[i]; i++)
  12688. {
  12689. str[i] = tolower(str[i]);
  12690. }
  12691. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12692. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12693. isSuccess = ConfigurationStatus_Accepted;
  12694. }
  12695. else
  12696. {
  12697. isSuccess = ConfigurationStatus_Rejected;
  12698. }
  12699. }
  12700. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12701. {
  12702. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12703. {
  12704. strcpy(str, (const char*)value);
  12705. for(int i = 0; str[i]; i++)
  12706. {
  12707. str[i] = tolower(str[i]);
  12708. }
  12709. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12710. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12711. isSuccess = ConfigurationStatus_Accepted;
  12712. }
  12713. else
  12714. {
  12715. isSuccess = ConfigurationStatus_Rejected;
  12716. }
  12717. }
  12718. if(strcmp(key, "StopTxnAlignedData") == 0)
  12719. {
  12720. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12721. {
  12722. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12723. isSuccess = ConfigurationStatus_Accepted;
  12724. }
  12725. else
  12726. {
  12727. isSuccess = ConfigurationStatus_Rejected;
  12728. }
  12729. }
  12730. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12731. {
  12732. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12733. {
  12734. check_ascii = value[0];
  12735. if( (check_ascii < 48) || (check_ascii > 57) )
  12736. {
  12737. isSuccess = ConfigurationStatus_Rejected;
  12738. }
  12739. else
  12740. {
  12741. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12742. isSuccess = ConfigurationStatus_Accepted;
  12743. }
  12744. }
  12745. else
  12746. {
  12747. isSuccess = ConfigurationStatus_Rejected;
  12748. }
  12749. }
  12750. if(strcmp(key, "StopTxnSampledData") == 0)
  12751. {
  12752. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12753. {
  12754. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12755. isSuccess = ConfigurationStatus_Accepted;
  12756. }
  12757. else
  12758. {
  12759. isSuccess = ConfigurationStatus_Rejected;
  12760. }
  12761. }
  12762. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12763. {
  12764. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12765. {
  12766. check_ascii = value[0];
  12767. if( (check_ascii < 48) || (check_ascii > 57) )
  12768. {
  12769. isSuccess = ConfigurationStatus_Rejected;
  12770. }
  12771. else
  12772. {
  12773. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12774. isSuccess = ConfigurationStatus_Accepted;
  12775. }
  12776. }
  12777. else
  12778. {
  12779. isSuccess = ConfigurationStatus_Rejected;
  12780. }
  12781. }
  12782. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12783. {
  12784. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12785. {
  12786. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12787. isSuccess = ConfigurationStatus_Accepted;
  12788. }
  12789. else
  12790. {
  12791. isSuccess = ConfigurationStatus_Rejected;
  12792. }
  12793. }
  12794. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12795. {
  12796. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12797. {
  12798. check_ascii = value[0];
  12799. if( (check_ascii < 48) || (check_ascii > 57) )
  12800. {
  12801. isSuccess = ConfigurationStatus_Rejected;
  12802. }
  12803. else
  12804. {
  12805. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12806. isSuccess = ConfigurationStatus_Accepted;
  12807. }
  12808. }
  12809. else
  12810. {
  12811. isSuccess = ConfigurationStatus_Rejected;
  12812. }
  12813. }
  12814. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12815. {
  12816. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12817. {
  12818. check_ascii = value[0];
  12819. if( (check_ascii < 48) || (check_ascii > 57) )
  12820. {
  12821. isSuccess = ConfigurationStatus_Rejected;
  12822. }
  12823. else
  12824. {
  12825. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12826. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12827. TransactionMessageAttemptsValue = atoi(value);
  12828. isSuccess = ConfigurationStatus_Accepted;
  12829. }
  12830. }
  12831. else
  12832. {
  12833. isSuccess = ConfigurationStatus_Rejected;
  12834. }
  12835. }
  12836. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12837. {
  12838. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12839. {
  12840. check_ascii = value[0];
  12841. if( (check_ascii < 48) || (check_ascii > 57) )
  12842. {
  12843. isSuccess = ConfigurationStatus_Rejected;
  12844. }
  12845. else
  12846. {
  12847. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12848. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12849. TransactionMessageRetryIntervalValue = atoi(value);
  12850. isSuccess = ConfigurationStatus_Accepted;
  12851. }
  12852. }
  12853. else
  12854. {
  12855. isSuccess = ConfigurationStatus_Rejected;
  12856. }
  12857. }
  12858. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12859. {
  12860. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12861. {
  12862. strcpy(str, (const char*)value);
  12863. for(int i = 0; str[i]; i++)
  12864. {
  12865. str[i] = tolower(str[i]);
  12866. }
  12867. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12868. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12869. isSuccess = ConfigurationStatus_Accepted;
  12870. }
  12871. else
  12872. {
  12873. isSuccess = ConfigurationStatus_Rejected;
  12874. }
  12875. }
  12876. if(strcmp(key, "WebSocketPingInterval") == 0)
  12877. {
  12878. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12879. {
  12880. check_ascii = value[0];
  12881. if( (check_ascii < 48) || (check_ascii > 57) )
  12882. {
  12883. isSuccess = ConfigurationStatus_Rejected;
  12884. }
  12885. else
  12886. {
  12887. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12888. isSuccess = ConfigurationStatus_Accepted;
  12889. }
  12890. }
  12891. else
  12892. {
  12893. isSuccess = ConfigurationStatus_Rejected;
  12894. }
  12895. }
  12896. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  12897. {
  12898. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12899. {
  12900. strcpy(str, (const char*)value);
  12901. for(int i = 0; str[i]; i++)
  12902. {
  12903. str[i] = tolower(str[i]);
  12904. }
  12905. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12906. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12907. isSuccess = ConfigurationStatus_Accepted;
  12908. }
  12909. else
  12910. {
  12911. isSuccess = ConfigurationStatus_Rejected;
  12912. }
  12913. }
  12914. if(strcmp(key, "AuthorizationKey") == 0)
  12915. {
  12916. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  12917. {
  12918. strcpy(str, (const char*)value);
  12919. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  12920. isSuccess = ConfigurationStatus_Accepted;
  12921. }
  12922. else
  12923. {
  12924. isSuccess = ConfigurationStatus_Rejected;
  12925. }
  12926. }
  12927. if(strcmp(key, "SecurityProfile") == 0)
  12928. {
  12929. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  12930. {
  12931. check_ascii = value[0];
  12932. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  12933. {
  12934. isSuccess = ConfigurationStatus_Rejected;
  12935. }
  12936. else if(check_ascii == 0x33)
  12937. {
  12938. isSuccess = NotSupported;
  12939. }
  12940. else
  12941. {
  12942. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  12943. {
  12944. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  12945. isSuccess = ConfigurationStatus_Accepted;
  12946. }
  12947. else
  12948. isSuccess = ConfigurationStatus_Rejected;
  12949. }
  12950. }
  12951. else
  12952. {
  12953. isSuccess = ConfigurationStatus_Rejected;
  12954. }
  12955. }
  12956. if(strcmp(key, "DefaultPrice") == 0)
  12957. {
  12958. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  12959. {
  12960. strcpy(str, (const char*)value);
  12961. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  12962. isSuccess = ConfigurationStatus_Accepted;
  12963. }
  12964. else
  12965. {
  12966. isSuccess = ConfigurationStatus_Rejected;
  12967. }
  12968. }
  12969. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  12970. {
  12971. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  12972. {
  12973. strcpy(str, (const char*)value);
  12974. for(int i = 0; str[i]; i++)
  12975. {
  12976. str[i] = tolower(str[i]);
  12977. }
  12978. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12979. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12980. isSuccess = ConfigurationStatus_Accepted;
  12981. }
  12982. else
  12983. {
  12984. isSuccess = ConfigurationStatus_Rejected;
  12985. }
  12986. }
  12987. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  12988. {
  12989. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  12990. {
  12991. strcpy(str, (const char*)value);
  12992. for(int i = 0; str[i]; i++)
  12993. {
  12994. str[i] = tolower(str[i]);
  12995. }
  12996. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12997. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12998. isSuccess = ConfigurationStatus_Accepted;
  12999. }
  13000. else
  13001. {
  13002. isSuccess = ConfigurationStatus_Rejected;
  13003. }
  13004. }
  13005. #if 0
  13006. //For OCPP Test Case
  13007. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  13008. {
  13009. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13010. {
  13011. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  13012. isSuccess = ConfigurationStatus_Accepted;
  13013. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13014. }
  13015. else
  13016. {
  13017. isSuccess = ConfigurationStatus_Rejected;
  13018. }
  13019. }
  13020. #endif
  13021. #if 1
  13022. if(strcmp(key, "LocalAuthListEnabled") == 0)
  13023. {
  13024. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13025. {
  13026. strcpy(str, (const char*)value);
  13027. for(int i = 0; str[i]; i++)
  13028. {
  13029. str[i] = tolower(str[i]);
  13030. }
  13031. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13032. isSuccess = ConfigurationStatus_Accepted;
  13033. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13034. }
  13035. else
  13036. {
  13037. isSuccess = ConfigurationStatus_Rejected;
  13038. }
  13039. }
  13040. #endif
  13041. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  13042. {
  13043. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  13044. {
  13045. check_ascii = value[0];
  13046. if( (check_ascii < 48) || (check_ascii > 57) )
  13047. {
  13048. isSuccess = ConfigurationStatus_Rejected;
  13049. }
  13050. else
  13051. {
  13052. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  13053. isSuccess = ConfigurationStatus_Accepted;
  13054. }
  13055. }
  13056. else
  13057. {
  13058. isSuccess = ConfigurationStatus_Rejected;
  13059. }
  13060. }
  13061. if(strcmp(key, "SendLocalListMaxLength") == 0)
  13062. {
  13063. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  13064. {
  13065. check_ascii = value[0];
  13066. if( (check_ascii < 48) || (check_ascii > 57) )
  13067. {
  13068. isSuccess = ConfigurationStatus_Rejected;
  13069. }
  13070. else
  13071. {
  13072. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  13073. isSuccess = ConfigurationStatus_Accepted;
  13074. }
  13075. }
  13076. else
  13077. {
  13078. isSuccess = ConfigurationStatus_Rejected;
  13079. }
  13080. }
  13081. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  13082. {
  13083. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  13084. {
  13085. strcpy(str, (const char*)value);
  13086. for(int i = 0; str[i]; i++)
  13087. {
  13088. str[i] = tolower(str[i]);
  13089. }
  13090. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13091. isSuccess = ConfigurationStatus_Accepted;
  13092. }
  13093. else
  13094. {
  13095. isSuccess = ConfigurationStatus_Rejected;
  13096. }
  13097. }
  13098. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  13099. {
  13100. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  13101. {
  13102. check_ascii = value[0];
  13103. if( (check_ascii < 48) || (check_ascii > 57) )
  13104. {
  13105. isSuccess = ConfigurationStatus_Rejected;
  13106. }
  13107. else
  13108. {
  13109. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  13110. isSuccess = ConfigurationStatus_Accepted;
  13111. }
  13112. }
  13113. else
  13114. {
  13115. isSuccess = ConfigurationStatus_Rejected;
  13116. }
  13117. }
  13118. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  13119. {
  13120. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  13121. {
  13122. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  13123. isSuccess = ConfigurationStatus_Accepted;
  13124. }
  13125. else
  13126. {
  13127. isSuccess = ConfigurationStatus_Rejected;
  13128. }
  13129. }
  13130. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  13131. {
  13132. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  13133. {
  13134. check_ascii = value[0];
  13135. if( (check_ascii < 48) || (check_ascii > 57) )
  13136. {
  13137. isSuccess = ConfigurationStatus_Rejected;
  13138. }
  13139. else
  13140. {
  13141. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  13142. isSuccess = ConfigurationStatus_Accepted;
  13143. }
  13144. }
  13145. else
  13146. {
  13147. isSuccess = ConfigurationStatus_Rejected;
  13148. }
  13149. }
  13150. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  13151. {
  13152. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  13153. {
  13154. strcpy(str, (const char*)value);
  13155. for(int i = 0; str[i]; i++)
  13156. {
  13157. str[i] = tolower(str[i]);
  13158. }
  13159. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13160. isSuccess = ConfigurationStatus_Accepted;
  13161. }
  13162. else
  13163. {
  13164. isSuccess = ConfigurationStatus_Rejected;
  13165. }
  13166. }
  13167. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  13168. {
  13169. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  13170. {
  13171. check_ascii = value[0];
  13172. if( (check_ascii < 48) || (check_ascii > 57) )
  13173. {
  13174. isSuccess = ConfigurationStatus_Rejected;
  13175. }
  13176. else
  13177. {
  13178. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  13179. isSuccess = ConfigurationStatus_Accepted;
  13180. }
  13181. }
  13182. else
  13183. {
  13184. isSuccess = ConfigurationStatus_Rejected;
  13185. }
  13186. }
  13187. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13188. return isSuccess;
  13189. }
  13190. int TransactionMessageAttemptsGet(void)
  13191. {
  13192. return TransactionMessageAttemptsValue;
  13193. }
  13194. int FirstHeartBeatResponse(void)
  13195. {
  13196. return FirstHeartBeat;
  13197. }
  13198. int TransactionMessageRetryIntervalGet(void)
  13199. {
  13200. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13201. }
  13202. int ReadHttpStatus(int sock)
  13203. {
  13204. //char c;
  13205. char buff[1024]="",*ptr=buff+1;
  13206. int bytes_received, status;
  13207. DEBUG_INFO("Begin Response ..\n");
  13208. while((bytes_received = recv(sock, ptr, 1, 0))){
  13209. if(bytes_received==-1){
  13210. perror("ReadHttpStatus");
  13211. exit(1);
  13212. }
  13213. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  13214. ptr++;
  13215. }
  13216. *ptr=0;
  13217. ptr=buff+1;
  13218. sscanf(ptr,"%*s %d ", &status);
  13219. DEBUG_INFO("%s\n",ptr);
  13220. DEBUG_INFO("status=%d\n",status);
  13221. DEBUG_INFO("End Response ..\n");
  13222. return (bytes_received>0)?status:0;
  13223. }
  13224. //the only filed that it parsed is 'Content-Length'
  13225. int ParseHeader(int sock)
  13226. {
  13227. //char c;
  13228. char buff[1024]="",*ptr=buff+4;
  13229. int bytes_received;
  13230. DEBUG_INFO("Begin HEADER ..\n");
  13231. while((bytes_received = recv(sock, ptr, 1, 0))){
  13232. if(bytes_received==-1){
  13233. perror("Parse Header");
  13234. exit(1);
  13235. }
  13236. if(
  13237. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  13238. (ptr[-1]=='\r') && (*ptr=='\n' )
  13239. ) break;
  13240. ptr++;
  13241. }
  13242. *ptr=0;
  13243. ptr=buff+4;
  13244. //printf("%s",ptr);
  13245. if(bytes_received){
  13246. ptr=strstr(ptr,"Content-Length:");
  13247. if(ptr){
  13248. sscanf(ptr,"%*s %d",&bytes_received);
  13249. }else
  13250. bytes_received=-1; //unknown size
  13251. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  13252. }
  13253. DEBUG_INFO("End HEADER ..\n");
  13254. return bytes_received ;
  13255. }
  13256. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  13257. {
  13258. int result = TRUE;
  13259. char rmFileCmd[100]={0};
  13260. char FilePath[100]={0};
  13261. char ftpbuf[200];
  13262. int systemresult;
  13263. //DEBUG_INFO("filename=%s\n",filename);
  13264. //DEBUG_INFO("url=%s\n",url);
  13265. sprintf(FilePath,"/mnt/%s",filename);
  13266. system("ping 8.8.8.8 &");
  13267. if((access(FilePath,F_OK))!=-1)
  13268. {
  13269. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13270. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13271. system(rmFileCmd);
  13272. }
  13273. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13274. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  13275. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13276. systemresult = system(ftpbuf);
  13277. //DEBUG_INFO("systemresult=%d\n",systemresult);
  13278. if(systemresult != 0)
  13279. {
  13280. DEBUG_INFO("http DownLoad error!\n");
  13281. result = FALSE;
  13282. }
  13283. system("pkill ping");
  13284. return result;
  13285. }
  13286. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  13287. {
  13288. int result = TRUE;
  13289. char rmFileCmd[100]={0};
  13290. char FilePath[100]={0};
  13291. char ftpbuf[200];
  13292. int systemresult;
  13293. //char temp[100];
  13294. sprintf(FilePath,"/mnt/%s",filename);
  13295. system("ping 8.8.8.8 &");
  13296. if((access(FilePath,F_OK))!=-1)
  13297. {
  13298. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13299. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13300. system(rmFileCmd);
  13301. }
  13302. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13303. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  13304. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  13305. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  13306. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13307. systemresult = system(ftpbuf);
  13308. //DEBUG_INFO("systemresult=%d\n",systemresult);
  13309. if(systemresult != 0)
  13310. {
  13311. printf("wget error!\n");
  13312. result = FALSE;
  13313. }
  13314. system("pkill ping");
  13315. return result;
  13316. }
  13317. int httpUploadFile(char *location, char *path, char *filename,char *url)
  13318. {
  13319. char rmFileCmd[100]={0};
  13320. char FilePath[100]={0};
  13321. char buf[512];
  13322. int systemresult = 0;
  13323. //DEBUG_INFO("filename=%s\n",filename);
  13324. //DEBUG_INFO("url=%s\n",url);
  13325. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  13326. if((access(FilePath,F_OK))!=-1)
  13327. {
  13328. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13329. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13330. system(rmFileCmd);
  13331. }
  13332. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  13333. if(fp == NULL)
  13334. {
  13335. DEBUG_INFO("log is NULL\n");
  13336. return FALSE;
  13337. }
  13338. else
  13339. {
  13340. fprintf(fp, "%s\n", url);
  13341. fprintf(fp, "%s\n", filename);
  13342. fclose(fp);
  13343. }
  13344. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  13345. if(phpFP == NULL)
  13346. {
  13347. DEBUG_INFO("PHP upload fail.\n");
  13348. return FALSE;
  13349. }
  13350. else
  13351. {
  13352. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  13353. {
  13354. if(strstr(buf, "result") != NULL)
  13355. {
  13356. sscanf(buf, "result: %d", &systemresult);
  13357. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  13358. }
  13359. }
  13360. pclose(phpFP);
  13361. }
  13362. if(systemresult != 1)
  13363. {
  13364. DEBUG_INFO("HTTP upload error!\n");
  13365. return FALSE;
  13366. }
  13367. return TRUE;
  13368. }
  13369. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  13370. {
  13371. struct hostent* server;
  13372. char *IPbuffer;
  13373. char ftpbuf[200];
  13374. int systemresult;
  13375. // To retrieve host information
  13376. server = gethostbyname(location);
  13377. // To convert an Internet network
  13378. // address into ASCII string
  13379. IPbuffer = inet_ntoa(*((struct in_addr*)
  13380. server->h_addr_list[0]));
  13381. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13382. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  13383. /* format : ftpput -u username -p passwd IP target source*/
  13384. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  13385. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  13386. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13387. systemresult = system(ftpbuf);
  13388. DEBUG_INFO("systemresult=%d\n",systemresult);
  13389. if(systemresult != 0)
  13390. {
  13391. DEBUG_INFO("ftpput error!\n");
  13392. return FALSE;
  13393. }
  13394. return TRUE;
  13395. }
  13396. int GetOcppServerURL()
  13397. {
  13398. int result = FALSE;
  13399. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  13400. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  13401. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  13402. struct yuarel url;
  13403. char urlStr[512];
  13404. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  13405. {
  13406. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  13407. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13408. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  13409. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  13410. if(yuarel_parse(&url, urlStr) != -1)
  13411. {
  13412. sprintf(OcppProtocol, "%s", url.scheme);
  13413. sprintf(OcppHost, "%s", url.host);
  13414. if(url.path == NULL)
  13415. OcppTempPath[0] = '\0';
  13416. else
  13417. {
  13418. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  13419. {
  13420. sprintf(OcppTempPath, "%s/", url.path);
  13421. }
  13422. else
  13423. {
  13424. sprintf(OcppTempPath, "%s", url.path);
  13425. }
  13426. }
  13427. if(url.port == 0)
  13428. {
  13429. if(strcmp(OcppProtocol, "wss") == 0)
  13430. OcppPort = 443;
  13431. else
  13432. OcppPort = 80;
  13433. }
  13434. else
  13435. OcppPort = url.port;
  13436. result = TRUE;
  13437. }
  13438. }
  13439. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  13440. {
  13441. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  13442. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13443. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  13444. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  13445. if(yuarel_parse(&url, urlStr) != -1)
  13446. {
  13447. sprintf(OcppProtocol, "%s", url.scheme);
  13448. sprintf(OcppHost, "%s", url.host);
  13449. if(url.path == NULL)
  13450. OcppTempPath[0] = '\0';
  13451. else
  13452. sprintf(OcppTempPath, "%s", url.path);
  13453. if(url.port == 0)
  13454. {
  13455. if(strcmp(OcppProtocol, "wss") == 0)
  13456. OcppPort = 443;
  13457. else
  13458. OcppPort = 80;
  13459. }
  13460. else
  13461. OcppPort = url.port;
  13462. result = TRUE;
  13463. }
  13464. }
  13465. else
  13466. {
  13467. strcpy(OcppHost,"");
  13468. }
  13469. return result;
  13470. }
  13471. int GetOcppPath()
  13472. {
  13473. int result = FALSE;
  13474. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  13475. {
  13476. if(OcppTempPath == NULL)
  13477. {
  13478. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13479. }
  13480. else
  13481. {
  13482. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13483. }
  13484. result = TRUE;
  13485. goto End;
  13486. }
  13487. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  13488. {
  13489. if(OcppTempPath == NULL)
  13490. {
  13491. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  13492. }
  13493. else
  13494. {
  13495. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  13496. }
  13497. result = TRUE;
  13498. goto End;
  13499. }
  13500. else
  13501. {
  13502. strcpy(OcppPath,"");
  13503. }
  13504. End:
  13505. return result;
  13506. }
  13507. int GetOcppPort()
  13508. {
  13509. return OcppPort;
  13510. }
  13511. int GetOcppConnStatus(void)
  13512. {
  13513. return ShmOCPP16Data->OcppConnStatus;
  13514. }
  13515. void SetOcppConnStatus(uint8_t status)
  13516. {
  13517. ShmOCPP16Data->OcppConnStatus = status;
  13518. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  13519. }
  13520. int GetHeartBeatWithNOResponse(void)
  13521. {
  13522. return HeartBeatWithNOResponse;
  13523. }
  13524. void SetHeartBeatWithNOResponse(void)
  13525. {
  13526. HeartBeatWithNOResponse = 0;
  13527. }
  13528. void GetStartTransactionIdTag(int gun_index)
  13529. {
  13530. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  13531. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13532. }
  13533. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  13534. {
  13535. char ch;
  13536. FILE *fptr1;
  13537. int temptransactionId;
  13538. char str[100]={0};
  13539. temptransactionId = 0;
  13540. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  13541. {
  13542. DEBUG_INFO("IdTag is empty.\n");
  13543. return temptransactionId;
  13544. }
  13545. /*------ Read the file ----------------*/
  13546. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  13547. if (!fptr1)
  13548. {
  13549. DEBUG_INFO("QueueTransactionId file open error.\n");
  13550. //printf(" File not found or unable to open the input file!!\n");
  13551. return temptransactionId;
  13552. }
  13553. ch=fgetc(fptr1);
  13554. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13555. rewind(fptr1);
  13556. if(ch!=EOF)
  13557. {
  13558. // printf("%c",ch);
  13559. while (fgets(str, 100, fptr1) != NULL)
  13560. {
  13561. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13562. if(str[0]=='\0')
  13563. {
  13564. break;
  13565. }
  13566. char *revbuf[8] = {0}; // Variable store string split
  13567. int num = 0;// Quantity after string split
  13568. DEBUG_INFO("Transaction queue data= %s\n", str);
  13569. splitstring(str,",",revbuf,&num); // String split
  13570. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  13571. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  13572. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  13573. DEBUG_INFO("------------------------------\n");
  13574. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13575. {
  13576. if(isStopTransaction)
  13577. {
  13578. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  13579. {
  13580. temptransactionId = atoi(revbuf[2]);
  13581. //break;
  13582. }
  13583. }
  13584. else
  13585. {
  13586. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13587. {
  13588. temptransactionId = atoi(revbuf[2]);
  13589. //break;
  13590. }
  13591. }
  13592. }
  13593. }
  13594. }
  13595. else
  13596. DEBUG_INFO("EOF\n");
  13597. fclose(fptr1);
  13598. /*------- End of reading ---------------*/
  13599. return temptransactionId;
  13600. }
  13601. void SetTransactionIdZero(int transactionId)
  13602. {
  13603. char ch;
  13604. FILE *fptr1, *fptr2;
  13605. int temptransactionId = 0;
  13606. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13607. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13608. if (!fptr1)
  13609. {
  13610. //printf(" File not found or unable to open the input file!!\n");
  13611. return ;
  13612. }
  13613. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13614. if (!fptr2)
  13615. {
  13616. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  13617. fclose(fptr1);
  13618. return ;
  13619. }
  13620. ch=fgetc(fptr1);
  13621. rewind(fptr1);
  13622. if(ch!=EOF)
  13623. {
  13624. // copy all contents to the temporary file except the specific line
  13625. while (fgets(str, 100, fptr1) != NULL)
  13626. {
  13627. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13628. if(str[0]=='\0')
  13629. {
  13630. break;
  13631. }
  13632. char *revbuf[8] = {0};
  13633. int num = 0;
  13634. strcpy(strtemp, str);
  13635. splitstring(str,",",revbuf,&num);
  13636. if(revbuf[2][0] != '\0')
  13637. {
  13638. temptransactionId = atoi(revbuf[2]);
  13639. if(transactionId != temptransactionId)
  13640. {
  13641. fprintf(fptr2, "%s\n", strtemp);
  13642. }
  13643. }
  13644. }
  13645. }
  13646. fclose(fptr1);
  13647. fclose(fptr2);
  13648. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13649. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13650. /*------ Read the file ----------------*/
  13651. }
  13652. int InternetDisconnect(void)
  13653. {
  13654. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13655. }
  13656. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  13657. void storeTempStopTransaction(int gun_index)
  13658. {
  13659. char guid[37]={0};
  13660. int tempIndex = 0;
  13661. char TempStopTransaction[256];
  13662. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  13663. DEBUG_INFO("storeTempStopTransaction...\n");
  13664. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  13665. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  13666. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  13667. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13668. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  13669. {
  13670. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13671. {
  13672. tempIndex = ((gun_index==2) ? 1: 0);
  13673. }
  13674. else
  13675. {
  13676. tempIndex = gun_index;
  13677. }
  13678. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13679. {
  13680. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13681. {
  13682. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  13683. }
  13684. }// END OF CHAdeMO_QUANTITY
  13685. }
  13686. else if(gunType[gun_index] == GUN_TYPE_CCS)
  13687. {
  13688. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13689. {
  13690. tempIndex = ((gun_index==2) ? 1: 0);
  13691. }
  13692. else
  13693. {
  13694. tempIndex = gun_index;
  13695. }
  13696. for (int index = 0; index < CCS_QUANTITY; index++)
  13697. {
  13698. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13699. {
  13700. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  13701. }
  13702. }// END OF CCS_QUANTITY
  13703. }
  13704. else if(gunType[gun_index] == GUN_TYPE_GBT)
  13705. {
  13706. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13707. {
  13708. tempIndex = ((gun_index==2) ? 1: 0);
  13709. }
  13710. else
  13711. {
  13712. tempIndex = gun_index;
  13713. }
  13714. for (int index = 0; index < GB_QUANTITY; index++)
  13715. {
  13716. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13717. {
  13718. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  13719. }
  13720. }// END OF GB_QUANTITY
  13721. }
  13722. else if(gunType[gun_index] == GUN_TYPE_DO)
  13723. {
  13724. tempIndex = gun_index;
  13725. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13726. {
  13727. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13728. {
  13729. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  13730. }
  13731. }
  13732. }
  13733. else
  13734. {
  13735. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13736. {
  13737. tempIndex = 2;
  13738. }
  13739. else
  13740. {
  13741. tempIndex = gun_index;
  13742. }
  13743. for (int index = 0; index < AC_QUANTITY; index++)
  13744. {
  13745. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13746. {
  13747. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  13748. }
  13749. }// END OF AC_QUANTITY
  13750. }
  13751. //Stop Transaction Time
  13752. struct timeval tmnow;
  13753. struct tm *tm;
  13754. char buf[28];//, usec_buf[6];
  13755. gettimeofday(&tmnow, NULL);
  13756. time_t t;
  13757. t = time(NULL);
  13758. /*UTC time and date*/
  13759. tm = gmtime(&t);
  13760. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  13761. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  13762. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  13763. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13764. random_uuid(guid);
  13765. /***********************************transactionData******************************************************/
  13766. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  13767. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  13768. //=================================
  13769. //1. Transaction_Begin
  13770. //=================================
  13771. //============================== Energy.Active.Import.Interval ===========================================
  13772. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  13773. {
  13774. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  13775. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  13776. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  13777. 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*/]);
  13778. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13779. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  13780. {
  13781. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  13782. }
  13783. else
  13784. {
  13785. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  13786. }
  13787. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  13788. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13789. }
  13790. //=================================
  13791. //2. Transaction_End
  13792. //=================================
  13793. //2.1====================================== Current.Import L1 ==============================================
  13794. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  13795. {
  13796. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  13797. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  13798. {
  13799. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13800. {
  13801. tempIndex = ((gun_index==2) ? 1: 0);
  13802. }
  13803. else
  13804. {
  13805. tempIndex = gun_index;
  13806. }
  13807. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13808. {
  13809. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13810. {
  13811. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13812. }
  13813. }// End of for CHAdeMO_QUANTITY
  13814. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13815. }
  13816. else if(gunType[gun_index] == GUN_TYPE_CCS)
  13817. {
  13818. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13819. {
  13820. tempIndex = ((gun_index==2) ? 1: 0);
  13821. }
  13822. else
  13823. {
  13824. tempIndex = gun_index;
  13825. }
  13826. for (int index = 0; index < CCS_QUANTITY; index++)
  13827. {
  13828. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13829. {
  13830. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13831. }
  13832. }// End of for CCS_QUANTITY
  13833. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13834. }
  13835. else if(gunType[gun_index] == GUN_TYPE_GBT)
  13836. {
  13837. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13838. {
  13839. tempIndex = ((gun_index==2) ? 1: 0);
  13840. }
  13841. else
  13842. {
  13843. tempIndex = gun_index;
  13844. }
  13845. for (int index = 0; index < GB_QUANTITY; index++)
  13846. {
  13847. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13848. {
  13849. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13850. }
  13851. }// End of for GB_QUANTITY
  13852. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13853. }
  13854. else if(gunType[gun_index] == GUN_TYPE_DO)
  13855. {
  13856. tempIndex = gun_index;
  13857. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13858. {
  13859. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13860. {
  13861. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13862. }
  13863. }
  13864. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13865. }
  13866. else
  13867. {
  13868. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13869. {
  13870. tempIndex = 2;
  13871. }
  13872. else
  13873. {
  13874. tempIndex = gun_index;
  13875. }
  13876. for (int index = 0; index < AC_QUANTITY; index++)
  13877. {
  13878. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13879. {
  13880. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  13881. }
  13882. }// End of for AC_QUANTITY
  13883. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13884. }
  13885. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13886. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  13887. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  13888. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13889. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  13890. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13891. }
  13892. //2.2===================================== Energy.Active.Import.Interval ==========================================
  13893. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  13894. {
  13895. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13896. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  13897. {
  13898. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13899. {
  13900. tempIndex = ((gun_index==2) ? 1: 0);
  13901. }
  13902. else
  13903. {
  13904. tempIndex = gun_index;
  13905. }
  13906. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13907. {
  13908. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13909. {
  13910. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13911. }
  13912. }// END OF CHAdeMO_QUANTITY
  13913. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13914. }
  13915. else if(gunType[gun_index] == GUN_TYPE_CCS)
  13916. {
  13917. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13918. {
  13919. tempIndex = ((gun_index==2) ? 1: 0);
  13920. }
  13921. else
  13922. {
  13923. tempIndex = gun_index;
  13924. }
  13925. for (int index = 0; index < CCS_QUANTITY; index++)
  13926. {
  13927. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13928. {
  13929. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13930. }
  13931. }// END OF CCS_QUANTITY
  13932. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13933. }
  13934. else if(gunType[gun_index] == GUN_TYPE_GBT)
  13935. {
  13936. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13937. {
  13938. tempIndex = ((gun_index==2) ? 1: 0);
  13939. }
  13940. else
  13941. {
  13942. tempIndex = gun_index;
  13943. }
  13944. for (int index = 0; index < GB_QUANTITY; index++)
  13945. {
  13946. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13947. {
  13948. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13949. }
  13950. }// END OF GB_QUANTITY
  13951. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13952. }
  13953. else if(gunType[gun_index] == GUN_TYPE_DO)
  13954. {
  13955. tempIndex = gun_index;
  13956. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13957. {
  13958. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13959. {
  13960. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13961. }
  13962. }
  13963. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13964. }
  13965. else
  13966. {
  13967. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13968. {
  13969. tempIndex = 2;
  13970. }
  13971. else
  13972. {
  13973. tempIndex = gun_index;
  13974. }
  13975. for (int index = 0; index < AC_QUANTITY; index++)
  13976. {
  13977. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13978. {
  13979. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13980. }
  13981. }// END OF AC_QUANTITY
  13982. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13983. }
  13984. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13985. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  13986. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  13987. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13988. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  13989. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13990. }
  13991. //2.3====================================== Power.Active.Import =========================================
  13992. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  13993. {
  13994. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13995. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  13996. {
  13997. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13998. {
  13999. tempIndex = ((gun_index==2) ? 1: 0);
  14000. }
  14001. else
  14002. {
  14003. tempIndex = gun_index;
  14004. }
  14005. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14006. {
  14007. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14008. {
  14009. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14010. }
  14011. } // End for CHAdeMO_QUANTITY
  14012. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14013. }
  14014. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14015. {
  14016. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14017. {
  14018. tempIndex = ((gun_index==2) ? 1: 0);
  14019. }
  14020. else
  14021. {
  14022. tempIndex = gun_index;
  14023. }
  14024. for (int index = 0; index < CCS_QUANTITY; index++)
  14025. {
  14026. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14027. {
  14028. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14029. }
  14030. } // END for CCS_QUANTITY
  14031. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14032. }
  14033. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14034. {
  14035. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14036. {
  14037. tempIndex = ((gun_index==2) ? 1: 0);
  14038. }
  14039. else
  14040. {
  14041. tempIndex = gun_index;
  14042. }
  14043. for (int index = 0; index < GB_QUANTITY; index++)
  14044. {
  14045. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14046. {
  14047. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14048. }
  14049. }// END for GB_QUANTITY
  14050. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14051. }
  14052. else if(gunType[gun_index] == GUN_TYPE_DO)
  14053. {
  14054. tempIndex = gun_index;
  14055. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14056. {
  14057. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14058. {
  14059. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14060. }
  14061. }
  14062. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14063. }
  14064. else
  14065. {
  14066. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14067. {
  14068. tempIndex = 2;
  14069. }
  14070. else
  14071. {
  14072. tempIndex = gun_index;
  14073. }
  14074. for (int index = 0; index < AC_QUANTITY; index++)
  14075. {
  14076. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14077. {
  14078. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14079. }
  14080. } // END for AC_QUANTITY
  14081. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14082. }
  14083. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14084. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  14085. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  14086. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14087. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  14088. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  14089. }
  14090. //2.4====================================== Voltage L1 ====================================================
  14091. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  14092. {
  14093. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14094. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14095. {
  14096. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14097. {
  14098. tempIndex = ((gun_index==2) ? 1: 0);
  14099. }
  14100. else
  14101. {
  14102. tempIndex = gun_index;
  14103. }
  14104. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14105. {
  14106. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14107. {
  14108. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14109. }
  14110. } // END OF FOR CHAdeMO_QUANTITY
  14111. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14112. }
  14113. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14114. {
  14115. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14116. {
  14117. tempIndex = ((gun_index==2) ? 1: 0);
  14118. }
  14119. else
  14120. {
  14121. tempIndex = gun_index;
  14122. }
  14123. for (int index = 0; index < CCS_QUANTITY; index++)
  14124. {
  14125. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14126. {
  14127. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14128. }
  14129. } // END OF FOR CCS_QUANTITY
  14130. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14131. }
  14132. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14133. {
  14134. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14135. {
  14136. tempIndex = ((gun_index==2) ? 1: 0);
  14137. }
  14138. else
  14139. {
  14140. tempIndex = gun_index;
  14141. }
  14142. for (int index = 0; index < GB_QUANTITY; index++)
  14143. {
  14144. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14145. {
  14146. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14147. }
  14148. } // END OF FOR GB_QUANTITY
  14149. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14150. }
  14151. else if(gunType[gun_index] == GUN_TYPE_DO)
  14152. {
  14153. tempIndex = gun_index;
  14154. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14155. {
  14156. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14157. {
  14158. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14159. }
  14160. }
  14161. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14162. }
  14163. else
  14164. {
  14165. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14166. {
  14167. tempIndex = 2;
  14168. }
  14169. else
  14170. {
  14171. tempIndex = gun_index;
  14172. }
  14173. for (int index = 0; index < AC_QUANTITY; index++)
  14174. {
  14175. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14176. {
  14177. 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
  14178. }
  14179. } // END OF FOR AC_QUANTITY
  14180. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  14181. }
  14182. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14183. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  14184. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  14185. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  14186. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  14187. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14188. }
  14189. //2.5============================================== End SoC =========================================================
  14190. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  14191. {
  14192. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14193. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  14194. {
  14195. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  14196. {
  14197. tempIndex = ((gun_index==2) ? 1: 0);
  14198. }
  14199. else
  14200. {
  14201. tempIndex = gun_index;
  14202. }
  14203. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14204. {
  14205. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14206. {
  14207. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14208. {
  14209. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  14210. }
  14211. }
  14212. }
  14213. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14214. {
  14215. for (int index = 0; index < CCS_QUANTITY; index++)
  14216. {
  14217. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14218. {
  14219. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  14220. }
  14221. }
  14222. }
  14223. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14224. {
  14225. for (int index = 0; index < GB_QUANTITY; index++)
  14226. {
  14227. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14228. {
  14229. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  14230. }
  14231. }
  14232. }
  14233. else if(gunType[gun_index] == GUN_TYPE_DO)
  14234. {
  14235. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14236. {
  14237. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14238. {
  14239. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  14240. }
  14241. }
  14242. }
  14243. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14244. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  14245. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  14246. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  14247. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  14248. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  14249. } // END FOR DC CASE
  14250. }
  14251. //2.6====================================== Current.Import L2 ==============================================
  14252. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  14253. {
  14254. // AC 3 phase L2 current
  14255. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14256. {
  14257. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14258. {
  14259. tempIndex = 2;
  14260. }
  14261. else
  14262. {
  14263. tempIndex = gun_index;
  14264. }
  14265. for (int index = 0; index < AC_QUANTITY; index++)
  14266. {
  14267. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14268. {
  14269. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  14270. }
  14271. }// End of for AC_QUANTITY
  14272. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  14273. }
  14274. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14275. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  14276. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  14277. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  14278. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14279. }
  14280. //2.7====================================== Current.Import L3 ==============================================
  14281. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  14282. {
  14283. // AC 3 phase L3 current
  14284. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14285. {
  14286. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14287. {
  14288. tempIndex = 2;
  14289. }
  14290. else
  14291. {
  14292. tempIndex = gun_index;
  14293. }
  14294. for (int index = 0; index < AC_QUANTITY; index++)
  14295. {
  14296. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14297. {
  14298. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  14299. }
  14300. }// End of for AC_QUANTITY
  14301. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  14302. }
  14303. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14304. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  14305. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  14306. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  14307. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14308. }
  14309. //2.9====================================== Voltage L2 ====================================================
  14310. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  14311. {
  14312. // AC 3 phase L2 volatge
  14313. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14314. {
  14315. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14316. {
  14317. tempIndex = 2;
  14318. }
  14319. else
  14320. {
  14321. tempIndex = gun_index;
  14322. }
  14323. for (int index = 0; index < AC_QUANTITY; index++)
  14324. {
  14325. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14326. {
  14327. 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
  14328. }
  14329. } // END OF FOR AC_QUANTITY
  14330. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  14331. }
  14332. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14333. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  14334. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  14335. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  14336. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14337. }
  14338. //2.10====================================== Voltage L3 ====================================================
  14339. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  14340. {
  14341. // AC 3 phase L3 volatge
  14342. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  14343. {
  14344. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14345. {
  14346. tempIndex = 2;
  14347. }
  14348. else
  14349. {
  14350. tempIndex = gun_index;
  14351. }
  14352. for (int index = 0; index < AC_QUANTITY; index++)
  14353. {
  14354. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14355. {
  14356. 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
  14357. }
  14358. } // END OF FOR AC_QUANTITY
  14359. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  14360. }
  14361. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14362. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  14363. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  14364. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  14365. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14366. }
  14367. //====================== Start SoC ================================
  14368. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  14369. {
  14370. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14371. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  14372. {
  14373. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  14374. {
  14375. tempIndex = ((gun_index==2) ? 1: 0);
  14376. }
  14377. else
  14378. {
  14379. tempIndex = gun_index;
  14380. }
  14381. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14382. {
  14383. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14384. {
  14385. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14386. {
  14387. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  14388. }
  14389. }
  14390. }
  14391. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14392. {
  14393. for (int index = 0; index < CCS_QUANTITY; index++)
  14394. {
  14395. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14396. {
  14397. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  14398. }
  14399. }
  14400. }
  14401. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14402. {
  14403. for (int index = 0; index < GB_QUANTITY; index++)
  14404. {
  14405. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14406. {
  14407. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  14408. }
  14409. }
  14410. }
  14411. else if(gunType[gun_index] == GUN_TYPE_DO)
  14412. {
  14413. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14414. {
  14415. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14416. {
  14417. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  14418. }
  14419. }
  14420. }
  14421. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  14422. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  14423. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  14424. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  14425. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  14426. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  14427. } // END FOR DC CASE
  14428. }
  14429. //======================================== Message create ==============================================
  14430. json_object *StopTransaction = json_object_new_object();
  14431. json_object *transactionDatas = json_object_new_array();
  14432. json_object *sampledValues = json_object_new_array();
  14433. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  14434. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  14435. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  14436. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  14437. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  14438. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  14439. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  14440. {
  14441. json_object *transactionData = json_object_new_object();
  14442. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  14443. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  14444. {
  14445. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  14446. {
  14447. json_object *sampledValue = json_object_new_object();
  14448. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  14449. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  14450. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  14451. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  14452. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  14453. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  14454. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  14455. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  14456. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  14457. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  14458. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  14459. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  14460. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  14461. json_object_array_add(sampledValues, sampledValue);
  14462. }
  14463. }
  14464. json_object_object_add(transactionData, "sampledValue", sampledValues);
  14465. json_object_array_add(transactionDatas, transactionData);
  14466. }
  14467. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  14468. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  14469. ,MESSAGE_TYPE_CALL
  14470. ,guid
  14471. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  14472. json_object_put(StopTransaction);
  14473. // Check File "TempStopTransaction" Exist
  14474. if((access(TempStopTransaction,F_OK))!=-1)
  14475. {
  14476. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  14477. fclose(fopen(TempStopTransaction, "w"));
  14478. }
  14479. else
  14480. {
  14481. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  14482. FILE *log = fopen(TempStopTransaction, "w+");
  14483. if(log == NULL)
  14484. {
  14485. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  14486. return ;
  14487. }
  14488. else
  14489. {
  14490. fclose(log);
  14491. }
  14492. }
  14493. //Add TempStopTransaction | Update TempStopTransaction
  14494. // open file for writing
  14495. FILE *outfile;
  14496. outfile = fopen (TempStopTransaction, "a");
  14497. //DEBUG_INFO("data = %s\n", queuedata);
  14498. fputs(queuedata, outfile);
  14499. fputs("\n", outfile);
  14500. fclose (outfile);
  14501. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14502. }
  14503. void checkTempStopTransaction(int gun_index)
  14504. {
  14505. FILE *fptr1;
  14506. char ch;
  14507. char str[QUEUE_MESSAGE_LENGTH]={0};
  14508. char guid[37]={0};
  14509. char tempdata[65]={0};
  14510. char connectorStr[2]={0};
  14511. char TempStopTransaction[256];
  14512. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  14513. fptr1 = fopen(TempStopTransaction, "r");
  14514. //TempStopTransaction格式: 槍號,StopTransaction封包
  14515. if (!fptr1)
  14516. {
  14517. //printf(" File not found or unable to open the input file!!\n");
  14518. return ;
  14519. }
  14520. ch=fgetc(fptr1);
  14521. //printf(" Now the content of the file %s is : \n",fname);
  14522. rewind(fptr1);
  14523. if(ch!=EOF)
  14524. {
  14525. // copy all contents to the temporary file except the specific line
  14526. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  14527. {
  14528. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14529. if(str[0]=='\0')
  14530. {
  14531. break;
  14532. }
  14533. //TempStopTransaction格式: 槍號,StopTransaction封包
  14534. strncpy(connectorStr, str, 1);
  14535. if(atoi(connectorStr) != (gun_index+1))
  14536. {
  14537. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  14538. fclose(fptr1);
  14539. return ;
  14540. }
  14541. //random_uuid(guid);
  14542. strncpy(guid, str+6, 36); //copy guid
  14543. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  14544. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  14545. {
  14546. //DEBUG_INFO("StopTransaction mapitem pass\n");
  14547. }
  14548. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  14549. OCPP_insert_transaction_msg(NO, str);
  14550. memset(str,0,ARRAY_SIZE(str));
  14551. }
  14552. }
  14553. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  14554. fclose(fptr1);
  14555. remove(TempStopTransaction); // remove the original file
  14556. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14557. }
  14558. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  14559. {
  14560. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  14561. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  14562. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  14563. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  14564. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14565. }
  14566. int GetWebSocketPingInterval(void)
  14567. {
  14568. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14569. }
  14570. int GetServerSign(void)
  14571. {
  14572. return server_sign;
  14573. }
  14574. uint8_t GetOcppSecurityProfile()
  14575. {
  14576. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14577. }
  14578. void GetOcppChargerBoxId(uint8_t *data)
  14579. {
  14580. sprintf((char*)data, "%s", ShmOCPP16Data->ChargeBoxId);
  14581. }
  14582. void GetOcppSecurityPassword(uint8_t *data)
  14583. {
  14584. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14585. }
  14586. void SetOcppVersion(uint8_t *version)
  14587. {
  14588. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  14589. DEBUG_INFO("ocpp version: %s\n", version);
  14590. if(strstr((char*)version, "ocpp1.6") != NULL)
  14591. {
  14592. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  14593. }
  14594. else if(strstr((char*)version, "ocpp2.0") != NULL)
  14595. {
  14596. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  14597. system("pkill OcppBackend");
  14598. }
  14599. }
  14600. void SetServerSign(int value)
  14601. {
  14602. server_sign = value;
  14603. }
  14604. int GetBootNotificationInterval(void)
  14605. {
  14606. return BootNotificationInterval;
  14607. }
  14608. int GetInternetConn(void)
  14609. {
  14610. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  14611. }
  14612. int isConnectorInitMode(int gun_index)
  14613. {
  14614. int tempIndex = 0;
  14615. int result = TRUE;
  14616. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14617. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14618. {
  14619. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14620. {
  14621. tempIndex = ((gun_index==2) ? 1: 0);
  14622. }
  14623. else
  14624. {
  14625. tempIndex = gun_index;
  14626. }
  14627. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14628. {
  14629. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  14630. {
  14631. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  14632. } //end of the same index
  14633. }//end of for CHAdeMO_QUANTITY
  14634. }
  14635. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14636. {
  14637. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14638. {
  14639. tempIndex = ((gun_index==2) ? 1: 0);
  14640. }
  14641. else
  14642. {
  14643. tempIndex = gun_index;
  14644. }
  14645. for (int index = 0; index < CCS_QUANTITY; index++)
  14646. {
  14647. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14648. {
  14649. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  14650. } //end of the same index
  14651. } // end of for CCS_QUANTITY
  14652. }
  14653. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14654. {
  14655. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14656. {
  14657. tempIndex = ((gun_index==2) ? 1: 0);
  14658. }
  14659. else
  14660. {
  14661. tempIndex = gun_index;
  14662. }
  14663. for (int index = 0; index < GB_QUANTITY; index++)
  14664. {
  14665. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14666. {
  14667. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  14668. } //end of the same index
  14669. } // end of for GB_QUANTITY
  14670. }
  14671. else if(gunType[gun_index] == GUN_TYPE_DO)
  14672. {
  14673. tempIndex = gun_index;
  14674. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14675. {
  14676. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14677. {
  14678. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  14679. } //end of the same index
  14680. }
  14681. }
  14682. else
  14683. {
  14684. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14685. {
  14686. tempIndex = 2;
  14687. }
  14688. else
  14689. {
  14690. tempIndex = gun_index;
  14691. }
  14692. for (int index = 0; index < AC_QUANTITY; index++)
  14693. {
  14694. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14695. {
  14696. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  14697. }//end of the same index
  14698. }//end of for AC_QUANTITY
  14699. }
  14700. return result;
  14701. }
  14702. void refreshProcDogTimer()
  14703. {
  14704. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  14705. }
  14706. void InitialSystemValue(void)
  14707. {
  14708. int connectorIndex = 0;
  14709. //int valueASCII = 0;
  14710. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14711. gunTotalNumber=0;
  14712. SystemInitial = 0;
  14713. localversion=0;
  14714. BootNotificationInterval = 0;
  14715. authorizeRetryTimes = 0;
  14716. GunStatusInterval = 10;
  14717. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14718. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14719. //Hear Beat
  14720. HeartBeatWithNOResponse = 0;
  14721. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  14722. FirstHeartBeat = 0;
  14723. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  14724. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  14725. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  14726. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  14727. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  14728. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  14729. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  14730. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  14731. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  14732. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  14733. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  14734. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  14735. memset(gunType, 0, ARRAY_SIZE(gunType));
  14736. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14737. {
  14738. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O')
  14739. {
  14740. // DO series
  14741. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  14742. {
  14743. SystemInitial = SystemInitial + 1;
  14744. gunTotalNumber = gunTotalNumber + 1;
  14745. gunType[connectorIndex] = GUN_TYPE_DO;
  14746. connectorIndex = connectorIndex + 1;
  14747. }
  14748. }
  14749. else
  14750. {
  14751. // DM, DW, DS series
  14752. //check connector / socket type (index: 8, 9, 10)
  14753. for(int index=7; index <10 ; index++)
  14754. {
  14755. if(index != 8)
  14756. {
  14757. // DC Connector
  14758. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  14759. {
  14760. SystemInitial = SystemInitial + 1;
  14761. gunTotalNumber = gunTotalNumber + 1;
  14762. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  14763. connectorIndex = connectorIndex + 1;
  14764. }
  14765. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  14766. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  14767. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  14768. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  14769. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  14770. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  14771. {
  14772. SystemInitial = SystemInitial + 1;
  14773. gunTotalNumber = gunTotalNumber + 1;
  14774. gunType[connectorIndex] = GUN_TYPE_CCS;
  14775. connectorIndex = connectorIndex + 1;
  14776. }
  14777. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  14778. {
  14779. SystemInitial = SystemInitial + 1;
  14780. gunTotalNumber = gunTotalNumber + 1;
  14781. gunType[connectorIndex] = GUN_TYPE_GBT;
  14782. connectorIndex = connectorIndex + 1;
  14783. }
  14784. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  14785. {
  14786. SystemInitial = SystemInitial + 1;
  14787. gunTotalNumber = gunTotalNumber + 1;
  14788. gunType[connectorIndex] = GUN_TYPE_DO;
  14789. connectorIndex = connectorIndex + 1;
  14790. }
  14791. }
  14792. else
  14793. {
  14794. // AC Connector
  14795. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14796. {
  14797. SystemInitial = SystemInitial + 1;
  14798. gunTotalNumber = gunTotalNumber + 1;
  14799. gunType[connectorIndex] = GUN_TYPE_AC;
  14800. connectorIndex = connectorIndex + 1;
  14801. }
  14802. }
  14803. }
  14804. }
  14805. //DEBUG_INFO("DC ...\n");
  14806. }
  14807. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  14808. {
  14809. //check connector / socket type (index: 8, 9, 10)
  14810. for(int index=7; index <10 ; index++)
  14811. {
  14812. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14813. {
  14814. SystemInitial = SystemInitial + 1;
  14815. gunTotalNumber = gunTotalNumber + 1;
  14816. gunType[connectorIndex] = GUN_TYPE_AC;
  14817. connectorIndex = connectorIndex + 1;
  14818. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  14819. }
  14820. }
  14821. }
  14822. //Status && ConnectorPlugIn Setting
  14823. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14824. {
  14825. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  14826. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  14827. }
  14828. for (int index = 0; index < CCS_QUANTITY; index++)
  14829. {
  14830. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  14831. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  14832. }
  14833. for (int index = 0; index < GB_QUANTITY; index++)
  14834. {
  14835. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  14836. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  14837. }
  14838. for (int index = 0; index < AC_QUANTITY; index++)
  14839. {
  14840. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  14841. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  14842. }
  14843. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14844. {
  14845. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  14846. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  14847. }
  14848. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  14849. {
  14850. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14851. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  14852. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  14853. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  14854. }
  14855. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  14856. clientTime.Heartbeat=time((time_t*)NULL);
  14857. sleep(1);
  14858. }
  14859. void LWS_Send(char * str)
  14860. {
  14861. //=====================================================
  14862. // Check InternetConn 0: disconnected, 1: connected
  14863. //====================================================
  14864. if(GetOcppConnStatus() == 0)
  14865. {
  14866. DEBUG_INFO("offline now !!!\n");
  14867. return;
  14868. }
  14869. pthread_mutex_lock(&lock_send);
  14870. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14871. sprintf((char *)SendBuffer, "%s", str);
  14872. SendBufLen = strlen(str);
  14873. pthread_mutex_unlock(&lock_send);
  14874. lws_callback_on_writable(wsi_client);
  14875. //lws_service(context, 0);
  14876. //sleep(1);
  14877. }
  14878. void LWS_SendNow(char * str)
  14879. {
  14880. //=====================================================
  14881. // Check InternetConn 0: disconnected, 1: connected
  14882. //====================================================
  14883. if(GetOcppConnStatus() == 0)
  14884. {
  14885. DEBUG_INFO("offline now !!!\n");
  14886. return;
  14887. }
  14888. pthread_mutex_lock(&lock_send);
  14889. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14890. sprintf((char *)SendBuffer, "%s", str);
  14891. SendBufLen = strlen(str);
  14892. pthread_mutex_unlock(&lock_send);
  14893. lws_callback_on_writable(wsi_client);
  14894. lws_service(context, 0);
  14895. //sleep(1);
  14896. }